A platform for community discussion. Free, open, simple.
UX: Raise a clear workflow error when the author cannot whisper (#44420)
Régis Hanol8a1563f37ced
diff --git a/plugins/discourse-workflows/config/locales/server.en.yml b/plugins/discourse-workflows/config/locales/server.en.ymlindex dbdc9fff8c6..e01f2f861f4 100644--- a/plugins/discourse-workflows/config/locales/server.en.yml+++ b/plugins/discourse-workflows/config/locales/server.en.yml@@ -106,6 +106,7 @@ en:invalid_filter: "Invalid topic filter: %{fragments}."post:topic_closed_or_archived: "Cannot create a post in a closed or archived topic."+ whisper_not_allowed: "%{username} cannot whisper. Check the whispers allowed groups site setting."edit_failed: "Failed to edit post."invalid_filter: "Invalid post filter: %{fragments}."flag_post:diff --git a/plugins/discourse-workflows/lib/discourse_workflows/executor/node_execution_context.rb b/plugins/discourse-workflows/lib/discourse_workflows/executor/node_execution_context.rbindex 3bee3ce1a7d..529701b1ce4 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/executor/node_execution_context.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/executor/node_execution_context.rb@@ -420,11 +420,11 @@ module DiscourseWorkflows}.compactif ActiveModel::Type::Boolean.new.cast(whisper)- unless guardian.can_create_whisper?- raise Discourse::InvalidAccess.new(- "invalid_whisper_access",- nil,- custom_message: "invalid_whisper_access",+ if !guardian.can_create_whisper?+ raise DiscourseWorkflows::NodeError,+ I18n.t(+ "discourse_workflows.errors.post.whisper_not_allowed",+ username: guardian.user.username,)enddiff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/executor/node_execution_context_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/executor/node_execution_context_spec.rbindex c07bf32f939..922b2f13c00 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/executor/node_execution_context_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/executor/node_execution_context_spec.rb@@ -946,7 +946,7 @@ RSpec.describe DiscourseWorkflows::Executor::NodeExecutionContext doexpect doctx.create_post(user: user, raw: "Unauthorized whisper", topic_id: topic.id, whisper: true)- end.to raise_error(Discourse::InvalidAccess).and not_change { topic.posts.count }+ end.to raise_error(DiscourseWorkflows::NodeError).and not_change { topic.posts.count }endit "requires the user to see the topic" dodiff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_spec.rbindex 5221d1f62a9..52500d1bf9e 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_spec.rb@@ -164,25 +164,6 @@ RSpec.describe DiscourseWorkflows::Nodes::Post::V1 do)end- it "raises when the create author cannot whisper" do- SiteSetting.whispers_allowed_groups = Group::AUTO_GROUPS[:staff].to_s- first_post = Fabricate(:post, user: user, raw: "First post", post_number: 1)- topic = first_post.topic-- expect do- execute_node(- configuration: {- "operation" => "create",- "topic_id" => topic.id.to_s,- "raw" => "Unauthorized whisper",- "whisper" => true,- "author_username" => user.username,- },- item: item,- )- end.to raise_error(Discourse::InvalidAccess).and not_change { topic.posts.count }- end-it "raises when the create author cannot be found" dofirst_post = Fabricate(:post, user: user, raw: "First post", post_number: 1)