From 3ae8cc55865c4d95432766bf8ed970cce80dd8d2 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 3 Mar 2017 23:30:56 -0600 Subject: [PATCH] post_flags.rb: add 'rejected' and 'deleted' categories. Includes a category field in /post_flags.json. Adds 'rejected' and 'deleted' search categories. Categories: * unapproved - deleted after going unapproved in first three days * rejected - deleted after being manually flagged * deleted - either of the above * banned - artist requested removal * normal - none of the above (a "normal" manual flag) --- app/models/post_flag.rb | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/app/models/post_flag.rb b/app/models/post_flag.rb index 6e232638f..033f34b2f 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 @@ -66,11 +72,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 +95,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