From 8d45bb6d52a65749ab54e701737c6ab939f43003 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 3 Mar 2017 19:30:12 -0600 Subject: [PATCH] /post_{flags,appeals}: allow searching by tags. --- app/models/post_appeal.rb | 8 ++++++++ app/models/post_flag.rb | 8 ++++++++ app/views/post_appeals/_search.html.erb | 1 + app/views/post_flags/_search.html.erb | 1 + 4 files changed, 18 insertions(+) diff --git a/app/models/post_appeal.rb b/app/models/post_appeal.rb index a47fc08ee..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 @@ -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 0b8fbeee5..e29ab64f6 100644 --- a/app/models/post_flag.rb +++ b/app/models/post_flag.rb @@ -24,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 @@ -64,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" diff --git a/app/views/post_appeals/_search.html.erb b/app/views/post_appeals/_search.html.erb index 3f59219fb..1f6a5e285 100644 --- a/app/views/post_appeals/_search.html.erb +++ b/app/views/post_appeals/_search.html.erb @@ -1,5 +1,6 @@ <%= 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] %> diff --git a/app/views/post_flags/_search.html.erb b/app/views/post_flags/_search.html.erb index 18f6bd435..b70d5d207 100644 --- a/app/views/post_flags/_search.html.erb +++ b/app/views/post_flags/_search.html.erb @@ -1,5 +1,6 @@ <%= 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] } %>