post approvals: add index page + search options (fix #3579).
This commit is contained in:
@@ -5,10 +5,6 @@ class PostApproval < ApplicationRecord
|
||||
validate :validate_approval
|
||||
after_create :approve_post
|
||||
|
||||
def self.prune!
|
||||
where("created_at < ?", 1.month.ago).delete_all
|
||||
end
|
||||
|
||||
def validate_approval
|
||||
if post.is_status_locked?
|
||||
errors.add(:post, "is locked and cannot be approved")
|
||||
@@ -33,4 +29,26 @@ class PostApproval < ApplicationRecord
|
||||
post.flags.each(&:resolve!)
|
||||
post.update(approver: user, is_flagged: false, is_pending: false, is_deleted: false)
|
||||
end
|
||||
|
||||
concerning :SearchMethods do
|
||||
class_methods do
|
||||
def post_tags_match(query)
|
||||
PostQueryBuilder.new(query).build(self.joins(:post))
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = super
|
||||
params[:user_id] = User.name_to_id(params[:user_name]) if params[:user_name]
|
||||
|
||||
if params[:post_tags_match].present?
|
||||
q = q.post_tags_match(params[:post_tags_match])
|
||||
end
|
||||
|
||||
q = q.attribute_matches(:user_id, params[:user_id])
|
||||
q = q.attribute_matches(:post_id, params[:post_id])
|
||||
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user