A platform for community discussion. Free, open, simple.
FIX: provides a better error when user can't tag PM (#43019)
Joffrey JAFFEUX58f18d48d66d
diff --git a/plugins/discourse-workflows/config/locales/server.en.yml b/plugins/discourse-workflows/config/locales/server.en.ymlindex be8f3451e79..ef6bbd0a4ca 100644--- a/plugins/discourse-workflows/config/locales/server.en.yml+++ b/plugins/discourse-workflows/config/locales/server.en.yml@@ -124,6 +124,7 @@ en:topic_tags:no_tag_names: "No tag names provided."operation_failed: "Tag operation failed: %{errors}"+ personal_message_not_allowed: "'%{username}' cannot tag personal messages. Add one of their groups to the 'pm_tags_allowed_for_groups' site setting."topic_category:operation_failed: "Category change failed."private_message: "Personal messages cannot have a category."diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_tags/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_tags/v1.rbindex 57bb34000ad..3cff539c6e7 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_tags/v1.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_tags/v1.rb@@ -94,6 +94,7 @@ module DiscourseWorkflowsif names.empty?raise_node_error!(I18n.t("discourse_workflows.errors.topic_tags.no_tag_names"))end+ ensure_can_tag_personal_message!(topic, actor)case config["operation"]when "remove"@@ -107,6 +108,19 @@ module DiscourseWorkflowsendend+ def ensure_can_tag_personal_message!(topic, actor)+ guardian = actor.guardian+ return if !topic.private_message? || guardian.can_tag_pms?+ return if !SiteSetting.tagging_enabled || !guardian.authenticated?++ raise_node_error!(+ I18n.t(+ "discourse_workflows.errors.topic_tags.personal_message_not_allowed",+ username: actor.username,+ ),+ )+ end+def tag_topic!(topic, guardian, tag_names, append: false)unless DiscourseTagging.tag_topic_by_names(topic, guardian, tag_names, append:)raise_node_error!(diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_tags_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_tags_spec.rbindex acf64bbb69c..f3486872e78 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_tags_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_tags_spec.rb@@ -127,7 +127,15 @@ RSpec.describe DiscourseWorkflows::Nodes::TopicTags::V1 doendit "raises when no tag names are provided" do- config = { "operation" => "add", "topic_id" => topic.id.to_s, "tag_names" => "" }+ admin = Fabricate(:admin)+ personal_message = Fabricate(:private_message_topic)+ SiteSetting.pm_tags_allowed_for_groups = ""+ config = {+ "operation" => "add",+ "topic_id" => personal_message.id.to_s,+ "tag_names" => "",+ "actor_username" => admin.username,+ }expect { execute_node(configuration: config, item: item) }.to raise_error(DiscourseWorkflows::NodeError,@@ -135,6 +143,24 @@ RSpec.describe DiscourseWorkflows::Nodes::TopicTags::V1 do)end+ it "explains how to grant the actor permission to tag personal messages" do+ admin = Fabricate(:admin)+ personal_message = Fabricate(:private_message_topic)+ SiteSetting.pm_tags_allowed_for_groups = ""+ config = {+ "operation" => "add",+ "topic_id" => personal_message.id.to_s,+ "tag_names" => "onboarding-initiated",+ "actor_username" => admin.username,+ }++ expect { execute_node(configuration: config, item: item) }.to raise_error(+ DiscourseWorkflows::NodeError,+ "'#{admin.username}' cannot tag personal messages. Add one of their groups to the " \+ "'pm_tags_allowed_for_groups' site setting.",+ )+ end+context "with restricted tags" dofab!(:regular_user, :user)fab!(:admin)