* 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).
41 lines
866 B
Ruby
41 lines
866 B
Ruby
# frozen_string_literal: true
|
|
|
|
class PostEvent < ApplicationRecord
|
|
belongs_to :model, polymorphic: true
|
|
belongs_to :creator, class_name: "User"
|
|
belongs_to :post
|
|
|
|
def self.model_types
|
|
%w[Post PostAppeal PostApproval PostDisapproval PostFlag PostReplacement]
|
|
end
|
|
|
|
def self.visible(user)
|
|
all
|
|
end
|
|
|
|
def self.search(params, current_user)
|
|
q = search_attributes(params, [:model, :post, :creator, :event_at], current_user: current_user)
|
|
|
|
case params[:order]
|
|
when "event_at_asc"
|
|
q = q.order(event_at: :asc, model_id: :asc)
|
|
else
|
|
q = q.apply_default_order(params)
|
|
end
|
|
|
|
q
|
|
end
|
|
|
|
def self.default_order
|
|
order(event_at: :desc, model_id: :desc)
|
|
end
|
|
|
|
def self.available_includes
|
|
[:post, :model] # XXX creator isn't included because it leaks flagger/disapprover names
|
|
end
|
|
|
|
def readonly?
|
|
true
|
|
end
|
|
end
|