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 @@ -
| - |
-
- <%= text_field "search", "reason_matches", :label => "Reason", :value => params[:search][:reason_matches] %>
-
- |
-
|---|---|
| - |
-
- <%= text_field "search", "post_id", :value => params[:search][:post_id] %>
-
- |
-
| - |
-
- <%= text_field "search", "creator_name", :value => params[:search][:creator_name] %>
-
- |
-
| - |
-
- <%= select "search", "is_resolved", ["true", "false"], :selected => params[:search][:is_resolved], :include_blank => true %>
-
- |
-
| <%= submit_tag "Search" %> | - |
| - |
-
- <%= text_field "search", "reason_matches", :label => "Reason", :value => params[:search][:reason_matches] %>
-
- |
-
|---|---|
| - |
-
- <%= text_field "search", "post_id", :value => params[:search][:post_id] %>
-
- |
-
| - |
-
- <%= text_field "search", "creator_name", :value => params[:search][:creator_name] %>
-
- |
-
| - |
-
- <%= select "search", "is_resolved", ["true", "false"], :selected => params[:search][:is_resolved], :include_blank => true %>
-
- |
-
| - |
-
- <%= select "search", "category", ["normal", "unapproved", "banned"], :selected => params[:search][:category], :include_blank => true %>
-
- |
-
| <%= submit_tag "Search" %> | - |
| - <% if CurrentUser.user.is_moderator? %> - | Creator | - <% end %> +Post | Reason | -Date | +Flags | +Category | +Resolved? | +Uploaded | +Flagged | +Approver |
|---|---|---|---|---|---|---|---|---|---|---|
| <%= PostPresenter.preview(post_flag.post, :tags => "status:any") %> | - <% if CurrentUser.user.is_moderator? %> -- <%= link_to_user post_flag.creator %> - | - <% end %> -<%= 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 %> + |