A platform for community discussion. Free, open, simple.
DEV: Allow specifying button class in reviewable action definitions (#8093)
David Taylor479fdaaea11f
diff --git a/app/assets/javascripts/discourse/templates/components/reviewable-bundled-action.hbs b/app/assets/javascripts/discourse/templates/components/reviewable-bundled-action.hbsindex 1c9736a41f6..21bd7efbdf0 100644--- a/app/assets/javascripts/discourse/templates/components/reviewable-bundled-action.hbs+++ b/app/assets/javascripts/discourse/templates/components/reviewable-bundled-action.hbs@@ -9,7 +9,7 @@disabled=reviewableUpdating}}{{else}}{{d-button- class=(concat "reviewable-action " (dasherize first.id))+ class=(concat "reviewable-action " (dasherize first.id) " " first.button_class)icon=first.iconaction=(action "perform" first)translatedLabel=first.labeldiff --git a/app/assets/stylesheets/common/base/reviewables.scss b/app/assets/stylesheets/common/base/reviewables.scssindex 0228f0c1c70..e47cb5287f4 100644--- a/app/assets/stylesheets/common/base/reviewables.scss+++ b/app/assets/stylesheets/common/base/reviewables.scss@@ -262,10 +262,6 @@.reviewable-action,.reviewable-action-dropdown {margin-right: 0.5em;-- &.delete-user {- @extend .btn-danger;- }}}padding-bottom: 1em;diff --git a/app/models/reviewable_flagged_post.rb b/app/models/reviewable_flagged_post.rbindex e523ded4889..43622b14769 100644--- a/app/models/reviewable_flagged_post.rb+++ b/app/models/reviewable_flagged_post.rb@@ -269,10 +269,11 @@ protectedendend- def build_action(actions, id, icon:, bundle: nil, client_action: nil, confirm: false)+ def build_action(actions, id, icon:, button_class: nil, bundle: nil, client_action: nil, confirm: false)actions.add(id, bundle: bundle) do |action|prefix = "reviewables.actions.#{id}"action.icon = icon+ action.button_class = button_classaction.label = "#{prefix}.title"action.description = "#{prefix}.description"action.client_action = client_actiondiff --git a/app/models/reviewable_queued_post.rb b/app/models/reviewable_queued_post.rbindex 7fc6bc17fd3..8602a0fb728 100644--- a/app/models/reviewable_queued_post.rb+++ b/app/models/reviewable_queued_post.rb@@ -38,6 +38,7 @@ class ReviewableQueuedPost < Reviewableif pending? && guardian.can_delete_user?(created_by)actions.add(:delete_user) do |action|action.icon = 'trash-alt'+ action.button_class = 'btn-danger'action.label = 'reviewables.actions.delete_user.title'action.confirm_message = 'reviewables.actions.delete_user.confirm'enddiff --git a/app/serializers/reviewable_action_serializer.rb b/app/serializers/reviewable_action_serializer.rbindex 6fd1f889ac5..50c5310fcd7 100644--- a/app/serializers/reviewable_action_serializer.rb+++ b/app/serializers/reviewable_action_serializer.rb@@ -1,7 +1,7 @@# frozen_string_literal: trueclass ReviewableActionSerializer < ApplicationSerializer- attributes :id, :icon, :label, :confirm_message, :description, :client_action+ attributes :id, :icon, :button_class, :label, :confirm_message, :description, :client_actiondef labelI18n.t(object.label)diff --git a/lib/reviewable/actions.rb b/lib/reviewable/actions.rbindex 5d584b5123b..f433a8c8a89 100644--- a/lib/reviewable/actions.rb+++ b/lib/reviewable/actions.rb@@ -33,11 +33,11 @@ class Reviewable < ActiveRecord::Baseendclass Action < Item- attr_accessor :icon, :label, :description, :confirm_message, :client_action+ attr_accessor :icon, :button_class, :label, :description, :confirm_message, :client_action- def initialize(id, icon = nil, label = nil)+ def initialize(id, icon = nil, button_class = nil, label = nil)super(id)- @icon, @label = icon, label+ @icon, @button_class, @label = icon, button_class, labelendenddiff --git a/spec/models/reviewable_queued_post_spec.rb b/spec/models/reviewable_queued_post_spec.rbindex 016a348579e..70842e39a16 100644--- a/spec/models/reviewable_queued_post_spec.rb+++ b/spec/models/reviewable_queued_post_spec.rb@@ -118,6 +118,12 @@ RSpec.describe ReviewableQueuedPost, type: :model doendcontext "delete_user" do+ it "has the correct button class" do+ expect(reviewable.actions_for(Guardian.new(moderator)).to_a.+ find { |a| a.id == :delete_user }.button_class).+ to eq("btn-danger")+ end+it "deletes the user and rejects the post" doother_reviewable = Fabricate(:reviewable_queued_post, created_by: reviewable.created_by)