diff --git a/app/controllers/post_appeals_controller.rb b/app/controllers/post_appeals_controller.rb index 2f0bfd469..e11a73569 100644 --- a/app/controllers/post_appeals_controller.rb +++ b/app/controllers/post_appeals_controller.rb @@ -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") diff --git a/app/controllers/post_flags_controller.rb b/app/controllers/post_flags_controller.rb index 1649d5fc2..2c4813eb7 100644 --- a/app/controllers/post_flags_controller.rb +++ b/app/controllers/post_flags_controller.rb @@ -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") diff --git a/app/models/post_appeal.rb b/app/models/post_appeal.rb index ccec459fd..12f9119da 100644 --- a/app/models/post_appeal.rb +++ b/app/models/post_appeal.rb @@ -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" diff --git a/app/models/post_flag.rb b/app/models/post_flag.rb index 6e232638f..e29ab64f6 100644 --- a/app/models/post_flag.rb +++ b/app/models/post_flag.rb @@ -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 diff --git a/app/views/post_appeals/_search.html.erb b/app/views/post_appeals/_search.html.erb index 11bf48eec..1f6a5e285 100644 --- a/app/views/post_appeals/_search.html.erb +++ b/app/views/post_appeals/_search.html.erb @@ -1,45 +1,8 @@ - - - <%= form_tag(post_appeals_path, :method => :get, :class => "simple_form") do %> - - - - - - - - - - - - - - - - - - - - - - - <% end %> - - +<%= 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 %> diff --git a/app/views/post_appeals/index.html.erb b/app/views/post_appeals/index.html.erb index 8f9b0d59e..aa5e0ddbb 100644 --- a/app/views/post_appeals/index.html.erb +++ b/app/views/post_appeals/index.html.erb @@ -7,20 +7,44 @@ Post - Creator Reason - Date + Appeals Resolved? + Uploaded + Appealed + Approver <% @post_appeals.each do |post_appeal| %> <%= PostPresenter.preview(post_appeal.post, :tags => "status:any") %> - <%= link_to_user post_appeal.creator %> <%= format_text post_appeal.reason, :ragel => true %> - <%= compact_time post_appeal.updated_at %> - <%= post_appeal.resolved? %> + + <%= link_to post_appeal.post.appeals.size, post_appeals_path(search: { post_id: post_appeal.post_id }) %> + + + <%= link_to post_appeal.is_resolved.to_s, post_appeals_path(search: params[:search].merge(is_resolved: post_appeal.is_resolved)) %> + + + <%= compact_time post_appeal.post.created_at %> +
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)) %> + + + <%= compact_time post_appeal.created_at %> +
by <%= link_to_user post_appeal.creator %> + <%= link_to "»", post_appeals_path(search: params[:search].merge(creator_name: post_appeal.creator.name)) %> + + + <% 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 %> + none + <%= link_to "»", post_appeals_path(search: params[:search].merge(post_tags_match: "#{params[:search][:post_tags_match]} approver:none".strip)) %> + <% end %> + <% end %> diff --git a/app/views/post_flags/_search.html.erb b/app/views/post_flags/_search.html.erb index f94594d05..b70d5d207 100644 --- a/app/views/post_flags/_search.html.erb +++ b/app/views/post_flags/_search.html.erb @@ -1,56 +1,11 @@ - - - <%= form_tag(post_flags_path, :method => :get, :class => "simple_form") do %> - - - - - - - - - - - <% if CurrentUser.user.is_moderator? %> - - - - - <% end %> - - - - - - - - - - - - - - <% end %> - - +<%= 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 %> diff --git a/app/views/post_flags/index.html.erb b/app/views/post_flags/index.html.erb index 5e4e59829..4259117e2 100644 --- a/app/views/post_flags/index.html.erb +++ b/app/views/post_flags/index.html.erb @@ -6,25 +6,53 @@ - - <% if CurrentUser.user.is_moderator? %> - - <% end %> + - + + + + + + <% @post_flags.each do |post_flag| %> - <% if CurrentUser.user.is_moderator? %> - - <% end %> - - + + + + + + + <% end %>
CreatorPost ReasonDateFlagsCategoryResolved?UploadedFlaggedApprover
<%= PostPresenter.preview(post_flag.post, :tags => "status:any") %> - <%= link_to_user post_flag.creator %> - <%= format_text post_flag.reason, :ragel => true %><%= compact_time post_flag.updated_at %> + <%= format_text post_flag.reason, :ragel => true %> + + <%= link_to post_flag.post.flags.size, post_flags_path(search: { post_id: post_flag.post_id }) %> + + <%= link_to post_flag.category.to_s, post_flags_path(search: params[:search].merge(category: post_flag.category)) %> + + <%= link_to post_flag.is_resolved?.to_s, post_flags_path(search: params[:search].merge(is_resolved: post_flag.is_resolved?)) %> + + <%= compact_time post_flag.post.created_at %> +
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)) %> +
+ <%= compact_time post_flag.created_at %> + <% if CurrentUser.user.is_moderator? %> +
by <%= link_to_user post_flag.creator %> + <%= link_to "»", post_flags_path(search: params[:search].merge(creator_name: post_flag.creator.name)) %> + <% end %> +
+ <% 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 %> + none + <%= link_to "»", post_flags_path(search: params[:search].merge(post_tags_match: "#{params[:search][:post_tags_match]} approver:none".strip)) %> + <% end %> +