posts: rework post events page.
* 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).
This commit is contained in:
@@ -70,6 +70,7 @@ class Post < ApplicationRecord
|
||||
has_many :favorites, dependent: :destroy
|
||||
has_many :replacements, class_name: "PostReplacement", :dependent => :destroy
|
||||
has_many :ai_tags, through: :media_asset
|
||||
has_many :events, class_name: "PostEvent"
|
||||
|
||||
attr_accessor :old_tag_string, :old_parent_id, :old_source, :old_rating, :has_constraints, :disable_versioning, :post_edit
|
||||
|
||||
@@ -1631,7 +1632,7 @@ class Post < ApplicationRecord
|
||||
def self.available_includes
|
||||
# attributes accessible through the ?only= parameter
|
||||
%i[
|
||||
uploader approver flags appeals parent children notes
|
||||
uploader approver flags appeals events parent children notes
|
||||
comments approvals disapprovals replacements pixiv_ugoira_frame_data
|
||||
artist_commentary media_asset ai_tags
|
||||
]
|
||||
|
||||
@@ -1,82 +1,40 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PostEvent
|
||||
include ActiveModel::Model
|
||||
include ActiveModel::Serializers::JSON
|
||||
include ActiveModel::Serializers::Xml
|
||||
class PostEvent < ApplicationRecord
|
||||
belongs_to :model, polymorphic: true
|
||||
belongs_to :creator, class_name: "User"
|
||||
belongs_to :post
|
||||
|
||||
attr_accessor :event
|
||||
|
||||
delegate :created_at, to: :event
|
||||
|
||||
def self.find_for_post(post_id)
|
||||
post = Post.find(post_id)
|
||||
(post.appeals + post.flags + post.approvals).sort_by(&:created_at).reverse.map { |e| new(event: e) }
|
||||
def self.model_types
|
||||
%w[Post PostAppeal PostApproval PostDisapproval PostFlag PostReplacement]
|
||||
end
|
||||
|
||||
def type_name
|
||||
case event
|
||||
when PostFlag
|
||||
"flag"
|
||||
when PostAppeal
|
||||
"appeal"
|
||||
when PostApproval
|
||||
"approval"
|
||||
end
|
||||
def self.visible(user)
|
||||
all
|
||||
end
|
||||
|
||||
def type
|
||||
type_name.first
|
||||
end
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:model, :post, :creator, :event_at], current_user: current_user)
|
||||
|
||||
def reason
|
||||
event.try(:reason) || ""
|
||||
end
|
||||
|
||||
def creator_id
|
||||
event.try(:creator_id) || event.try(:user_id)
|
||||
end
|
||||
|
||||
def creator
|
||||
event.try(:creator) || event.try(:user)
|
||||
end
|
||||
|
||||
def status
|
||||
if event.is_a?(PostApproval)
|
||||
"approved"
|
||||
elsif (event.is_a?(PostAppeal) && event.succeeded?) || (event.is_a?(PostFlag) && event.rejected?)
|
||||
"approved"
|
||||
elsif (event.is_a?(PostAppeal) && event.rejected?) || (event.is_a?(PostFlag) && event.succeeded?)
|
||||
"deleted"
|
||||
case params[:order]
|
||||
when "event_at_asc"
|
||||
q = q.order(event_at: :asc, model_id: :asc)
|
||||
else
|
||||
"pending"
|
||||
q = q.apply_default_order(params)
|
||||
end
|
||||
|
||||
q
|
||||
end
|
||||
|
||||
def is_creator_visible?(user = CurrentUser.user)
|
||||
case event
|
||||
when PostAppeal, PostApproval
|
||||
true
|
||||
when PostFlag
|
||||
flag = event
|
||||
Pundit.policy!(user, flag).can_view_flagger?
|
||||
end
|
||||
def self.default_order
|
||||
order(event_at: :desc, model_id: :desc)
|
||||
end
|
||||
|
||||
def attributes
|
||||
{
|
||||
creator_id: nil,
|
||||
created_at: nil,
|
||||
reason: nil,
|
||||
status: nil,
|
||||
type: nil,
|
||||
}
|
||||
def self.available_includes
|
||||
[:post, :model] # XXX creator isn't included because it leaks flagger/disapprover names
|
||||
end
|
||||
|
||||
# XXX can't use hidden_attributes because we don't inherit from ApplicationRecord.
|
||||
def serializable_hash(options = {})
|
||||
hash = super
|
||||
hash = hash.except(:creator_id) unless is_creator_visible?
|
||||
hash
|
||||
def readonly?
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -115,6 +115,7 @@ class User < ApplicationRecord
|
||||
has_many :post_appeals, foreign_key: :creator_id
|
||||
has_many :post_approvals, :dependent => :destroy
|
||||
has_many :post_disapprovals, :dependent => :destroy
|
||||
has_many :post_events, class_name: "PostEvent", foreign_key: :creator_id
|
||||
has_many :post_flags, foreign_key: :creator_id
|
||||
has_many :post_votes
|
||||
has_many :post_versions, foreign_key: :updater_id
|
||||
|
||||
Reference in New Issue
Block a user