mirror of
https://github.com/discourse/discourse.git
synced 2024-12-24 06:13:47 +08:00
e74560f062
Currently, if the review queue has both a flagged post and a flagged chat message, one of the two will have some of the labels of their actions replaced by those of the other. In other words, the labels are getting mixed up. For example, a flagged chat message might show up with an action labelled "Delete post". This is happening because when using bundles, we are sending along the actions in a separate part of the response, so they can be shared by many reviewables. The bundles then index into this bag of actions by their ID, which is something generic describing the server action, e.g. "agree_and_delete". The problem here is the same action can have different labels depending on the type of reviewable. Now that the bag of actions contains multiple actions with the same ID, which one is chosen is arbitrary. I.e. it doesn't distinguish based on the type of the reviewable. This change adds an additional field to the actions, server_action, which now contains what used to be the ID. Meanwhile, the ID has been turned into a concatenation of the reviewable type and the server action, e.g. post-agree_and_delete. This still provides the upside of denormalizing the actions while allowing for different reviewable types to have different labels and descriptions. At first I thought I would prepend the reviewable type to the ID, but this doesn't work well because the ID is used on the server-side to determine which actions are possible, and these need to be shared between different reviewables. Hence the introduction of server_action, which now serves that purpose. I also thought about changing the way that the bundle indexes into the bag of actions, but this is happening through some EmberJS mechanism, so we don't own that code.
42 lines
684 B
Ruby
42 lines
684 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Reviewable < ActiveRecord::Base
|
|
class Collection
|
|
class Item
|
|
include ActiveModel::Serialization
|
|
attr_reader :id
|
|
|
|
def initialize(id)
|
|
@id = id
|
|
end
|
|
end
|
|
|
|
def initialize(reviewable, guardian, args = nil)
|
|
args ||= {}
|
|
|
|
@reviewable, @guardian, @args = reviewable, guardian, args
|
|
@content = []
|
|
end
|
|
|
|
def has?(action_id)
|
|
@content.any? { |a| a.server_action.to_s == action_id.to_s }
|
|
end
|
|
|
|
def blank?
|
|
@content.blank?
|
|
end
|
|
|
|
def present?
|
|
!blank?
|
|
end
|
|
|
|
def each
|
|
@content.each { |i| yield i }
|
|
end
|
|
|
|
def to_a
|
|
@content
|
|
end
|
|
end
|
|
end
|