* Add a global /post_events page that shows the history of all approvals, disapprovals, flags, appeals, and replacements on a single page. * Redesign the /posts/:id/events page to show all approval, disapproval, flag, appeal, and replacement events for a single post (before it only showed approvals, flags, and appeals). * Remove the replacement history link from the post show page. Replacements are now included in the post events page (closes #4948: Highlighed replacements). * Add /post_approvals/:id and /post_replacements/:id routes (these are used by the "Details" link on the post events page).
37 lines
1.0 KiB
Ruby
37 lines
1.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class PostEventPolicy < ApplicationPolicy
|
|
def can_see_creator?
|
|
case event.model_type
|
|
when "PostFlag"
|
|
policy(event.model).can_view_flagger?
|
|
when "PostDisapproval"
|
|
policy(event.model).can_view_creator?
|
|
else
|
|
true
|
|
end
|
|
end
|
|
|
|
def api_attributes
|
|
[:model_type, :model_id, :post_id, (:creator_id if can_see_creator?), :event_at].compact
|
|
end
|
|
|
|
def visible_for_search(events, attribute)
|
|
case attribute
|
|
in :creator | :creator_id
|
|
events.model_types.map do |type|
|
|
attr = attribute
|
|
attr = attr.to_s.gsub("creator", "uploader").to_sym if type == "Post"
|
|
attr = attr.to_s.gsub("creator", "user").to_sym if type in "PostApproval" | "PostDisapproval"
|
|
|
|
# XXX ordering by created_at desc is a query planner hack to make Postgres use the right indexes.
|
|
events.where(model: type.constantize.visible_for_search(attr, user).order(created_at: :desc))
|
|
end.reduce(:or)
|
|
else
|
|
events
|
|
end
|
|
end
|
|
|
|
alias_method :event, :record
|
|
end
|