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)
This commit is contained in:
@@ -1,6 +1,12 @@
|
|||||||
class PostFlag < ActiveRecord::Base
|
class PostFlag < ActiveRecord::Base
|
||||||
class Error < Exception ; end
|
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 :creator, :class_name => "User"
|
||||||
belongs_to :post
|
belongs_to :post
|
||||||
validates_presence_of :reason, :creator_id, :creator_ip_addr
|
validates_presence_of :reason, :creator_id, :creator_ip_addr
|
||||||
@@ -66,11 +72,15 @@ class PostFlag < ActiveRecord::Base
|
|||||||
|
|
||||||
case params[:category]
|
case params[:category]
|
||||||
when "normal"
|
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"
|
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"
|
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
|
end
|
||||||
|
|
||||||
q
|
q
|
||||||
@@ -85,11 +95,28 @@ class PostFlag < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
super + list
|
super + list
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def method_attributes
|
||||||
|
super + [:category]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
extend SearchMethods
|
extend SearchMethods
|
||||||
include ApiMethods
|
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
|
def update_post
|
||||||
post.update_column(:is_flagged, true) unless post.is_flagged?
|
post.update_column(:is_flagged, true) unless post.is_flagged?
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user