A platform for community discussion. Free, open, simple.
FIX: Don't mix up action labels between different reviewables (#23365)
Ted Johanssone74560f062f3
diff --git a/app/assets/javascripts/discourse/app/components/reviewable-item.js b/app/assets/javascripts/discourse/app/components/reviewable-item.jsindex 547da9cb4fe..a661bfce6aa 100644--- a/app/assets/javascripts/discourse/app/components/reviewable-item.js+++ b/app/assets/javascripts/discourse/app/components/reviewable-item.js@@ -154,7 +154,7 @@ export default Component.extend({});return ajax(- `/review/${reviewable.id}/perform/${performableAction.id}?version=${version}`,+ `/review/${reviewable.id}/perform/${performableAction.server_action}?version=${version}`,{type: "PUT",data,@@ -286,7 +286,8 @@ export default Component.extend({const requireRejectReason = performableAction.get("require_reject_reason");- const actionModalClass = actionModalClassMap[performableAction.id];+ const actionModalClass =+ actionModalClassMap[performableAction.server_action];if (message) {this.dialog.confirm({diff --git a/app/serializers/reviewable_action_serializer.rb b/app/serializers/reviewable_action_serializer.rbindex d4e09005619..fbdacf2f8c1 100644--- a/app/serializers/reviewable_action_serializer.rb+++ b/app/serializers/reviewable_action_serializer.rb@@ -7,6 +7,7 @@ class ReviewableActionSerializer < ApplicationSerializer:label,:confirm_message,:description,+ :server_action,:client_action,:require_reject_reason@@ -22,6 +23,10 @@ class ReviewableActionSerializer < ApplicationSerializerI18n.t(object.description, default: nil)end+ def server_action+ object.server_action+ end+def include_description?description.present?enddiff --git a/lib/reviewable/actions.rb b/lib/reviewable/actions.rbindex abee9387588..a2a34b61f78 100644--- a/lib/reviewable/actions.rb+++ b/lib/reviewable/actions.rb@@ -4,7 +4,7 @@ require "reviewable/collection"class Reviewable < ActiveRecord::Baseclass Actions < Reviewable::Collection- attr_reader :bundles+ attr_reader :bundles, :reviewabledef initialize(reviewable, guardian, args = nil)super(reviewable, guardian, args)@@ -46,6 +46,10 @@ class Reviewable < ActiveRecord::Basesuper(id)@icon, @button_class, @label = icon, button_class, labelend++ def server_action+ id.split("-").last+ endenddef add_bundle(id, icon: nil, label: nil)@@ -55,6 +59,7 @@ class Reviewable < ActiveRecord::Baseenddef add(id, bundle: nil)+ id = [reviewable.target_type&.underscore, id].compact_blank.join("-")action = Actions.common_actions[id] || Action.new(id)yield action if block_given?@content << actiondiff --git a/lib/reviewable/collection.rb b/lib/reviewable/collection.rbindex 1a9b354fbc5..f05e898f483 100644--- a/lib/reviewable/collection.rb+++ b/lib/reviewable/collection.rb@@ -18,8 +18,8 @@ class Reviewable < ActiveRecord::Base@content = []end- def has?(id)- @content.any? { |a| a.id.to_s == id.to_s }+ def has?(action_id)+ @content.any? { |a| a.server_action.to_s == action_id.to_s }enddef blank?diff --git a/lib/reviewable/editable_fields.rb b/lib/reviewable/editable_fields.rbindex d68ac138353..f6bc01b56b1 100644--- a/lib/reviewable/editable_fields.rb+++ b/lib/reviewable/editable_fields.rb@@ -9,6 +9,10 @@ class Reviewable < ActiveRecord::Basesuper(id)@type = typeend++ def server_action+ id+ endenddef add(id, type)diff --git a/spec/models/reviewable_user_spec.rb b/spec/models/reviewable_user_spec.rbindex 319ec0812e8..32c723b13e8 100644--- a/spec/models/reviewable_user_spec.rb+++ b/spec/models/reviewable_user_spec.rb@@ -49,7 +49,9 @@ RSpec.describe ReviewableUser, type: :model dodef assert_require_reject_reason(id, expected)actions = reviewable.actions_for(Guardian.new(moderator))- expect(actions.to_a.find { |a| a.id == id }.require_reject_reason).to eq(expected)+ expect(actions.to_a.find { |a| a.server_action.to_sym == id }.require_reject_reason).to eq(+ expected,+ )endend