Merge pull request #2967 from evazion/feat-flags-ui
Improve /post_flags, /post_appeals pages
This commit is contained in:
@@ -8,8 +8,8 @@ class PostAppealsController < ApplicationController
|
||||
end
|
||||
|
||||
def index
|
||||
@query = PostAppeal.order("post_appeals.id desc").includes(:post).search(params[:search])
|
||||
@post_appeals = @query.paginate(params[:page], :limit => params[:limit])
|
||||
@post_appeals = PostAppeal.includes(:creator).search(params[:search]).includes(post: [:appeals, :uploader, :approver])
|
||||
@post_appeals = @post_appeals.paginate(params[:page], limit: params[:limit])
|
||||
respond_with(@post_appeals) do |format|
|
||||
format.xml do
|
||||
render :xml => @post_appeals.to_xml(:root => "post-appeals")
|
||||
|
||||
@@ -8,8 +8,8 @@ class PostFlagsController < ApplicationController
|
||||
end
|
||||
|
||||
def index
|
||||
@query = PostFlag.order("id desc").search(params[:search])
|
||||
@post_flags = @query.paginate(params[:page], :limit => params[:limit])
|
||||
@post_flags = PostFlag.search(params[:search]).includes(:creator, post: [:flags, :uploader, :approver])
|
||||
@post_flags = @post_flags.paginate(params[:page], limit: params[:limit])
|
||||
respond_with(@post_flags) do |format|
|
||||
format.xml do
|
||||
render :xml => @post_flags.to_xml(:root => "post-flags")
|
||||
|
||||
@@ -16,6 +16,10 @@ class PostAppeal < ActiveRecord::Base
|
||||
where("reason ILIKE ? ESCAPE E'\\\\'", query.to_escaped_for_sql_like)
|
||||
end
|
||||
|
||||
def post_tags_match(query)
|
||||
PostQueryBuilder.new(query).build(self.joins(:post))
|
||||
end
|
||||
|
||||
def resolved
|
||||
joins(:post).where("posts.is_deleted = false and posts.is_flagged = false")
|
||||
end
|
||||
@@ -37,7 +41,7 @@ class PostAppeal < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = where("true")
|
||||
q = order("post_appeals.id desc")
|
||||
return q if params.blank?
|
||||
|
||||
if params[:reason_matches].present?
|
||||
@@ -56,6 +60,10 @@ class PostAppeal < ActiveRecord::Base
|
||||
q = q.where("post_id = ?", params[:post_id].to_i)
|
||||
end
|
||||
|
||||
if params[:post_tags_match].present?
|
||||
q = q.post_tags_match(params[:post_tags_match])
|
||||
end
|
||||
|
||||
if params[:is_resolved] == "true"
|
||||
q = q.resolved
|
||||
elsif params[:is_resolved] == "false"
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
class PostFlag < ActiveRecord::Base
|
||||
class Error < Exception ; end
|
||||
|
||||
module Reasons
|
||||
UNAPPROVED = "Unapproved in three days"
|
||||
REJECTED = "Unapproved in three days after returning to moderation queue%"
|
||||
BANNED = "Artist requested removal"
|
||||
end
|
||||
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to :post
|
||||
validates_presence_of :reason, :creator_id, :creator_ip_addr
|
||||
@@ -18,6 +24,10 @@ class PostFlag < ActiveRecord::Base
|
||||
where("reason ILIKE ? ESCAPE E'\\\\'", query.to_escaped_for_sql_like)
|
||||
end
|
||||
|
||||
def post_tags_match(query)
|
||||
PostQueryBuilder.new(query).build(self.joins(:post))
|
||||
end
|
||||
|
||||
def resolved
|
||||
where("is_resolved = ?", true)
|
||||
end
|
||||
@@ -39,7 +49,7 @@ class PostFlag < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = where("true")
|
||||
q = order("post_flags.id desc")
|
||||
return q if params.blank?
|
||||
|
||||
if params[:reason_matches].present?
|
||||
@@ -58,6 +68,10 @@ class PostFlag < ActiveRecord::Base
|
||||
q = q.where("post_id = ?", params[:post_id].to_i)
|
||||
end
|
||||
|
||||
if params[:post_tags_match].present?
|
||||
q = q.post_tags_match(params[:post_tags_match])
|
||||
end
|
||||
|
||||
if params[:is_resolved] == "true"
|
||||
q = q.resolved
|
||||
elsif params[:is_resolved] == "false"
|
||||
@@ -66,11 +80,15 @@ class PostFlag < ActiveRecord::Base
|
||||
|
||||
case params[:category]
|
||||
when "normal"
|
||||
q = q.where("reason not in (?)", ["Unapproved in three days", "Unapproved in three days after returning to moderation queue", "Artist requested removal"])
|
||||
q = q.where("reason NOT IN (?) AND reason NOT LIKE ?", [Reasons::UNAPPROVED, Reasons::BANNED], Reasons::REJECTED)
|
||||
when "unapproved"
|
||||
q = q.where("reason in (?)", ["Unapproved in three days", "Unapproved in three days after returning to moderation queue"])
|
||||
q = q.where(reason: Reasons::UNAPPROVED)
|
||||
when "banned"
|
||||
q = q.where("reason = ?", "Artist requested removal")
|
||||
q = q.where(reason: Reasons::BANNED)
|
||||
when "rejected"
|
||||
q = q.where("reason LIKE ?", Reasons::REJECTED)
|
||||
when "deleted"
|
||||
q = q.where("reason = ? OR reason LIKE ?", Reasons::UNAPPROVED, Reasons::REJECTED)
|
||||
end
|
||||
|
||||
q
|
||||
@@ -85,11 +103,28 @@ class PostFlag < ActiveRecord::Base
|
||||
end
|
||||
super + list
|
||||
end
|
||||
|
||||
def method_attributes
|
||||
super + [:category]
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
include ApiMethods
|
||||
|
||||
def category
|
||||
case reason
|
||||
when Reasons::UNAPPROVED
|
||||
:unapproved
|
||||
when /#{Reasons::REJECTED.gsub("%", ".*")}/
|
||||
:rejected
|
||||
when Reasons::BANNED
|
||||
:banned
|
||||
else
|
||||
:normal
|
||||
end
|
||||
end
|
||||
|
||||
def update_post
|
||||
post.update_column(:is_flagged, true) unless post.is_flagged?
|
||||
end
|
||||
|
||||
@@ -1,45 +1,8 @@
|
||||
<table class="search">
|
||||
<tbody>
|
||||
<%= form_tag(post_appeals_path, :method => :get, :class => "simple_form") do %>
|
||||
<tr>
|
||||
<th><label for="search_reason_matches">Reason</label></th>
|
||||
<td>
|
||||
<div class="input">
|
||||
<%= text_field "search", "reason_matches", :label => "Reason", :value => params[:search][:reason_matches] %>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th><label for="search_post_id">Post ID</label></th>
|
||||
<td>
|
||||
<div class="input">
|
||||
<%= text_field "search", "post_id", :value => params[:search][:post_id] %>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th><label for="search_creator_name">Creator</th>
|
||||
<td>
|
||||
<div class="input">
|
||||
<%= text_field "search", "creator_name", :value => params[:search][:creator_name] %>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th><label for="search_is_resolved">Resolved</label></th>
|
||||
<td>
|
||||
<div class="input">
|
||||
<%= select "search", "is_resolved", ["true", "false"], :selected => params[:search][:is_resolved], :include_blank => true %>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><%= submit_tag "Search" %><td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<%= simple_form_for(:search, url: post_appeals_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= f.input :reason_matches, label: "Reason", input_html: { value: params[:search][:reason_matches] } %>
|
||||
<%= f.input :post_tags_match, label: "Tags", input_html: { value: params[:search][:post_tags_match] } %>
|
||||
<%= f.input :post_id, label: "Post ID", input_html: { value: params[:search][:post_id] } %>
|
||||
<%= f.input :creator_name, label: "Creator", input_html: { value: params[:search][:creator_name] } %>
|
||||
<%= f.input :is_resolved, label: "Resolved?", collection: [["Yes", true], ["No", false]], selected: params[:search][:is_resolved] %>
|
||||
<%= f.submit "Search" %>
|
||||
<% end %>
|
||||
|
||||
@@ -7,20 +7,44 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="1%">Post</th>
|
||||
<th width="10%">Creator</th>
|
||||
<th>Reason</th>
|
||||
<th width="15%">Date</th>
|
||||
<th width="1%">Appeals</th>
|
||||
<th width="5%">Resolved?</th>
|
||||
<th width="15%">Uploaded</th>
|
||||
<th width="15%">Appealed</th>
|
||||
<th width="15%">Approver</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @post_appeals.each do |post_appeal| %>
|
||||
<tr>
|
||||
<td><%= PostPresenter.preview(post_appeal.post, :tags => "status:any") %></td>
|
||||
<td><%= link_to_user post_appeal.creator %></td>
|
||||
<td><%= format_text post_appeal.reason, :ragel => true %></td>
|
||||
<td><%= compact_time post_appeal.updated_at %></td>
|
||||
<td><%= post_appeal.resolved? %></td>
|
||||
<td>
|
||||
<%= link_to post_appeal.post.appeals.size, post_appeals_path(search: { post_id: post_appeal.post_id }) %>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to post_appeal.is_resolved.to_s, post_appeals_path(search: params[:search].merge(is_resolved: post_appeal.is_resolved)) %>
|
||||
</td>
|
||||
<td>
|
||||
<%= compact_time post_appeal.post.created_at %>
|
||||
<br> by <%= link_to_user post_appeal.post.uploader %>
|
||||
<%= link_to "»", post_appeals_path(search: params[:search].merge(post_tags_match: "#{params[:search][:post_tags_match]} user:#{post_appeal.post.uploader.name}".strip)) %>
|
||||
</td>
|
||||
<td>
|
||||
<%= compact_time post_appeal.created_at %>
|
||||
<br> by <%= link_to_user post_appeal.creator %>
|
||||
<%= link_to "»", post_appeals_path(search: params[:search].merge(creator_name: post_appeal.creator.name)) %>
|
||||
</td>
|
||||
<td>
|
||||
<% if post_appeal.post.approver %>
|
||||
<%= link_to_user post_appeal.post.approver %>
|
||||
<%= link_to "»", post_appeals_path(search: params[:search].merge(post_tags_match: "#{params[:search][:post_tags_match]} approver:#{post_appeal.post.approver.name}".strip)) %>
|
||||
<% else %>
|
||||
<em>none</em>
|
||||
<%= link_to "»", post_appeals_path(search: params[:search].merge(post_tags_match: "#{params[:search][:post_tags_match]} approver:none".strip)) %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
@@ -1,56 +1,11 @@
|
||||
<table class="search">
|
||||
<tbody>
|
||||
<%= form_tag(post_flags_path, :method => :get, :class => "simple_form") do %>
|
||||
<tr>
|
||||
<th><label for="search_reason_matches">Reason</label></th>
|
||||
<td>
|
||||
<div class="input">
|
||||
<%= text_field "search", "reason_matches", :label => "Reason", :value => params[:search][:reason_matches] %>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th><label for="search_post_id">Post ID</label></th>
|
||||
<td>
|
||||
<div class="input">
|
||||
<%= text_field "search", "post_id", :value => params[:search][:post_id] %>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<% if CurrentUser.user.is_moderator? %>
|
||||
<tr>
|
||||
<th><label for="search_creator_name">Creator</th>
|
||||
<td>
|
||||
<div class="input">
|
||||
<%= text_field "search", "creator_name", :value => params[:search][:creator_name] %>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
<tr>
|
||||
<th><label for="search_is_resolved">Resolved</label></th>
|
||||
<td>
|
||||
<div class="input">
|
||||
<%= select "search", "is_resolved", ["true", "false"], :selected => params[:search][:is_resolved], :include_blank => true %>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th><label for="search_category">Category</label></th>
|
||||
<td>
|
||||
<div class="input">
|
||||
<%= select "search", "category", ["normal", "unapproved", "banned"], :selected => params[:search][:category], :include_blank => true %>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><%= submit_tag "Search" %><td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<%= simple_form_for(:search, url: post_flags_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= f.input :reason_matches, label: "Reason", input_html: { value: params[:search][:reason_matches] } %>
|
||||
<%= f.input :post_tags_match, label: "Tags", input_html: { value: params[:search][:post_tags_match] } %>
|
||||
<%= f.input :post_id, label: "Post ID", input_html: { value: params[:search][:post_id] } %>
|
||||
<% if CurrentUser.is_moderator? %>
|
||||
<%= f.input :creator_name, label: "Creator", input_html: { value: params[:search][:creator_name] } %>
|
||||
<% end %>
|
||||
<%= f.input :is_resolved, label: "Resolved?", collection: [["Yes", true], ["No", false]], include_blank: true, selected: params[:search][:is_resolved] %>
|
||||
<%= f.input :category, label: "Category", collection: ["normal", "unapproved", "rejected", "deleted", "banned"], include_blank: true, selected: params[:search][:category] %>
|
||||
<%= f.submit "Search" %>
|
||||
<% end %>
|
||||
|
||||
@@ -6,25 +6,53 @@
|
||||
<table width="100%" class="striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="1%"></th>
|
||||
<% if CurrentUser.user.is_moderator? %>
|
||||
<th width="10%">Creator</th>
|
||||
<% end %>
|
||||
<th width="1%">Post</th>
|
||||
<th>Reason</th>
|
||||
<th width="15%">Date</th>
|
||||
<th width="1%">Flags</th>
|
||||
<th width="1%">Category</th>
|
||||
<th width="1%">Resolved?</th>
|
||||
<th width="15%">Uploaded</th>
|
||||
<th width="15%">Flagged</th>
|
||||
<th width="15%">Approver</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @post_flags.each do |post_flag| %>
|
||||
<tr class="resolved-<%= post_flag.is_resolved? %>">
|
||||
<td><%= PostPresenter.preview(post_flag.post, :tags => "status:any") %></td>
|
||||
<% if CurrentUser.user.is_moderator? %>
|
||||
<td>
|
||||
<%= link_to_user post_flag.creator %>
|
||||
</td>
|
||||
<% end %>
|
||||
<td><%= format_text post_flag.reason, :ragel => true %></td>
|
||||
<td><%= compact_time post_flag.updated_at %></td>
|
||||
<td>
|
||||
<%= format_text post_flag.reason, :ragel => true %>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to post_flag.post.flags.size, post_flags_path(search: { post_id: post_flag.post_id }) %>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to post_flag.category.to_s, post_flags_path(search: params[:search].merge(category: post_flag.category)) %>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to post_flag.is_resolved?.to_s, post_flags_path(search: params[:search].merge(is_resolved: post_flag.is_resolved?)) %>
|
||||
</td>
|
||||
<td>
|
||||
<%= compact_time post_flag.post.created_at %>
|
||||
<br> by <%= link_to_user post_flag.post.uploader %>
|
||||
<%= link_to "»", post_flags_path(search: params[:search].merge(post_tags_match: "#{params[:search][:post_tags_match]} user:#{post_flag.post.uploader.name}".strip)) %>
|
||||
</td>
|
||||
<td>
|
||||
<%= compact_time post_flag.created_at %>
|
||||
<% if CurrentUser.user.is_moderator? %>
|
||||
<br> by <%= link_to_user post_flag.creator %>
|
||||
<%= link_to "»", post_flags_path(search: params[:search].merge(creator_name: post_flag.creator.name)) %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td>
|
||||
<% if post_flag.post.approver %>
|
||||
<%= link_to_user post_flag.post.approver %>
|
||||
<%= link_to "»", post_flags_path(search: params[:search].merge(post_tags_match: "#{params[:search][:post_tags_match]} approver:#{post_flag.post.approver.name}".strip)) %>
|
||||
<% else %>
|
||||
<em>none</em>
|
||||
<%= link_to "»", post_flags_path(search: params[:search].merge(post_tags_match: "#{params[:search][:post_tags_match]} approver:none".strip)) %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user