2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
class ReviewableActionSerializer < ApplicationSerializer
|
2021-03-03 00:28:27 +08:00
|
|
|
attributes :id,
|
|
|
|
:icon,
|
|
|
|
:button_class,
|
|
|
|
:label,
|
|
|
|
:confirm_message,
|
|
|
|
:description,
|
FIX: Don't mix up action labels between different reviewables (#23365)
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.
2023-09-06 10:57:30 +08:00
|
|
|
:server_action,
|
2021-03-03 00:28:27 +08:00
|
|
|
:client_action,
|
2023-08-29 12:36:20 +08:00
|
|
|
:require_reject_reason
|
2019-01-04 01:03:01 +08:00
|
|
|
|
|
|
|
def label
|
|
|
|
I18n.t(object.label)
|
|
|
|
end
|
|
|
|
|
|
|
|
def confirm_message
|
|
|
|
I18n.t(object.confirm_message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
|
|
|
I18n.t(object.description, default: nil)
|
|
|
|
end
|
|
|
|
|
FIX: Don't mix up action labels between different reviewables (#23365)
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.
2023-09-06 10:57:30 +08:00
|
|
|
def server_action
|
|
|
|
object.server_action
|
|
|
|
end
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
def include_description?
|
|
|
|
description.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_confirm_message?
|
|
|
|
object.confirm_message.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_client_action?
|
|
|
|
object.client_action.present?
|
|
|
|
end
|
|
|
|
|
2021-01-15 06:43:26 +08:00
|
|
|
def include_require_reject_reason?
|
|
|
|
object.require_reject_reason.present?
|
|
|
|
end
|
2019-01-04 01:03:01 +08:00
|
|
|
end
|