A platform for community discussion. Free, open, simple.
FIX: Don't allow submitting bulk topic actions without a notification… (#33292)
Penar Musaraj00c97178d517
diff --git a/app/assets/javascripts/discourse/app/components/modal/bulk-topic-actions.gjs b/app/assets/javascripts/discourse/app/components/modal/bulk-topic-actions.gjsindex 4ba5b6ccaf5..2a385613ffa 100644--- a/app/assets/javascripts/discourse/app/components/modal/bulk-topic-actions.gjs+++ b/app/assets/javascripts/discourse/app/components/modal/bulk-topic-actions.gjs@@ -38,7 +38,7 @@ export default class BulkTopicActions extends Component {@tracked isSilent = false;@tracked closeNote = null;- notificationLevelId = null;+ @tracked notificationLevelId = null;constructor() {super(...arguments);@@ -327,6 +327,14 @@ export default class BulkTopicActions extends Component {return this.soleCategory && this.isTagAction;}+ get disabledSubmit() {+ if (this.isNotificationAction) {+ return !this.notificationLevelId || this.loading;+ }++ return this.loading;+ }+@actiononCategoryChange(categoryId) {this.categoryId = categoryId;@@ -449,7 +457,7 @@ export default class BulkTopicActions extends Component {/><DButton@action={{this.performAction}}- @disabled={{this.loading}}+ @disabled={{this.disabledSubmit}}@icon="check"@label="topics.bulk.confirm"id="bulk-topics-confirm"diff --git a/lib/topics_bulk_action.rb b/lib/topics_bulk_action.rbindex d639a734c47..5cdd985aabf 100644--- a/lib/topics_bulk_action.rb+++ b/lib/topics_bulk_action.rb@@ -154,9 +154,13 @@ class TopicsBulkActionenddef change_notification_level+ notification_level_id = @operation[:notification_level_id]++ raise Discourse::InvalidParameters.new(:notification_level_id) if notification_level_id.blank?+topics.each do |t|if guardian.can_see?(t)- TopicUser.change(@user, t.id, notification_level: @operation[:notification_level_id].to_i)+ TopicUser.change(@user, t.id, notification_level: notification_level_id.to_i)@changed_ids << t.idendenddiff --git a/spec/lib/topics_bulk_action_spec.rb b/spec/lib/topics_bulk_action_spec.rbindex d5088cd44af..5770cdf3bcc 100644--- a/spec/lib/topics_bulk_action_spec.rb+++ b/spec/lib/topics_bulk_action_spec.rb@@ -293,6 +293,44 @@ RSpec.describe TopicsBulkAction doendend+ context "when notification_level_id is blank" do+ it "raises an invalid parameters error" do+ tba =+ TopicsBulkAction.new(+ topic.user,+ [topic.id],+ type: "change_notification_level",+ notification_level_id: "",+ )+ expect { tba.perform! }.to raise_error(+ Discourse::InvalidParameters,+ /notification_level_id/,+ )+ end++ it "raises an invalid parameters error when notification_level_id is nil" do+ tba =+ TopicsBulkAction.new(+ topic.user,+ [topic.id],+ type: "change_notification_level",+ notification_level_id: nil,+ )+ expect { tba.perform! }.to raise_error(+ Discourse::InvalidParameters,+ /notification_level_id/,+ )+ end++ it "raises an invalid parameters error when notification_level_id is missing" do+ tba = TopicsBulkAction.new(topic.user, [topic.id], type: "change_notification_level")+ expect { tba.perform! }.to raise_error(+ Discourse::InvalidParameters,+ /notification_level_id/,+ )+ end+ end+context "when the user can't see the topic" doit "doesn't change the level" doGuardian.any_instance.expects(:can_see?).returns(false)diff --git a/spec/system/page_objects/modals/topic_bulk_actions.rb b/spec/system/page_objects/modals/topic_bulk_actions.rbindex 1a02eb8cad0..d459e83b8b9 100644--- a/spec/system/page_objects/modals/topic_bulk_actions.rb+++ b/spec/system/page_objects/modals/topic_bulk_actions.rb@@ -24,6 +24,10 @@ module PageObjectsfind("#bulk-close-note").set(message)end+ def select_notification_level(level)+ find(".bulk-notification-list input[name='notification_level'][value='#{level}']").click+ end+def has_category_badge?(category)within(MODAL_SELECTOR) doPageObjects::Components::CategoryBadge.new.find_for_category(category)diff --git a/spec/system/topic_bulk_select_spec.rb b/spec/system/topic_bulk_select_spec.rbindex a7e453dc763..afadeb7ff94 100644--- a/spec/system/topic_bulk_select_spec.rb+++ b/spec/system/topic_bulk_select_spec.rb@@ -389,4 +389,35 @@ describe "Topic bulk select", type: :system doendendend++ context "when changing topic notification levels" do+ it "allows changing notification levels for selected topics" do+ sign_in(admin)+ visit("/latest")++ # Click bulk select button+ topic_list_header.click_bulk_select_button+ expect(topic_list).to have_topic_checkbox(topics.first)++ # Select Topics+ topic_list.click_topic_checkbox(topics.first)+ topic_list.click_topic_checkbox(topics.second)++ # Has Dropdown+ expect(topic_list_header).to have_bulk_select_topics_dropdown+ topic_list_header.click_bulk_select_topics_dropdown++ topic_list_header.click_bulk_button("update-notifications")+ expect(topic_bulk_actions_modal).to be_open++ # By default, the confirm button is disabled+ expect(page).to have_css("#bulk-topics-confirm:disabled")++ topic_bulk_actions_modal.select_notification_level(NotificationLevels.all[:muted])+ topic_bulk_actions_modal.click_bulk_topics_confirm++ expect(topic_list).to have_no_topic(topics.first)+ expect(topic_list).to have_no_topic(topics.second)+ end+ endend