A platform for community discussion. Free, open, simple.
FEATURE: Fill output gaps in plugin workflow nodes (#44553)
Régis Hanolef54f5a6a390
diff --git a/.skills/discourse-workflow-nodes/SKILL.md b/.skills/discourse-workflow-nodes/SKILL.mdindex 85af0353e92..e2c71b05956 100644--- a/.skills/discourse-workflow-nodes/SKILL.md+++ b/.skills/discourse-workflow-nodes/SKILL.md@@ -16,14 +16,15 @@ Shape entities only with `DiscourseWorkflows::EntitySerializers` (`lib/discourse| Topic (actions) | `serialize_topic(topic, guardian:, custom_field_names:)` | `TOPIC_LIST_ITEM_SCHEMA` || Post | `serialize_post(post, guardian:, include_raw:, include_cooked:)` (nil for nil post) | `Schema::POST_SCHEMA` / `POST_PROPERTIES` || Reviewable | `serialize_reviewable(reviewable)` | `Schema::REVIEWABLE_EVENT_SCHEMA` |-| Assignee (user or group) | `serialize_assignee(assignee, guardian:)` | |+| Assignee (user or group) | `serialize_assignee(assignee, guardian:)` | `Schema::ASSIGNEE_PROPERTIES` || Group (basic) | `serialize_basic_group(group)` | `BASIC_GROUP_PROPERTIES` || Any serializer | `serialize_record(record, SerializerClass, scope:)` | |-- Name every helper that shapes an entity for output `serialize_<entity>` (`serialize_badge`, `serialize_group`, `serialize_timer`, `serialize_assignee`, `serialize_channel`, `serialize_event`...), never `<entity>_data`.+- Name every helper that shapes an entity for output `serialize_<entity>` (`serialize_badge`, `serialize_group`, `serialize_timer`, `serialize_assignee`, `serialize_channel`, `serialize_event`...), never `<entity>_data`; `node_entity_builders_spec` fails on `def <entity>_data`.- Don't wrap a shared builder in a node-private helper; call it directly.- `serialize_topic_list_item` (`DiscourseWorkflows::TopicListItemSerializer`) carries plugin-added list fields (assign `assigned_to_*`, solved `has_accepted_answer`, voting `can_vote`/`vote_count`...); `serialize_topic` (`DiscourseWorkflows::TopicSerializer`) adds posters, participants and custom fields.- Outside a `NodeType`, call them on the module: `DiscourseWorkflows::EntitySerializers.serialize_user(...)`.+- Never use `BasicUserSerializer` or `TopicListItemSerializer` in node files; `node_entity_builders_spec` fails if you do.- Groups: `BasicGroupSerializer` (`BASIC_GROUP_PROPERTIES`) or `WebHookGroupSerializer` (`GROUP_SCHEMA`).## Output conventions@@ -31,3 +32,4 @@ Shape entities only with `DiscourseWorkflows::EntitySerializers` (`lib/discourse- URLs are absolute (`Discourse.base_url + ...`, `full_url`). Keep existing relative keys such as `post_url`.- Actions that may no-op output `changed` (boolean), computed by comparing state before and after (see badge, group, post_like).- Actions that mutate a topic also return `topic`.+- Cap user lists with a named constant (e.g. `PostEventScoping::MAX_GOING_USERNAMES`).diff --git a/plugins/boards/lib/discourse_workflows/nodes/boards_schema.rb b/plugins/boards/lib/discourse_workflows/nodes/boards_schema.rbindex d1616d27c00..7f28efa2dd0 100644--- a/plugins/boards/lib/discourse_workflows/nodes/boards_schema.rb+++ b/plugins/boards/lib/discourse_workflows/nodes/boards_schema.rb@@ -7,12 +7,21 @@ if defined?(DiscourseWorkflows)CARD_PROPERTIES = JSON.parse(<<~JSON).freeze{"id": { "type": "integer" },- "title": { "type": "string" },+ "title": { "type": ["string", "null"] },"unicode_title": { "type": "string" },"board_id": { "type": "integer" },"column_id": { "type": "integer" },"assigned_to_id": { "type": ["integer", "null"] },- "topic_id": { "type": ["integer", "null"] }+ "topic_id": { "type": ["integer", "null"] },+ "url": { "type": "string" }+ }+ JSON++ BOARD_PROPERTIES = JSON.parse(<<~JSON).freeze+ {+ "id": { "type": "integer" },+ "name": { "type": "string" },+ "url": { "type": "string" }}JSON@@ -51,19 +60,26 @@ if defined?(DiscourseWorkflows)CARD_SCHEMA =DiscourseWorkflows::Schema.entity("card",- CARD_PROPERTIES,+ CARD_PROPERTIES.merge("assignee" => DiscourseWorkflows::Schema::ASSIGNEE_PROPERTIES),"Card, with board and column details",)+ BOARD_SCHEMA = DiscourseWorkflows::Schema.entity("board", BOARD_PROPERTIES, "Board")+ACTING_USER_SCHEMA =DiscourseWorkflows::Schema.entity("acting_user",- DiscourseWorkflows::Schema::BASIC_USER_PROPERTIES,+ DiscourseWorkflows::Schema::USER_PROPERTIES,"User who moved the card",)CARD_MOVED_OUTPUT_SCHEMA =- DiscourseWorkflows::Schema.merge(CARD_SCHEMA, CARD_MOVED_SCHEMA, ACTING_USER_SCHEMA)+ DiscourseWorkflows::Schema.merge(+ CARD_SCHEMA,+ BOARD_SCHEMA,+ CARD_MOVED_SCHEMA,+ ACTING_USER_SCHEMA,+ )endendenddiff --git a/plugins/boards/lib/discourse_workflows/nodes/card_moved/v1.rb b/plugins/boards/lib/discourse_workflows/nodes/card_moved/v1.rbindex 352e46d8d72..2e31d9870b4 100644--- a/plugins/boards/lib/discourse_workflows/nodes/card_moved/v1.rb+++ b/plugins/boards/lib/discourse_workflows/nodes/card_moved/v1.rb@@ -83,14 +83,19 @@ if defined?(DiscourseWorkflows){card:@card.as_json(- only: BoardsSchema::CARD_PROPERTIES.keys - ["unicode_title"],- methods: [:unicode_title],- ),+ only: BoardsSchema::CARD_PROPERTIES.keys - %w[unicode_title url],+ methods: %i[unicode_title url],+ ).merge("assignee" => serialize_assignee(@card.assigned_to)),+ board: {+ id: @card.board.id,+ name: @card.board.name,+ url: @card.board.url,+ },card_moved: {old_column: serialize_column(@old_column),new_column: serialize_column(@new_column),},- acting_user: serialize_record(@acting_user, BasicUserSerializer),+ acting_user: serialize_user(@acting_user),}enddiff --git a/plugins/boards/spec/lib/discourse_workflows/nodes/card_moved/v1_spec.rb b/plugins/boards/spec/lib/discourse_workflows/nodes/card_moved/v1_spec.rbindex dadd66a0a3c..c03b48a78e6 100644--- a/plugins/boards/spec/lib/discourse_workflows/nodes/card_moved/v1_spec.rb+++ b/plugins/boards/spec/lib/discourse_workflows/nodes/card_moved/v1_spec.rb@@ -107,9 +107,24 @@ RSpec.describe DiscourseWorkflows::Nodes::CardMoved::V1 doendit "returns card and column data that conforms to the output schema" do+ card.update!(assigned_to: manage_group)+expect(trigger.output).to match_node_output_schema(described_class)expect(trigger.output).to include(- card: include("id" => card.id, "board_id" => board.id, "column_id" => new_column.id),+ card:+ include(+ "id" => card.id,+ "board_id" => board.id,+ "column_id" => new_column.id,+ "url" => card.url,+ "assignee" =>+ include(type: "group", group: include(id: manage_group.id, name: manage_group.name)),+ ),+ board: {+ id: board.id,+ name: board.name,+ url: board.url,+ },card_moved: {old_column: include("id" => old_column.id, "board_id" => board.id),new_column: include("id" => new_column.id, "board_id" => board.id),diff --git a/plugins/chat/config/locales/client.en.yml b/plugins/chat/config/locales/client.en.ymlindex ffe1963cce3..e5f849465c2 100644--- a/plugins/chat/config/locales/client.en.yml+++ b/plugins/chat/config/locales/client.en.yml@@ -952,6 +952,8 @@ en:user: "Users (a direct message each)"group: "Group (one direct message with everyone)"channel_id: "Channel"+ thread_id: "Thread ID"+ thread_id_description: "Reply in this thread instead of the main channel. Leave blank to post in the channel."target_usernames: "Recipients"target_usernames_description: "Users to message. Use an expression such as $trigger.user.username to pick them from each item."message: "Message"diff --git a/plugins/chat/lib/discourse_workflows/nodes/chat_approval/v2.rb b/plugins/chat/lib/discourse_workflows/nodes/chat_approval/v2.rbindex 38241140f43..fe771fd9ce1 100644--- a/plugins/chat/lib/discourse_workflows/nodes/chat_approval/v2.rb+++ b/plugins/chat/lib/discourse_workflows/nodes/chat_approval/v2.rb@@ -28,7 +28,7 @@ if defined?(DiscourseWorkflows)},"user" => {"type" => "object",- "properties" => DiscourseWorkflows::Schema::BASIC_USER_PROPERTIES,+ "properties" => DiscourseWorkflows::Schema::USER_PROPERTIES,},},}.freeze@@ -233,9 +233,8 @@ if defined?(DiscourseWorkflows)user = interaction.userchannel = interaction.message.chat_channelscope = user.guardian- channel_data =- Chat::WorkflowChannelSerializer.new(channel, scope: scope, root: false).as_json- user_data = BasicUserSerializer.new(user, scope: scope, root: false).as_json+ channel_data = serialize_record(channel, Chat::WorkflowChannelSerializer, scope:)+ user_data = serialize_user(user, guardian: scope)[DiscourseWorkflows::Item.wrap(diff --git a/plugins/chat/lib/discourse_workflows/nodes/chat_message_created/v1.rb b/plugins/chat/lib/discourse_workflows/nodes/chat_message_created/v1.rbindex 77aa0cafcaa..bf39b7c9893 100644--- a/plugins/chat/lib/discourse_workflows/nodes/chat_message_created/v1.rb+++ b/plugins/chat/lib/discourse_workflows/nodes/chat_message_created/v1.rb@@ -49,16 +49,16 @@ if defined?(DiscourseWorkflows)"chat_channel_id" => {"type" => "integer",},+ "url" => {+ "type" => "string",+ },},},"channel" => {"type" => "object","properties" => Chat::WorkflowChannelSerializer::PROPERTIES,},- "user" => {- "type" => "object",- "properties" => DiscourseWorkflows::Schema::BASIC_USER_PROPERTIES,- },+ "user" => DiscourseWorkflows::Schema.nullable_user("Message author"),},},},@@ -127,20 +127,15 @@ if defined?(DiscourseWorkflows)created_at: @message.created_at.iso8601,thread_id: @message.thread_id,chat_channel_id: @message.chat_channel_id,+ url: @message.full_url,},channel: serialize_channel,- user: user_data,+ user: serialize_user(@user),}endprivate- def user_data- return {} if @user.blank?-- serialize_record(@user, BasicUserSerializer)- end-def serialize_channelscope = @user&.guardian || Discourse.system_user.guardianserialize_record(@channel, Chat::WorkflowChannelSerializer, scope:)diff --git a/plugins/chat/lib/discourse_workflows/nodes/send_chat_message/v1.rb b/plugins/chat/lib/discourse_workflows/nodes/send_chat_message/v1.rbindex 6dd8eb9f103..9aad68bd303 100644--- a/plugins/chat/lib/discourse_workflows/nodes/send_chat_message/v1.rb+++ b/plugins/chat/lib/discourse_workflows/nodes/send_chat_message/v1.rb@@ -46,6 +46,9 @@ if defined?(DiscourseWorkflows)"message" => {"type" => "string",},+ "thread_id" => {+ "type" => %w[integer null],+ },"username" => {"type" => "string",},@@ -96,6 +99,15 @@ if defined?(DiscourseWorkflows)hidden: true,},},+ thread_id: {+ type: :integer,+ required: false,+ display_options: {+ show: {+ target: ["channel"],+ },+ },+ },target_usernames: {type: :array,required: true,@@ -172,6 +184,7 @@ if defined?(DiscourseWorkflows)sender.guardian,channel,sender: sender.username,+ thread_id: run.parameter("thread_id").presence,channel_id: channel.id,),)@@ -335,11 +348,12 @@ if defined?(DiscourseWorkflows)endend- def create_message(run, target, guardian, channel, **labels)+ def create_message(run, target, guardian, channel, thread_id: nil, **labels)Chat::CreateMessage.call(guardian:,params: {chat_channel_id: channel.id,+ thread_id:,message: run.message,},) do |result|@@ -356,6 +370,7 @@ if defined?(DiscourseWorkflows)"channel_id" => channel.id,"message_id" => message_instance.id,"message" => run.message,+ "thread_id" => message_instance.thread_id,}endon_failed_contract { |contract| invalid_params!(run, contract) }diff --git a/plugins/chat/spec/lib/discourse_workflows/nodes/chat_approval/v2_spec.rb b/plugins/chat/spec/lib/discourse_workflows/nodes/chat_approval/v2_spec.rbindex feadb250921..0144b90f437 100644--- a/plugins/chat/spec/lib/discourse_workflows/nodes/chat_approval/v2_spec.rb+++ b/plugins/chat/spec/lib/discourse_workflows/nodes/chat_approval/v2_spec.rb@@ -73,21 +73,6 @@ RSpec.describe DiscourseWorkflows::Nodes::ChatApproval::V2 doit "exposes the exact click output and timeout continuation contracts" doinput_schema = DiscourseWorkflows::Schema::POST_SCHEMA- expected_properties = {- "value" => {- "type" => "string",- },- "channel" => {- "type" => "object",- "properties" => Chat::WorkflowChannelSerializer::PROPERTIES,- },- "user" => {- "type" => "object",- "properties" => DiscourseWorkflows::Schema::BASIC_USER_PROPERTIES,- },- }-- expect(described_class::CLICK_OUTPUT_SCHEMA.fetch("properties")).to eq(expected_properties)expect(described_class.output_schemas({})).to eq([described_class::CLICK_OUTPUT_SCHEMA])expect(described_class.output_schemas(diff --git a/plugins/chat/spec/lib/discourse_workflows/nodes/chat_message_created_spec.rb b/plugins/chat/spec/lib/discourse_workflows/nodes/chat_message_created_spec.rbindex cd925756ae2..6107ecb9348 100644--- a/plugins/chat/spec/lib/discourse_workflows/nodes/chat_message_created_spec.rb+++ b/plugins/chat/spec/lib/discourse_workflows/nodes/chat_message_created_spec.rb@@ -53,6 +53,7 @@ RSpec.describe DiscourseWorkflows::Nodes::ChatMessageCreated::V1 doid: message.id,message: message.message,chat_channel_id: channel.id,+ url: message.full_url,)expect(output[:channel]).to include(id: channel.id, slug: channel.slug)expect(output[:user]).to include(@@ -63,6 +64,13 @@ RSpec.describe DiscourseWorkflows::Nodes::ChatMessageCreated::V1 doexpect(output).to match_node_output_schema(described_class)end+ it "returns a nil user when there is no user", :aggregate_failures do+ output = described_class.new(message, channel, nil).output++ expect(output[:user]).to be_nil+ expect(output).to match_node_output_schema(described_class)+ end+it "matches nodes with no channel filter or the same channel" dotrigger = described_class.new(message, channel, user)diff --git a/plugins/chat/spec/lib/discourse_workflows/nodes/send_chat_message_spec.rb b/plugins/chat/spec/lib/discourse_workflows/nodes/send_chat_message_spec.rbindex 4a386bea56f..3163889f3e6 100644--- a/plugins/chat/spec/lib/discourse_workflows/nodes/send_chat_message_spec.rb+++ b/plugins/chat/spec/lib/discourse_workflows/nodes/send_chat_message_spec.rb@@ -99,10 +99,21 @@ RSpec.describe DiscourseWorkflows::Nodes::SendChatMessage::V1 dofirst, second = channel.chat_messages.order(:id).last(2)expect(output.first.map { |item| item["json"] }).to eq([- { "channel_id" => channel.id, "message_id" => first.id, "message" => "First message" },- { "channel_id" => channel.id, "message_id" => second.id, "message" => "Second message" },+ {+ "channel_id" => channel.id,+ "message_id" => first.id,+ "message" => "First message",+ "thread_id" => nil,+ },+ {+ "channel_id" => channel.id,+ "message_id" => second.id,+ "message" => "Second message",+ "thread_id" => nil,+ },],)+ expect(output.first.first["json"]).to match_node_output_schema(described_class)expect([first, second].map(&:message)).to eq(["First message", "Second message"])expect([first, second].map(&:user_id)).to all(eq(Discourse.system_user.id))expect(log).to eq(@@ -119,6 +130,30 @@ RSpec.describe DiscourseWorkflows::Nodes::SendChatMessage::V1 do)end+ it "replies in the given thread" do+ channel.update!(threading_enabled: true)+ thread = Fabricate(:chat_thread, channel:)++ output =+ execute_node_output(+ configuration: {+ "channel_id" => channel.id.to_s,+ "thread_id" => "={{ $json.thread_id }}",+ "message" => "In thread",+ },+ item: {+ "json" => {+ "thread_id" => thread.id,+ },+ },+ )++ json = output.first.sole["json"]+ expect(json["thread_id"]).to eq(thread.id)+ expect(Chat::Message.find(json["message_id"]).thread_id).to eq(thread.id)+ expect(json).to match_node_output_schema(described_class)+ end+it "rejects expression-resolved channels outside the selectable channel scope" doclosed_channel = Fabricate(:chat_channel, name: "Closed", status: :closed)@@ -202,6 +237,7 @@ RSpec.describe DiscourseWorkflows::Nodes::SendChatMessage::V1 do"channel_id" => channel.id,"message_id" => message.id,"message" => "Hello channel",+ "thread_id" => nil,)expect(message.user_id).to eq(sender.id)expect(log).to eq(@@ -342,8 +378,10 @@ RSpec.describe DiscourseWorkflows::Nodes::SendChatMessage::V1 do"channel_id" => message.chat_channel_id,"message_id" => message.id,"message" => "Hello there",+ "thread_id" => nil,"username" => recipient.username,)+ expect(json).to match_node_output_schema(described_class)expect(message).to have_attributes(message: "Hello there", user_id: Discourse.system_user.id)expect(dm_user_ids(json["channel_id"])).to contain_exactly(Discourse.system_user.id,@@ -572,6 +610,7 @@ RSpec.describe DiscourseWorkflows::Nodes::SendChatMessage::V1 doitem = output.first.solechannel_id = item["json"]["channel_id"]expect(item["json"]).to include("usernames" => usernames, "message" => "Hello there")+ expect(item["json"]).to match_node_output_schema(described_class)expect(item["pairedItem"]).to eq("item" => 0)expect(Chat::Channel.find(channel_id).chatable).to be_groupexpect(dm_user_ids(channel_id)).to contain_exactly(diff --git a/plugins/chat/spec/services/chat/workflows/approval/resume_interaction_spec.rb b/plugins/chat/spec/services/chat/workflows/approval/resume_interaction_spec.rbindex 3b6a3202568..8fb5a74d937 100644--- a/plugins/chat/spec/services/chat/workflows/approval/resume_interaction_spec.rb+++ b/plugins/chat/spec/services/chat/workflows/approval/resume_interaction_spec.rb@@ -232,12 +232,8 @@ RSpec.describe Chat::Workflows::Approval::ResumeInteraction doit "returns the configured value, channel, and clicking user as one paired item" doexpect(result).to run_successfully- expected_user = {- "id" => clicking_user.id,- "username" => clicking_user.username,- "name" => clicking_user.name,- "avatar_template" => clicking_user.avatar_template,- }+ expected_user =+ DiscourseWorkflows::EntitySerializers.serialize_user(clicking_user).deep_stringify_keysexpected_channel = {"id" => channel.id,"title" => channel.title(clicking_user),@@ -261,6 +257,9 @@ RSpec.describe Chat::Workflows::Approval::ResumeInteraction do},],)+ expect(+ execution.execution_data.context_data.dig("Wait", 0, "json"),+ ).to match_node_output_schema(DiscourseWorkflows::Nodes::ChatApproval::V2)expect(execution.execution_data.context_data.dig("After", 0, "json")).to include("value" => "needs:changes","current_user_id" => clicking_user.id,diff --git a/plugins/discourse-assign/lib/discourse_assign/workflows/assignment_trigger.rb b/plugins/discourse-assign/lib/discourse_assign/workflows/assignment_trigger.rbnew file mode 100644index 00000000000..7c41d791c42--- /dev/null+++ b/plugins/discourse-assign/lib/discourse_assign/workflows/assignment_trigger.rb@@ -0,0 +1,55 @@+# frozen_string_literal: true++module DiscourseAssign+ module Workflows+ module AssignmentTrigger+ def initialize(assignment, *)+ super(parameters: {})+ @assignment = assignment+ end++ def valid?+ @assignment.present? && @assignment.topic.present? && @assignment.assigned_to.present? &&+ post.present?+ end++ def matches?(trigger_ctx)+ !trigger_ctx.get_node_parameter("topic_assignments_only", false) || topic_assignment?+ end++ def output+ {+ assignment: serialize_assignment,+ post: serialize_post(post),+ topic: serialize_topic_list_item(@assignment.topic),+ }+ end++ private++ def serialize_assignment+ {+ id: @assignment.id,+ target_type: @assignment.target_type,+ target_id: @assignment.target_id,+ topic_id: @assignment.topic_id,+ topic_assignment: topic_assignment?,+ assigned_to_id: @assignment.assigned_to_id,+ assigned_to_type: @assignment.assigned_to_type,+ assigned_to: serialize_assignee(@assignment.assigned_to),+ assigned_by_user: serialize_user(@assignment.assigned_by_user),+ note: @assignment.note,+ status: @assignment.status,+ }+ end++ def post+ @post ||= @assignment.post+ end++ def topic_assignment?+ @assignment.target_type == "Topic"+ end+ end+ end+enddiff --git a/plugins/discourse-assign/lib/discourse_assign/workflows/schema.rb b/plugins/discourse-assign/lib/discourse_assign/workflows/schema.rbindex fbf3a4228c6..a45b4731758 100644--- a/plugins/discourse-assign/lib/discourse_assign/workflows/schema.rb+++ b/plugins/discourse-assign/lib/discourse_assign/workflows/schema.rb@@ -3,29 +3,12 @@module DiscourseAssignmodule Workflowsmodule Schema- ASSIGNEE_SCHEMA = {- "type" => "object",- "properties" => {- "type" => {- "type" => %w[string null],- },- "user" => {- "type" => "object",- "properties" => DiscourseWorkflows::Schema::BASIC_USER_PROPERTIES,- },- "group" => {- "type" => "object",- "properties" => DiscourseWorkflows::Schema::BASIC_GROUP_PROPERTIES,- },- },- }.freeze-ASSIGN_TOPIC_OUTPUT_SCHEMA = {"$schema" => DiscourseWorkflows::Schema::DRAFT_URI,"type" => "object","properties" => {- "assignee" => ASSIGNEE_SCHEMA,- "previously_assigned" => ASSIGNEE_SCHEMA,+ "assignee" => DiscourseWorkflows::Schema::ASSIGNEE_PROPERTIES,+ "previously_assigned" => DiscourseWorkflows::Schema::ASSIGNEE_PROPERTIES,},}.freeze@@ -67,11 +50,9 @@ module DiscourseAssign"assigned_to_type" => {"type" => "string",},- "assigned_to" => ASSIGNEE_SCHEMA,- "assigned_by_user" => {- "type" => "object",- "properties" => DiscourseWorkflows::Schema::BASIC_USER_PROPERTIES,- },+ "assigned_to" => DiscourseWorkflows::Schema::ASSIGNEE_PROPERTIES,+ "assigned_by_user" =>+ DiscourseWorkflows::Schema.nullable_user("User who made the assignment"),"note" => {"type" => %w[string null],},@@ -83,14 +64,7 @@ module DiscourseAssign},}.freeze- ASSIGNED_OUTPUT_SCHEMA =- DiscourseWorkflows::Schema.merge(- DiscourseWorkflows::Schema::POST_SCHEMA,- DiscourseWorkflows::Schema::TOPIC_LIST_ITEM_SCHEMA,- ASSIGNMENT_SCHEMA,- ).freeze-- UNASSIGNED_OUTPUT_SCHEMA =+ ASSIGNMENT_OUTPUT_SCHEMA =DiscourseWorkflows::Schema.merge(DiscourseWorkflows::Schema::POST_SCHEMA,DiscourseWorkflows::Schema::TOPIC_LIST_ITEM_SCHEMA,diff --git a/plugins/discourse-assign/lib/discourse_workflows/nodes/assigned/v1.rb b/plugins/discourse-assign/lib/discourse_workflows/nodes/assigned/v1.rbindex ae7fc656605..6fefc6e33b2 100644--- a/plugins/discourse-assign/lib/discourse_workflows/nodes/assigned/v1.rb+++ b/plugins/discourse-assign/lib/discourse_workflows/nodes/assigned/v1.rb@@ -5,6 +5,8 @@ if defined?(DiscourseWorkflows)module Nodesmodule Assignedclass V1 < DiscourseWorkflows::NodeType+ include DiscourseAssign::Workflows::AssignmentTrigger+description(name: "trigger:assigned",version: "1.0",@@ -17,7 +19,7 @@ if defined?(DiscourseWorkflows)available: -> { SiteSetting.assign_enabled },unavailable_reason_key: "discourse_workflows.node_unavailable.requires_assign",output_contracts: [- { schema: DiscourseAssign::Workflows::Schema::ASSIGNED_OUTPUT_SCHEMA },+ { schema: DiscourseAssign::Workflows::Schema::ASSIGNMENT_OUTPUT_SCHEMA },],properties: {topic_assignments_only: {@@ -29,54 +31,6 @@ if defined?(DiscourseWorkflows)},},)-- def initialize(assignment, *)- super(parameters: {})- @assignment = assignment- end-- def valid?- @assignment.present? && @assignment.topic.present? &&- @assignment.assigned_to.present? && post.present?- end-- def output- {- assignment: serialize_assignment,- post: serialize_post(post),- topic: serialize_record(@assignment.topic, TopicListItemSerializer),- }- end-- def matches?(trigger_ctx)- !trigger_ctx.get_node_parameter("topic_assignments_only", false) || topic_assignment?- end-- private-- def serialize_assignment- {- id: @assignment.id,- target_type: @assignment.target_type,- target_id: @assignment.target_id,- topic_id: @assignment.topic_id,- topic_assignment: topic_assignment?,- assigned_to_id: @assignment.assigned_to_id,- assigned_to_type: @assignment.assigned_to_type,- assigned_to: serialize_assignee(@assignment.assigned_to),- assigned_by_user: serialize_record(@assignment.assigned_by_user, BasicUserSerializer),- note: @assignment.note,- status: @assignment.status,- }- end-- def post- @post ||= @assignment.post- end-- def topic_assignment?- @assignment.target_type == "Topic"- endendendenddiff --git a/plugins/discourse-assign/lib/discourse_workflows/nodes/unassigned/v1.rb b/plugins/discourse-assign/lib/discourse_workflows/nodes/unassigned/v1.rbindex 7fb2dfb077b..d2934471ecd 100644--- a/plugins/discourse-assign/lib/discourse_workflows/nodes/unassigned/v1.rb+++ b/plugins/discourse-assign/lib/discourse_workflows/nodes/unassigned/v1.rb@@ -5,6 +5,8 @@ if defined?(DiscourseWorkflows)module Nodesmodule Unassignedclass V1 < DiscourseWorkflows::NodeType+ include DiscourseAssign::Workflows::AssignmentTrigger+description(name: "trigger:unassigned",version: "1.0",@@ -17,7 +19,7 @@ if defined?(DiscourseWorkflows)available: -> { SiteSetting.assign_enabled },unavailable_reason_key: "discourse_workflows.node_unavailable.requires_assign",output_contracts: [- { schema: DiscourseAssign::Workflows::Schema::UNASSIGNED_OUTPUT_SCHEMA },+ { schema: DiscourseAssign::Workflows::Schema::ASSIGNMENT_OUTPUT_SCHEMA },],properties: {topic_assignments_only: {@@ -29,54 +31,6 @@ if defined?(DiscourseWorkflows)},},)-- def initialize(assignment, *)- super(parameters: {})- @assignment = assignment- end-- def valid?- @assignment.present? && @assignment.topic.present? &&- @assignment.assigned_to.present? && post.present?- end-- def output- {- assignment: serialize_assignment,- post: serialize_post(post),- topic: serialize_record(@assignment.topic, TopicListItemSerializer),- }- end-- def matches?(trigger_ctx)- !trigger_ctx.get_node_parameter("topic_assignments_only", false) || topic_assignment?- end-- private-- def serialize_assignment- {- id: @assignment.id,- target_type: @assignment.target_type,- target_id: @assignment.target_id,- topic_id: @assignment.topic_id,- topic_assignment: topic_assignment?,- assigned_to_id: @assignment.assigned_to_id,- assigned_to_type: @assignment.assigned_to_type,- assigned_to: serialize_assignee(@assignment.assigned_to),- assigned_by_user: serialize_record(@assignment.assigned_by_user, BasicUserSerializer),- note: @assignment.note,- status: @assignment.status,- }- end-- def post- @post ||= @assignment.post- end-- def topic_assignment?- @assignment.target_type == "Topic"- endendendenddiff --git a/plugins/discourse-chat-integration/lib/discourse_workflows/nodes/send_chat_integration_message/v1.rb b/plugins/discourse-chat-integration/lib/discourse_workflows/nodes/send_chat_integration_message/v1.rbindex f1f72c9ed20..13efcbf2cfd 100644--- a/plugins/discourse-chat-integration/lib/discourse_workflows/nodes/send_chat_integration_message/v1.rb+++ b/plugins/discourse-chat-integration/lib/discourse_workflows/nodes/send_chat_integration_message/v1.rb@@ -46,7 +46,7 @@ if defined?(DiscourseWorkflows)},ui: {control: :combo_box,- dynamic_value: :chat_channel_id,+ dynamic_value: :chat_integration_channel_id,},control_options: {action_icon: "wrench",diff --git a/plugins/discourse-chat-integration/spec/lib/discourse_workflows/nodes/send_chat_integration_message_spec.rb b/plugins/discourse-chat-integration/spec/lib/discourse_workflows/nodes/send_chat_integration_message_spec.rbindex f37b21b5aa9..32e59538350 100644--- a/plugins/discourse-chat-integration/spec/lib/discourse_workflows/nodes/send_chat_integration_message_spec.rb+++ b/plugins/discourse-chat-integration/spec/lib/discourse_workflows/nodes/send_chat_integration_message_spec.rb@@ -43,7 +43,7 @@ RSpec.describe DiscourseWorkflows::Nodes::SendChatIntegrationMessage::V1 doit "preserves the selected channel label for dynamic values", :aggregate_failures doschema = described_class.property_schema- expect(schema.dig(:channel_id, :ui, :dynamic_value)).to eq(:chat_channel_id)+ expect(schema.dig(:channel_id, :ui, :dynamic_value)).to eq(:chat_integration_channel_id)expect(schema.dig(:channel_id, :control_options, :set_from_option)).to eq(channel_name: "name",)diff --git a/plugins/discourse-events/lib/discourse_workflows/nodes/post_event_schema.rb b/plugins/discourse-events/lib/discourse_workflows/nodes/post_event_schema.rbindex ca81b1d8777..88e78b0a6f8 100644--- a/plugins/discourse-events/lib/discourse_workflows/nodes/post_event_schema.rb+++ b/plugins/discourse-events/lib/discourse_workflows/nodes/post_event_schema.rb@@ -14,11 +14,13 @@ if defined?(DiscourseWorkflows)"timezone": { "type": ["string", "null"] },"all_day": { "type": "boolean" },"closed": { "type": "boolean" },+ "chat_channel_id": { "type": ["integer", "null"] },"recurring": { "type": "boolean" },"recurrence": { "type": ["string", "null"] },"starts_at": { "type": ["string", "null"], "format": "date-time" },"ends_at": { "type": ["string", "null"], "format": "date-time" },- "custom_fields": { "type": "object" }+ "custom_fields": { "type": "object" },+ "going_usernames": { "type": "array", "items": { "type": "string" } }}JSON@@ -26,7 +28,8 @@ if defined?(DiscourseWorkflows){"id": { "type": "integer" },"post_number": { "type": "integer" },- "url": { "type": ["string", "null"] }+ "url": { "type": ["string", "null"] },+ "username": { "type": ["string", "null"] }}JSONdiff --git a/plugins/discourse-events/lib/discourse_workflows/nodes/post_event_scoping.rb b/plugins/discourse-events/lib/discourse_workflows/nodes/post_event_scoping.rbindex 0162d4405cf..7cdebcdbdb9 100644--- a/plugins/discourse-events/lib/discourse_workflows/nodes/post_event_scoping.rb+++ b/plugins/discourse-events/lib/discourse_workflows/nodes/post_event_scoping.rb@@ -8,6 +8,8 @@ if defined?(DiscourseWorkflows)# `topic_id`/`topic_id_description` from one translated pair.I18N_SCOPE = "post_event"+ MAX_GOING_USERNAMES = 100+SCOPE_PROPERTIES = {topic_id: {type: :string,@@ -38,11 +40,13 @@ if defined?(DiscourseWorkflows)timezone: event.timezone,all_day: !!event.all_day,closed: !!event.closed,+ chat_channel_id: event.chat_channel_id,recurring: event.recurring?,recurrence: event.recurrence,starts_at: starts_at&.iso8601,ends_at: ends_at&.iso8601,custom_fields: event.custom_fields || {},+ going_usernames: going_usernames,}end@@ -50,7 +54,21 @@ if defined?(DiscourseWorkflows)post = event&.postreturn nil if post.blank?- { id: post.id, post_number: post.post_number, url: post.url }+ {+ id: post.id,+ post_number: post.post_number,+ url: post.url,+ username: post.user&.username,+ }+ end++ def going_usernames+ event+ .invitees+ .with_status(:going)+ .order(:created_at)+ .limit(MAX_GOING_USERNAMES)+ .pluck("users.username")enddef serialize_event_statsdiff --git a/plugins/discourse-events/spec/lib/discourse_workflows/nodes/event_ended/v1_spec.rb b/plugins/discourse-events/spec/lib/discourse_workflows/nodes/event_ended/v1_spec.rbindex b875b4ae99b..9ac12cb1fec 100644--- a/plugins/discourse-events/spec/lib/discourse_workflows/nodes/event_ended/v1_spec.rb+++ b/plugins/discourse-events/spec/lib/discourse_workflows/nodes/event_ended/v1_spec.rb@@ -43,16 +43,40 @@ RSpec.describe DiscourseWorkflows::Nodes::EventEnded::V1 dodescribe "#output" doit "returns the event, post, topic and RSVP counts", :aggregate_failures doDiscourseEvents::Events::Invitee.create_attendance!(Fabricate(:user).id, event.id, :going)+ channel = Fabricate(:category_channel)+ event.update_column(:chat_channel_id, channel.id)output = described_class.new(event, event_date).output- expect(output[:event]).to include(id: event.id, name: event.name)- expect(output[:post]).to include(id: event.post.id)+ expect(output[:event]).to include(id: event.id, name: event.name, chat_channel_id: channel.id)+ expect(output[:post]).to include(id: event.post.id, username: event.post.user.username)expect(output[:topic][:id]).to eq(topic.id)expect(output[:stats][:going]).to eq(1)expect(output).to match_node_output_schema(described_class)end+ it "lists the usernames going, excluding suspended, silenced and staged users" do+ going = Fabricate(:user)+ DiscourseEvents::Events::Invitee.create_attendance!(going.id, event.id, :going)+ DiscourseEvents::Events::Invitee.create_attendance!(+ Fabricate(:user).id,+ event.id,+ :interested,+ )++ %i[suspended silenced staged].each do |trait|+ user = Fabricate(:user)+ DiscourseEvents::Events::Invitee.create_attendance!(user.id, event.id, :going)+ user.update_columns(+ trait == :staged ? { staged: true } : { "#{trait}_till": 1.year.from_now },+ )+ end++ output = described_class.new(event, event_date).output++ expect(output[:event][:going_usernames]).to contain_exactly(going.username)+ end+it "reports the dates of the occurrence that ended, not the next one" doended_at = 2.days.agoevent_date.update!(starts_at: 3.days.ago, ends_at: ended_at)diff --git a/plugins/discourse-topic-voting/lib/discourse_workflows/nodes/topic_received_vote/v1.rb b/plugins/discourse-topic-voting/lib/discourse_workflows/nodes/topic_received_vote/v1.rbindex ac92748eb39..4607847bc2b 100644--- a/plugins/discourse-topic-voting/lib/discourse_workflows/nodes/topic_received_vote/v1.rb+++ b/plugins/discourse-topic-voting/lib/discourse_workflows/nodes/topic_received_vote/v1.rb@@ -37,7 +37,7 @@ if defined?(DiscourseWorkflows)def output{- topic: serialize_record(topic, TopicListItemSerializer),+ topic: serialize_topic_list_item(topic),user: serialize_user(voter),vote: {id: @vote.id,diff --git a/plugins/discourse-workflows/config/locales/client.en.yml b/plugins/discourse-workflows/config/locales/client.en.ymlindex a8dd5b46f25..b3cbce8368c 100644--- a/plugins/discourse-workflows/config/locales/client.en.yml+++ b/plugins/discourse-workflows/config/locales/client.en.yml@@ -933,6 +933,7 @@ en:boolean: "true or false"category_id: "a category ID"chat_channel_id: "a chat channel ID"+ chat_integration_channel_id: "a chat integration channel ID"column_name: "a column name"data_table_id: "a data table ID"group_id: "a group ID"diff --git a/plugins/discourse-workflows/lib/discourse_workflows/entity_serializers.rb b/plugins/discourse-workflows/lib/discourse_workflows/entity_serializers.rbindex 20cbc39881e..d8ab0b71365 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/entity_serializers.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/entity_serializers.rb@@ -59,10 +59,7 @@ module DiscourseWorkflowscase assigneewhen ::User- base.merge(- type: "user",- user: serialize_record(assignee, BasicUserSerializer, scope: guardian),- )+ base.merge(type: "user", user: serialize_user(assignee, guardian:))when ::Groupbase.merge(type: "group",diff --git a/plugins/discourse-workflows/lib/discourse_workflows/schema.rb b/plugins/discourse-workflows/lib/discourse_workflows/schema.rbindex 7c53580d645..4398e411225 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/schema.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/schema.rb@@ -112,15 +112,6 @@ module DiscourseWorkflows}JSON- BASIC_USER_PROPERTIES = JSON.parse(<<~JSON).freeze- {- "id": { "type": "integer" },- "username": { "type": "string" },- "name": { "type": ["string", "null"] },- "avatar_template": { "type": "string" }- }- JSON-USER_PROPERTIES = JSON.parse(<<~JSON).freeze{"id": { "type": "integer" },@@ -176,9 +167,26 @@ module DiscourseWorkflowsTOPIC_LIST_ITEM_SCHEMA = entity("topic", TOPIC_PROPERTIES, "Workflow topic payload")POST_SCHEMA = entity("post", POST_PROPERTIES, "DiscourseWorkflows::PostSerializer payload")- BASIC_USER_SCHEMA = entity("user", BASIC_USER_PROPERTIES, "BasicUserSerializer payload")USER_SCHEMA = entity("user", USER_PROPERTIES, "Basic safe user attributes")ACTOR_SCHEMA = document("actor" => nullable_user("User who performed the action"))+ ASSIGNEE_PROPERTIES = {+ "type" => "object",+ "properties" => {+ "type" => {+ "type" => %w[string null],+ },+ "user" => {+ "type" => "object",+ "x-optional" => true,+ "properties" => USER_PROPERTIES,+ },+ "group" => {+ "type" => "object",+ "x-optional" => true,+ "properties" => BASIC_GROUP_PROPERTIES,+ },+ },+ }.freezeIP_LOCATION_PROPERTIES = JSON.parse(<<~JSON).freeze{"type": ["object", "null"],diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/ai/tools/workflow_node_catalog_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/ai/tools/workflow_node_catalog_spec.rbindex 82cf9490cf3..9df2411983d 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/ai/tools/workflow_node_catalog_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/ai/tools/workflow_node_catalog_spec.rb@@ -243,12 +243,8 @@ RSpec.describe DiscourseWorkflows::Ai::Tools::WorkflowNodeCatalog do"user.id" => "integer","user.username" => "string","user.avatar_template" => "string",- )- expect(output_fields_by_type.fetch("trigger:chat_message_created")).not_to include(- "user.trust_level",- "user.admin",- "user.moderator",- "user.staff",+ "user.trust_level" => "integer",+ "user.staff" => "boolean",)expect(output_fields_by_type.fetch("action:ai_agent")).to include("result" => "string")enddiff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/node_entity_builders_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/node_entity_builders_spec.rbnew file mode 100644index 00000000000..7da22fcb1ad--- /dev/null+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/node_entity_builders_spec.rb@@ -0,0 +1,63 @@+# frozen_string_literal: true++RSpec.describe DiscourseWorkflows::NodeType do+ let(:node_source_globs) do+ %w[+ plugins/*/lib/discourse_workflows/**/*.rb+ plugins/*/lib/*/workflows/**/*.rb+ plugins/discourse-ai/discourse_workflows/**/*.rb+ ]+ end+ let(:builders_file) do+ "plugins/discourse-workflows/lib/discourse_workflows/entity_serializers.rb"+ end+ let(:banned_serializers) { /\b(BasicUserSerializer|TopicListItemSerializer)\b/ }+ let(:entity_names) do+ %w[+ user+ post+ topic+ group+ reviewable+ event+ badge+ tag+ channel+ message+ card+ board+ assignee+ assignment+ stats+ timer+ participation+ chat_message+ ]+ end+ let(:banned_entity_data_definitions) { /^\s*def\s+(self\.)?(#{entity_names.join("|")})_data\b/ }++ def node_source_paths+ node_source_globs+ .flat_map { |glob| Dir[Rails.root.join(glob)] }+ .uniq+ .map { |path| Pathname.new(path).relative_path_from(Rails.root).to_s }+ end++ it "builds users and topics through the NodeType helpers" do+ offenders =+ node_source_paths+ .reject { |path| path == builders_file }+ .select { |path| Rails.root.join(path).read.match?(banned_serializers) }++ expect(offenders).to be_empty+ end++ it "names entity builders serialize_<entity>" do+ offenders =+ node_source_paths.select do |path|+ Rails.root.join(path).read.match?(banned_entity_data_definitions)+ end++ expect(offenders).to be_empty+ end+enddiff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/schema_serializer_sync_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/schema_serializer_sync_spec.rbindex b1a9a1d8fa1..844c48237a8 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/schema_serializer_sync_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/schema_serializer_sync_spec.rb@@ -53,13 +53,6 @@ RSpec.describe DiscourseWorkflows::Schema do)end- it "matches BasicUserSerializer" do- expect_ledger(- described_class::BASIC_USER_PROPERTIES,- serialized_keys(BasicUserSerializer, user),- )- end-it "matches DiscourseWorkflows::PostSerializer" doexpect_ledger(described_class::POST_PROPERTIES,diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/schema_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/schema_spec.rbindex f15304f0259..05d9d23bced 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/schema_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/schema_spec.rb@@ -39,28 +39,12 @@ RSpec.describe DiscourseWorkflows::Schema doenddescribe "reusable schema constants" do- it "exposes reusable basic user and group properties" do- property_types =- {- "user" => described_class::BASIC_USER_PROPERTIES,- "group" => described_class::BASIC_GROUP_PROPERTIES,- }.transform_values do |properties|- properties.transform_values { |property| property.fetch("type") }- end-- expect(property_types).to eq(- "user" => {- "id" => "integer",- "username" => "string",- "name" => %w[string null],- "avatar_template" => "string",- },- "group" => {- "id" => "integer",- "name" => "string",- "full_name" => %w[string null],- "automatic" => "boolean",- },+ it "exposes reusable basic group properties" do+ expect(described_class::BASIC_GROUP_PROPERTIES.transform_values { _1.fetch("type") }).to eq(+ "id" => "integer",+ "name" => "string",+ "full_name" => %w[string null],+ "automatic" => "boolean",)end