A platform for community discussion. Free, open, simple.
FEATURE: Fill output gaps in core workflow nodes (#44552)
Régis Hanol53bd7bee9de8
diff --git a/.skills/discourse-workflow-nodes/SKILL.md b/.skills/discourse-workflow-nodes/SKILL.mdindex 35860397af9..85af0353e92 100644--- a/.skills/discourse-workflow-nodes/SKILL.md+++ b/.skills/discourse-workflow-nodes/SKILL.md@@ -11,7 +11,7 @@ Shape entities only with `DiscourseWorkflows::EntitySerializers` (`lib/discourse| Entity | Builder | Schema ||---|---|---|-| User | `serialize_user(user, guardian:)` (nil for nil user) | `Schema::USER_SCHEMA` / `USER_PROPERTIES` |+| User | `serialize_user(user, guardian:)` (nil for nil user) | `Schema::USER_SCHEMA` / `USER_PROPERTIES` / `Schema.nullable_user(description)` || Topic (triggers) | `serialize_topic_list_item(topic, scope:)` | `Schema::TOPIC_LIST_ITEM_SCHEMA` / `TOPIC_PROPERTIES` || 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` |@@ -25,3 +25,9 @@ Shape entities only with `DiscourseWorkflows::EntitySerializers` (`lib/discourse- `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(...)`.- Groups: `BasicGroupSerializer` (`BASIC_GROUP_PROPERTIES`) or `WebHookGroupSerializer` (`GROUP_SCHEMA`).++## Output conventions++- 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`.diff --git a/plugins/chat/spec/lib/discourse_workflows/nodes/reviewable_created_spec.rb b/plugins/chat/spec/lib/discourse_workflows/nodes/reviewable_created_spec.rbnew file mode 100644index 00000000000..0a19923ed56--- /dev/null+++ b/plugins/chat/spec/lib/discourse_workflows/nodes/reviewable_created_spec.rb@@ -0,0 +1,15 @@+# frozen_string_literal: true++RSpec.describe DiscourseWorkflows::Nodes::ReviewableCreated::V1 do+ fab!(:reviewable, :chat_reviewable_message)++ it "exposes the chat channel when the flagged message was deleted", :aggregate_failures do+ channel_id = reviewable.target.chat_channel_id+ reviewable.target.trash!++ output = described_class.new(Reviewable.find(reviewable.id)).output++ expect(output[:reviewable][:chat_channel_id]).to eq(channel_id)+ expect(output).to match_node_output_schema(described_class)+ end+enddiff --git a/plugins/discourse-workflows/app/serializers/discourse_workflows/post_serializer.rb b/plugins/discourse-workflows/app/serializers/discourse_workflows/post_serializer.rbindex 73b6e9e650c..4661528d91a 100644--- a/plugins/discourse-workflows/app/serializers/discourse_workflows/post_serializer.rb+++ b/plugins/discourse-workflows/app/serializers/discourse_workflows/post_serializer.rb@@ -9,7 +9,10 @@ module DiscourseWorkflows:post_number,:post_type,:reply_to_post_number,+ :reply_to_post_id,+ :reply_to_username,:post_url,+ :url,:username,:user_id,:created_at,@@ -20,6 +23,7 @@ module DiscourseWorkflows:score,:category_id,:category_name,+ :category_slug,:tags,:upload_ids,:raw,@@ -45,6 +49,22 @@ module DiscourseWorkflows::Post.url(topic.slug, topic.id, object.post_number)end+ def url+ "#{Discourse.base_url}#{post_url}"+ end++ def reply_to_post_id+ if object.has_attribute?(:reply_to_post_id)+ object[:reply_to_post_id]+ else+ object.reply_to_post&.id+ end+ end++ def reply_to_username+ object.reply_to_user&.username+ end+def usernameobject.user&.usernameend@@ -69,6 +89,10 @@ module DiscourseWorkflowstopic&.category&.nameend+ def category_slug+ topic&.category&.slug_for_url+ end+def tagsreturn [] if topic.blank? || !SiteSetting.tagging_enableddiff --git a/plugins/discourse-workflows/app/serializers/discourse_workflows/topic_list_item_serializer.rb b/plugins/discourse-workflows/app/serializers/discourse_workflows/topic_list_item_serializer.rbindex b486d303bab..018cb9b0ca9 100644--- a/plugins/discourse-workflows/app/serializers/discourse_workflows/topic_list_item_serializer.rb+++ b/plugins/discourse-workflows/app/serializers/discourse_workflows/topic_list_item_serializer.rb@@ -2,6 +2,18 @@module DiscourseWorkflowsclass TopicListItemSerializer < ::TopicListItemSerializer- attributes :user_id, :url+ attributes :user_id, :username, :url++ def username+ object.user&.username+ end++ def include_first_post_id?+ true+ end++ def first_post_id+ object.first_post&.id+ endendenddiff --git a/plugins/discourse-workflows/app/serializers/discourse_workflows/topic_serializer.rb b/plugins/discourse-workflows/app/serializers/discourse_workflows/topic_serializer.rbindex 820726f1766..e41ed42d6d7 100644--- a/plugins/discourse-workflows/app/serializers/discourse_workflows/topic_serializer.rb+++ b/plugins/discourse-workflows/app/serializers/discourse_workflows/topic_serializer.rb@@ -26,6 +26,7 @@ module DiscourseWorkflows:like_count,:category_id,:user_id,+ :username,:last_post_user_id,:last_poster_username,:first_post_id,@@ -69,6 +70,10 @@ module DiscourseWorkflowsobject.last_poster&.usernameend+ def username+ object.user&.username+ end+def first_post_idobject.first_post&.idenddiff --git a/plugins/discourse-workflows/lib/discourse_workflows/entity_serializers.rb b/plugins/discourse-workflows/lib/discourse_workflows/entity_serializers.rbindex f10b27ac5cb..20cbc39881e 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/entity_serializers.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/entity_serializers.rb@@ -82,7 +82,12 @@ module DiscourseWorkflowstarget_id: reviewable.target_id,topic_id: reviewable.topic_id,category_id: reviewable.category_id,+ chat_channel_id: reviewable.try(:chat_message)&.chat_channel_id,score: reviewable.score,+ potential_spam: reviewable.potential_spam,+ url: "#{Discourse.base_url}/review/#{reviewable.id}",+ target_user: serialize_user(reviewable.target_user),+ created_by: serialize_user(reviewable.created_by),created_at: reviewable.created_at&.iso8601,}enddiff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/badge/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/badge/v1.rbindex 74a77cfe4b2..862e54b75c8 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/badge/v1.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/badge/v1.rb@@ -21,6 +21,9 @@ module DiscourseWorkflows"badge_name" => {"type" => "string",},+ "changed" => {+ "type" => "boolean",+ },},}.freeze@@ -110,15 +113,26 @@ module DiscourseWorkflowsactor = exec_ctx.actor_from_parameter("actor_username", item_index)raise Discourse::InvalidAccess if !actor.guardian.can_grant_badges?(user)+ user_badges = UserBadge.where(user: user, badge: badge)+case config["operation"]when "revoke"- user_badge = UserBadge.find_by(user: user, badge: badge)+ user_badge = user_badges.firstBadgeGranter.revoke(user_badge, revoked_by: actor) if user_badge+ changed = user_badge.present?else+ last_user_badge_id = user_badges.maximum(:id)BadgeGranter.grant(badge, user, granted_by: actor)+ changed = user_badges.maximum(:id) != last_user_badge_idend- { user_id: user.id, username: user.username, badge_id: badge.id, badge_name: badge.name }+ {+ user_id: user.id,+ username: user.username,+ badge_id: badge.id,+ badge_name: badge.name,+ changed:,+ }endendenddiff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/error/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/error/v1.rbindex 0599351db03..ac00ab6c3c3 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/error/v1.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/error/v1.rb@@ -4,6 +4,37 @@ module DiscourseWorkflowsmodule Nodesmodule Errorclass V1 < NodeType+ OUTPUT_SCHEMA = Schema.document(JSON.parse(<<~JSON)).freeze+ {+ "trigger": { "description": "Trigger data of the failed run, null when an error workflow failed" },+ "workflow": {+ "type": "object",+ "properties": {+ "id": { "type": "string" },+ "name": { "type": "string" }+ }+ },+ "execution": {+ "type": "object",+ "properties": {+ "id": { "type": ["string", "null"] },+ "url": { "type": ["string", "null"] },+ "retryOf": { "type": "null" },+ "error": {+ "type": "object",+ "properties": {+ "message": { "type": "string" },+ "name": { "type": "string" },+ "stack": { "type": "string", "x-optional": true }+ }+ },+ "lastNodeExecuted": { "type": ["string", "null"] },+ "mode": { "type": "string", "enum": ["error", "manual", "webhook", "trigger"] }+ }+ }+ }+ JSON+description(name: "trigger:error",version: "1.0",@@ -13,6 +44,7 @@ module DiscourseWorkflows},inputs: [],max_nodes: 1,+ output_contracts: [{ schema: OUTPUT_SCHEMA }],)def initialize(error_data = {}, *)diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/flag_post/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/flag_post/v1.rbindex d7f75081f4f..fa94aaaf721 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/flag_post/v1.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/flag_post/v1.rb@@ -38,7 +38,7 @@ module DiscourseWorkflows"type" => "string",},"reviewable_id" => {- "type" => "integer",+ "type" => %w[integer null],},"post_hidden" => {"type" => "boolean",diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/group/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/group/v1.rbindex 2a117c9c0fa..628f19c2f18 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/group/v1.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/group/v1.rb@@ -5,6 +5,12 @@ module DiscourseWorkflowsmodule Groupclass V1 < NodeTypeOPERATIONS = %w[add remove get check_membership].freeze+ GROUP_ACTION_SCHEMA =+ Schema.merge(+ Schema::GROUP_SCHEMA,+ Schema::USER_SCHEMA,+ Schema.document("changed" => { "type" => "boolean" }),+ )description(name: "action:group",@@ -21,7 +27,7 @@ module DiscourseWorkflows{variants: [{- schema: Schema.merge(Schema::GROUP_SCHEMA, Schema::BASIC_USER_SCHEMA),+ schema: GROUP_ACTION_SCHEMA,display_options: {show: {operation: %w[add remove],@@ -135,9 +141,8 @@ module DiscourseWorkflowsactor = exec_ctx.actor_from_parameter("actor_username", item_index)guardian = actor.guardianguardian.ensure_can_see_group!(group)- serialized_group = serialize_group(group, guardian)- return { group: serialized_group } if config["operation"] == "get"+ return { group: serialize_group(group, guardian) } if config["operation"] == "get"guardian.ensure_can_edit_group!(group)@@ -147,19 +152,27 @@ module DiscourseWorkflowscase config["operation"]when "remove"- group.remove(user)+ changed = group.remove(user)logger.log_remove_user_from_group(user)else- group.add(user)+ changed = GroupManager.new(group).add([user.id]).present?logger.log_add_user_to_group(user)- set_primary_group(user, group, guardian) if config["set_primary_group"]+ changed = set_primary_group(user, group, guardian) || changed if config[+ "set_primary_group"+ ]end- { group: serialized_group, user: user_data(user, guardian) }+ {+ group: serialize_group(group.reload, guardian),+ user: serialize_user(user.reload, guardian:),+ changed:,+ }enddef set_primary_group(user, group, guardian)guardian.ensure_can_change_primary_group!(user, group)+ return false if user.primary_group_id == group.id+user.update!(primary_group_id: group.id)end@@ -187,10 +200,6 @@ module DiscourseWorkflowsdef serialize_group(group, guardian)serialize_record(group, WebHookGroupSerializer, scope: guardian)end-- def user_data(user, guardian)- serialize_record(user, BasicUserSerializer, scope: guardian)- endendendenddiff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/http_request/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/http_request/v1.rbindex 93191eca1d9..5b35e6fa371 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/http_request/v1.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/http_request/v1.rb@@ -6,6 +6,21 @@ module DiscourseWorkflowsclass V1 < NodeTypeinclude HttpHelpers+ FULL_RESPONSE_SCHEMA =+ Schema.document(+ "status_code" => {+ "type" => "integer",+ },+ "status_message" => {+ "type" => %w[string null],+ },+ "headers" => {+ "type" => "object",+ },+ "body" => {+ },+ )+description(name: "action:http_request",version: "1.0",@@ -16,6 +31,20 @@ module DiscourseWorkflowscapabilities: {run_scope: "per_item",},+ output_contracts: [+ {+ variants: [+ {+ schema: FULL_RESPONSE_SCHEMA,+ display_options: {+ show: {+ full_response: [true],+ },+ },+ },+ ],+ },+ ],properties: {method: {type: :options,diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/post/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/post/v1.rbindex 1c9794a431b..ce79f024001 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/post/v1.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/post/v1.rb@@ -34,6 +34,12 @@ module DiscourseWorkflows"offset" => 0,}.freezeMAX_LIMIT = 800+ REPLY_TO_POST_JOIN = <<~SQL+ LEFT JOIN posts reply_posts+ ON reply_posts.topic_id = posts.topic_id+ AND reply_posts.post_number = posts.reply_to_post_number+ AND reply_posts.deleted_at IS NULL+ SQLdef self.list_string_property(control: nil, hidden: false)property = {@@ -425,11 +431,11 @@ module DiscourseWorkflowsenddef list_posts(exec_ctx, config, item_index)- actor = exec_ctx.actor_from_parameter("actor_username", item_index)+ guardian = exec_ctx.actor_from_parameter("actor_username", item_index).guardianlimit = bounded_integer(config["limit"], default: DEFAULT_LIMIT, min: 1, max: MAX_LIMIT)offset = bounded_integer(config["offset"], default: 0, min: 0)query = query_from_config(config)- filter = PostsFilter.new(query, guardian: actor.guardian, limit: limit, offset: offset)+ filter = PostsFilter.new(query, guardian:, limit: limit, offset: offset)if filter.invalid_filters.present?raise_node_error!(@@ -440,10 +446,13 @@ module DiscourseWorkflows)end- posts = filter.search.includes(:user, topic: %i[category tags])- posts.map do |post|- { post: serialized_post(post, guardian: actor.guardian, config: config) }- end+ posts =+ filter+ .search+ .joins(REPLY_TO_POST_JOIN)+ .select("posts.*, reply_posts.id AS reply_to_post_id")+ .preload(:user, :reply_to_user, :uploads, topic: %i[category tags])+ posts.map { |post| { post: serialized_post(post, guardian:, config:) } }enddef serialized_post(post, guardian:, config:)diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_edited/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_edited/v1.rbindex 7e7f3c1e39c..38ba4f5508f 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_edited/v1.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_edited/v1.rb@@ -28,6 +28,30 @@ module DiscourseWorkflows"description" => "User who performed the edit, when available","properties" => Schema::USER_PROPERTIES,},+ "revision" => {+ "type" => %w[object null],+ "description" =>+ "Revision created by the edit, null for edits within the grace period",+ "properties" => {+ "number" => {+ "type" => "integer",+ },+ "edit_reason" => {+ "type" => %w[string null],+ },+ "changes" => {+ "type" => "array",+ "description" => "Names of the modified fields",+ "items" => {+ "type" => "string",+ },+ },+ "previous_raw" => {+ "type" => %w[string null],+ "description" => "Raw before the edit, null when the raw did not change",+ },+ },+ },),),},@@ -48,10 +72,9 @@ module DiscourseWorkflows},)- def initialize(post, topic_changed_or_cooked = nil, revisor = nil, *)+ def initialize(post, _topic_changed = nil, revisor = nil, *)super(parameters: {})@post = post- @cooked = topic_changed_or_cooked.is_a?(String) ? topic_changed_or_cooked : post&.cooked@revisor = revisorend@@ -62,10 +85,11 @@ module DiscourseWorkflowsdef output{- post: serialize_post(@post, include_cooked: true).merge(cooked: @cooked),+ post: serialize_post(@post, include_cooked: true),topic: serialize_topic_list_item(@post.topic),user: serialize_user(@post.user),editor: serialize_user(@revisor&.editor),+ revision: serialize_revision,}end@@ -78,6 +102,18 @@ module DiscourseWorkflowsprivate+ def serialize_revision+ revision = @revisor&.post_revision+ return if revision.blank?++ {+ number: revision.number,+ edit_reason: @post.edit_reason,+ changes: revision.modifications.keys,+ previous_raw: revision.modifications.dig("raw", 0),+ }+ end+def matches_post_scope?(post_scope)case post_scopewhen "all_posts"diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/schedule/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/schedule/v1.rbindex 7c642c76df4..e9cfe54b0a2 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/schedule/v1.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/schedule/v1.rb@@ -17,14 +17,17 @@ module DiscourseWorkflows**%w[readable_datereadable_time+ dateday_of_weekyearmonth+ month_numberday_of_monthhourminutesecondtimezone+ time].index_with { { "type" => "string" } },},}.freezediff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/stale_topic/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/stale_topic/v1.rbindex ca40e488657..8c1615bec7e 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/stale_topic/v1.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/stale_topic/v1.rb@@ -59,7 +59,7 @@ module DiscourseWorkflows.where("GREATEST(topics.created_at, topics.last_posted_at) < ?", threshold).where(closed: false, archived: false, visible: true).where("topics.archetype = ?", Archetype.default)- .includes(first_post: :user)+ .includes(:user, first_post: :user)if category_ids.present?scoped_category_ids =diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic/v1.rbindex 07989ed04aa..0d5af4f322e 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic/v1.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic/v1.rb@@ -9,6 +9,18 @@ module DiscourseWorkflowsDEFAULT_LIMIT = 30CUSTOM_FIELD_OPTIONS_LIMIT = 100+ TOPIC_SCHEMA =+ Schema.merge(+ Schema::TOPIC_LIST_ITEM_SCHEMA,+ Schema.entity_extension(+ "topic",+ "custom_fields" => {+ "type" => "object",+ "x-optional" => true,+ },+ ),+ )+TOPIC_POST_SCHEMA =Schema.entity("post",@@ -18,7 +30,10 @@ module DiscourseWorkflows"like_count","tags","upload_ids",- ).merge("category_slug" => { "type" => "string" }),+ "reply_to_post_id",+ "reply_to_username",+ "url",+ ),"WebHookPostSerializer payload",)@@ -34,7 +49,19 @@ module DiscourseWorkflowsrun_scope: "per_item",},output_contracts: [- { schema: Schema.merge(Schema::TOPIC_LIST_ITEM_SCHEMA, TOPIC_POST_SCHEMA) },+ {+ variants: [+ {+ schema: TOPIC_SCHEMA,+ display_options: {+ show: {+ operation: ["set_custom_fields"],+ },+ },+ },+ ],+ schema: Schema.merge(TOPIC_SCHEMA, TOPIC_POST_SCHEMA),+ },],properties: {operation: {diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_category/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_category/v1.rbindex 37373172d20..827aa344b1f 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_category/v1.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_category/v1.rb@@ -17,21 +17,21 @@ module DiscourseWorkflows},output_contracts: [{- schema: {- "$schema" => Schema::DRAFT_URI,- "type" => "object",- "properties" => {- "topic_id" => {- "type" => "integer",- },- "category_id" => {- "type" => "integer",- },- "old_category_id" => {- "type" => "integer",- },- },- },+ schema:+ Schema.merge(+ Schema.document(+ "topic_id" => {+ "type" => "integer",+ },+ "category_id" => {+ "type" => "integer",+ },+ "old_category_id" => {+ "type" => "integer",+ },+ ),+ Schema::TOPIC_LIST_ITEM_SCHEMA,+ ),},],properties: {@@ -96,7 +96,12 @@ module DiscourseWorkflows)end- { topic_id: topic.id, category_id: topic.category_id, old_category_id: old_category_id }+ {+ topic_id: topic.id,+ category_id: topic.category_id,+ old_category_id: old_category_id,+ topic: serialize_topic(topic.reload, guardian:),+ }enddef target_category_id(raw_value)diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_created/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_created/v1.rbindex 0149453ccb8..b5af092659f 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_created/v1.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_created/v1.rb@@ -14,7 +14,14 @@ module DiscourseWorkflowsgroup: "discourse_triggers",event: :topic_created,output_contracts: [- { schema: Schema.merge(Schema::TOPIC_LIST_ITEM_SCHEMA, Schema::POST_SCHEMA) },+ {+ schema:+ Schema.merge(+ Schema::TOPIC_LIST_ITEM_SCHEMA,+ Schema::POST_SCHEMA,+ Schema::USER_SCHEMA,+ ),+ },],properties: {**TOPIC_TYPE_FILTER_PROPERTIES,@@ -66,7 +73,11 @@ module DiscourseWorkflowsenddef output- { post: serialize_post(@topic.first_post), topic: serialize_topic_list_item(@topic) }+ {+ post: serialize_post(@topic.first_post),+ topic: serialize_topic_list_item(@topic),+ user: serialize_user(@topic.user),+ }enddef matches?(trigger_ctx)diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_pin/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_pin/v1.rbindex b172cc677a2..d996bbaaf3f 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_pin/v1.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_pin/v1.rb@@ -49,7 +49,9 @@ module DiscourseWorkflowscapabilities: {run_scope: "per_item",},- output_contracts: [{ schema: OUTPUT_SCHEMA }],+ output_contracts: [+ { schema: Schema.merge(OUTPUT_SCHEMA, Schema::TOPIC_LIST_ITEM_SCHEMA) },+ ],properties: {operation: {type: :options,@@ -191,6 +193,7 @@ module DiscourseWorkflowspinned_until: topic.pinned_until&.utc&.iso8601,banner: topic.archetype == ::Archetype.banner,bannered_until: topic.bannered_until&.utc&.iso8601,+ topic: serialize_topic(topic.reload, guardian: actor.guardian),}enddiff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/user/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/user/v1.rbindex 71c5701b7fe..04d504549a6 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/user/v1.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/user/v1.rb@@ -270,6 +270,7 @@ module DiscourseWorkflowstitle: user.title,bio_raw: profile&.bio_raw,website: profile&.website,+ location: profile&.location,profile_background_upload_id: profile&.profile_background_upload_id,card_background_upload_id: profile&.card_background_upload_id,manual_locked_trust_level: user.manual_locked_trust_level,diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/user_moderation_changed/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/user_moderation_changed/v1.rbindex bd51b2e2a01..2b99cdeecf0 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/user_moderation_changed/v1.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/user_moderation_changed/v1.rb@@ -14,18 +14,21 @@ module DiscourseWorkflowsOUTPUT_SCHEMA =Schema.merge(Schema::USER_SCHEMA,+ Schema::ACTOR_SCHEMA,Schema.document("change" => {"type" => "string","enum" => CHANGES.values,},- "actor" => {- "type" => %w[object null],- "properties" => Schema::BASIC_USER_PROPERTIES,- },"reason" => {"type" => %w[string null],},+ "message" => {+ "type" => %w[string null],+ },+ "post_id" => {+ "type" => %w[integer null],+ },"expires_at" => {"type" => %w[string null],"format" => "date-time",@@ -66,6 +69,8 @@ module DiscourseWorkflows@user = payload[:user]@actor = payload[:by_user] || payload[:silenced_by]@reason = payload[:reason]+ @message = payload[:message]+ @post_id = payload[:post_id].presence&.to_ienddef valid?@@ -88,8 +93,10 @@ module DiscourseWorkflows{user: serialize_user(@user),change: @change,- actor: @actor && serialize_record(@actor, BasicUserSerializer),+ actor: serialize_user(@actor),reason: @reason,+ message: @message,+ post_id: @post_id,expires_at: expiry&.iso8601,}enddiff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/user_seen/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/user_seen/v1.rbindex ca5725322ba..fa4147cd5b1 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/user_seen/v1.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/user_seen/v1.rb@@ -103,7 +103,7 @@ module DiscourseWorkflowsdef output{- user: user_data(@user),+ user: serialize_user(@user),seen: {first_seen: first_seen?,current_seen_at: current_seen_at&.iso8601,@@ -160,10 +160,6 @@ module DiscourseWorkflowsamount.positive? && NOT_SEEN_UNITS.include?(unit) &&previous_seen_at <= amount.public_send(unit).agoend-- def user_data(user)- serialize_record(user, BasicUserSerializer)- endendendenddiff --git a/plugins/discourse-workflows/lib/discourse_workflows/schema.rb b/plugins/discourse-workflows/lib/discourse_workflows/schema.rbindex 12f738a47e6..7c53580d645 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/schema.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/schema.rb@@ -26,6 +26,10 @@ module DiscourseWorkflows{ "$schema" => DRAFT_URI, "type" => "object", "properties" => properties }.freezeend+ def self.nullable_user(description)+ { "type" => %w[object null], "description" => description, "properties" => USER_PROPERTIES }+ end+def self.entity_extension(name, properties){"$schema" => DRAFT_URI,@@ -50,6 +54,7 @@ module DiscourseWorkflows"posts_count": { "type": "integer" },"category_id": { "type": ["integer", "null"] },"user_id": { "type": "integer" },+ "username": { "type": ["string", "null"], "description": "Username of the topic author" },"tags": {"type": "array","items": {@@ -61,7 +66,7 @@ module DiscourseWorkflows}}},- "first_post_id": { "type": "integer" },+ "first_post_id": { "type": ["integer", "null"] },"visible": { "type": "boolean" },"visibility_reason_id": { "type": "integer" },"closed": { "type": "boolean" },@@ -84,12 +89,16 @@ module DiscourseWorkflows"post_number": { "type": "integer" },"post_type": { "type": "integer" },"reply_to_post_number": { "type": ["integer", "null"] },+ "reply_to_post_id": { "type": ["integer", "null"] },+ "reply_to_username": { "type": ["string", "null"] },"topic_id": { "type": "integer" },"topic_slug": { "type": "string" },"topic_title": { "type": "string" },"post_url": { "type": "string", "description": "Relative URL of the post" },+ "url": { "type": "string", "description": "Absolute URL of the post" },"category_id": { "type": ["integer", "null"] },"category_name": { "type": ["string", "null"] },+ "category_slug": { "type": ["string", "null"] },"user_id": { "type": "integer" },"username": { "type": "string" },"created_at": { "type": "string", "format": "date-time" },@@ -169,6 +178,7 @@ module DiscourseWorkflowsPOST_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"))IP_LOCATION_PROPERTIES = JSON.parse(<<~JSON).freeze{"type": ["object", "null"],@@ -194,6 +204,7 @@ module DiscourseWorkflows"title": { "type": ["string", "null"] },"bio_raw": { "type": ["string", "null"] },"website": { "type": ["string", "null"] },+ "location": { "type": ["string", "null"] },"profile_background_upload_id": { "type": ["integer", "null"] },"card_background_upload_id": { "type": ["integer", "null"] },"manual_locked_trust_level": { "type": ["integer", "null"] },@@ -345,7 +356,7 @@ module DiscourseWorkflowsUSER_SEEN_SCHEMA =document(- BASIC_USER_SCHEMA.fetch("properties").merge(+ USER_SCHEMA.fetch("properties").merge("seen" => {"type" => "object","description" => "User seen event details",@@ -369,7 +380,10 @@ module DiscourseWorkflows),)- REVIEWABLE_PROPERTIES = JSON.parse(<<~JSON).freeze+ REVIEWABLE_PROPERTIES = {+ "target_user" => nullable_user("User the reviewable is about"),+ "created_by" => nullable_user("User who flagged or queued the item"),+ }.merge(JSON.parse(<<~JSON)).freeze{"id": { "type": "integer" },"type": { "type": "string" },@@ -378,7 +392,10 @@ module DiscourseWorkflows"target_id": { "type": ["integer", "null"] },"topic_id": { "type": ["integer", "null"] },"category_id": { "type": ["integer", "null"] },- "score": { "type": "number" },+ "chat_channel_id": { "type": ["integer", "null"] },+ "score": { "type": "number", "description": "Total review score. Flag scores are added after the item is queued, so this is usually 0 when the item is created" },+ "potential_spam": { "type": "boolean" },+ "url": { "type": "string", "description": "Absolute URL of the item in the review queue" },"created_at": { "type": ["string", "null"], "format": "date-time" }}JSONdiff --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 34d9be20288..82cf9490cf3 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@@ -89,9 +89,9 @@ RSpec.describe DiscourseWorkflows::Ai::Tools::WorkflowNodeCatalog do"post.post_url" => "string","post.upload_ids" => "array<integer>",)- expect(output_fields_by_type.fetch("trigger:topic_created")).not_to include(- "post.trust_level",- "user.trust_level",+ expect(output_fields_by_type.fetch("trigger:topic_created")).not_to include("post.trust_level")+ expect(output_fields_by_type.fetch("trigger:topic_created")).to include(+ "user.trust_level" => "integer",)expect(output_fields_by_type.fetch("trigger:post_created")).to include("post.user_id" => "integer",diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/node_output_contracts_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/node_output_contracts_spec.rbindex 02325d79cf0..2b1705a35c3 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/node_output_contracts_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/node_output_contracts_spec.rb@@ -93,11 +93,7 @@ RSpec.describe DiscourseWorkflows::NodeType doit "unions the group variants in contention when the operation is an expression" donode_class = DiscourseWorkflows::Nodes::Group::V1- add_remove_schema =- DiscourseWorkflows::Schema.merge(- DiscourseWorkflows::Schema::GROUP_SCHEMA,- DiscourseWorkflows::Schema::BASIC_USER_SCHEMA,- )+ add_remove_schema = node_class::GROUP_ACTION_SCHEMAexpect(node_class.output_schemas({ "operation" => "add" }, input_schemas: [input_schema]),diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/node_type_serializer_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/node_type_serializer_spec.rbindex e3ba8269936..423d2d71bf5 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/node_type_serializer_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/node_type_serializer_spec.rb@@ -12,11 +12,7 @@ RSpec.describe DiscourseWorkflows::NodeTypeSerializer doexpect(version.dig(:output_contracts, 0, :variants)).to eq([{- schema:- DiscourseWorkflows::Schema.merge(- DiscourseWorkflows::Schema::GROUP_SCHEMA,- DiscourseWorkflows::Schema::BASIC_USER_SCHEMA,- ),+ schema: DiscourseWorkflows::Nodes::Group::V1::GROUP_ACTION_SCHEMA,mode: :replace,display_options: {show: {diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/badge_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/badge_spec.rbindex 1d3a9cbb3f7..ec64926ea99 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/badge_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/badge_spec.rb@@ -60,6 +60,7 @@ RSpec.describe DiscourseWorkflows::Nodes::Badge::V1 doexpect(result["username"]).to eq(user.username)expect(result["badge_id"]).to eq(badge.id)expect(result["badge_name"]).to eq(badge.name)+ expect(result["changed"]).to be(true)expect(UserBadge.exists?(user: user, badge: badge)).to be(true)expect(result).to match_node_output_schema(described_class)end@@ -73,9 +74,25 @@ RSpec.describe DiscourseWorkflows::Nodes::Badge::V1 do"badge_id" => badge.id.to_s,}- expect { execute_node(configuration: config, item: item) }.not_to change {+ result = nil+ expect { result = execute_node(configuration: config, item: item) }.not_to change {UserBadge.where(user: user, badge: badge).count}+ expect(result["changed"]).to be(false)+ end++ it "reports no change when the badge is disabled" do+ badge.update!(enabled: false)++ config = {+ "operation" => "grant",+ "username" => user.username,+ "badge_id" => badge.id.to_s,+ }++ result = execute_node(configuration: config, item: item)++ expect(result["changed"]).to be(false)endit "raises when granting as the anonymous actor" do@@ -102,9 +119,10 @@ RSpec.describe DiscourseWorkflows::Nodes::Badge::V1 do"badge_id" => badge.id.to_s,}- execute_node(configuration: config, item: item)+ result = execute_node(configuration: config, item: item)expect(UserBadge.exists?(user: user, badge: badge)).to be(false)+ expect(result["changed"]).to be(true)endit "is idempotent when user does not have the badge" do@@ -124,6 +142,7 @@ RSpec.describe DiscourseWorkflows::Nodes::Badge::V1 do"username" => user.username,"badge_id" => badge.id,"badge_name" => badge.name,+ "changed" => false,)endenddiff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/flag_post_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/flag_post_spec.rbindex 1c8aff5d52f..c195fcacd68 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/flag_post_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/flag_post_spec.rb@@ -225,6 +225,22 @@ RSpec.describe DiscourseWorkflows::Nodes::FlagPost::V1 do)end+ it "returns a null reviewable_id when no review item is created", :aggregate_failures do+ bot_post = Fabricate(:post, user: Discourse.system_user)++ result =+ execute_node(+ configuration: {+ "post_id" => bot_post.id.to_s,+ "flag_type" => "spam",+ "actor_username" => moderator.username,+ },+ )++ expect(result["reviewable_id"]).to be_nil+ expect(result).to match_node_output_schema(described_class)+ end+it "flags the post as spam and silences the author with spam_silence", :aggregate_failures doresult =execute_node(configuration: { "post_id" => post.id.to_s, "flag_type" => "spam_silence" })diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/group_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/group_spec.rbindex 448e0c14b4a..02d91274bb0 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/group_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/group_spec.rb@@ -55,11 +55,7 @@ RSpec.describe DiscourseWorkflows::Nodes::Group::V1 doendit "advertises a concrete schema for each operation", :aggregate_failures do- group_with_user =- DiscourseWorkflows::Schema.merge(- DiscourseWorkflows::Schema::GROUP_SCHEMA,- DiscourseWorkflows::Schema::BASIC_USER_SCHEMA,- )+ group_with_user = described_class::GROUP_ACTION_SCHEMAexpect(described_class.output_schemas({ "operation" => "add" }, input_schemas: [input_schema]),@@ -97,18 +93,33 @@ RSpec.describe DiscourseWorkflows::Nodes::Group::V1 doexpect(result["group"]["name"]).to eq(group.name)expect(result["user"]["id"]).to eq(user.id)expect(result["user"]["username"]).to eq(user.username)+ expect(result["user"]["trust_level"]).to eq(user.trust_level)+ expect(result["group"]["user_count"]).to eq(group.reload.user_count)+ expect(result["changed"]).to be(true)expect(GroupUser.exists?(user: user, group: group)).to be(true)expect(result).to match_node_output_schema(described_class, configuration: config)end+ it "returns the trust level granted by the group" do+ user.update!(trust_level: TrustLevel[0])+ group.update!(grant_trust_level: TrustLevel[2])+ config = { "operation" => "add", "username" => user.username, "group_id" => group.id.to_s }++ result = execute_node(configuration: config, item: item)++ expect(result["user"]["trust_level"]).to eq(TrustLevel[2])+ end+it "is idempotent when user is already a member" dogroup.add(user)config = { "operation" => "add", "username" => user.username, "group_id" => group.id.to_s }- expect { execute_node(configuration: config, item: item) }.not_to change {+ result = nil+ expect { result = execute_node(configuration: config, item: item) }.not_to change {GroupUser.where(user: user, group: group).count}+ expect(result["changed"]).to be(false)endit "logs the action in group history" do@@ -198,9 +209,10 @@ RSpec.describe DiscourseWorkflows::Nodes::Group::V1 doit "sets the primary group when the user is already a member" dogroup.add(user)- execute_node(configuration: config, item: item)+ result = execute_node(configuration: config, item: item)expect(user.reload.primary_group_id).to eq(group.id)+ expect(result["changed"]).to be(true)endit "resolves the value from an expression" do@@ -229,6 +241,8 @@ RSpec.describe DiscourseWorkflows::Nodes::Group::V1 doexpect(result["group"]["name"]).to eq(group.name)expect(result["user"]["id"]).to eq(user.id)expect(result["user"]["username"]).to eq(user.username)+ expect(result["group"]["user_count"]).to eq(group.reload.user_count)+ expect(result["changed"]).to be(true)expect(GroupUser.exists?(user: user, group: group)).to be(false)expect(result).to match_node_output_schema(described_class, configuration: config)enddiff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_created_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_created_spec.rbindex cf6b0808b01..419405685f9 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_created_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_created_spec.rb@@ -66,6 +66,8 @@ RSpec.describe DiscourseWorkflows::Nodes::PostCreated::V1 doexpect(output[:post][:post_number]).to eq(reply.post_number)expect(output[:post][:raw]).to eq(reply.raw)expect(output[:post][:reply_to_post_number]).to eq(topic.first_post.post_number)+ expect(output[:post][:reply_to_post_id]).to eq(topic.first_post.id)+ expect(output[:post][:reply_to_username]).to eq(topic_owner.username)expect(output[:post][:user_id]).to eq(reply_user.id)expect(output[:post][:username]).to eq(reply_user.username)expect(output[:post][:upload_ids]).to contain_exactly(upload.id)@@ -92,6 +94,7 @@ RSpec.describe DiscourseWorkflows::Nodes::PostCreated::V1 dooutput = described_class.new(personal_message_post).outputexpect(output.dig(:post, :category_id)).to be_nil+ expect(output[:post]).to include(reply_to_post_id: nil, reply_to_username: nil)expect(output.dig(:topic, :category_id)).to be_nilexpect(output).to match_node_output_schema(described_class)enddiff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_edited/v1_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_edited/v1_spec.rbindex 187a5eef2a8..07237020227 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_edited/v1_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_edited/v1_spec.rb@@ -43,11 +43,12 @@ RSpec.describe DiscourseWorkflows::Nodes::PostEdited::V1 doenddescribe "#output" do- it "exposes the editor separately from the author" do+ it "exposes the editor separately from the author with the revision details",+ :aggregate_failures doeditor = Fabricate(:admin)events =DiscourseEvent.track_events(:post_edited) do- first_post.revise(editor, raw: "Edited by another user")+ first_post.revise(editor, raw: "Edited by another user", edit_reason: "Typo")endoutput = described_class.new(*events.sole[:params]).output@@ -58,6 +59,12 @@ RSpec.describe DiscourseWorkflows::Nodes::PostEdited::V1 dotrust_level: editor.trust_level,)expect(output[:user][:id]).to eq(user.id)+ expect(output[:revision]).to include(+ number: 2,+ edit_reason: "Typo",+ previous_raw: "First post",+ )+ expect(output[:revision][:changes]).to include("raw")expect(output).to match_node_output_schema(described_class)editor_schema = described_class.output_schemas.first.dig("properties", "editor")expect(editor_schema).to include("properties" => DiscourseWorkflows::Schema::USER_PROPERTIES)@@ -69,7 +76,7 @@ RSpec.describe DiscourseWorkflows::Nodes::PostEdited::V1 doexpect(output[:post][:id]).to eq(first_post.id)expect(output[:post][:raw]).to eq(first_post.raw)- expect(output[:post][:cooked]).to eq("<p>Cooked</p>")+ expect(output[:post][:cooked]).to eq(first_post.cooked)expect(output[:user]).to include(id: user.id,username: user.username,@@ -80,7 +87,7 @@ RSpec.describe DiscourseWorkflows::Nodes::PostEdited::V1 doexpect(output[:topic][:user_id]).to eq(topic.user_id)expect(output[:topic][:tags].map { |topic_tag| topic_tag[:name] }).to eq(["test-tag"])expect(output).not_to have_key(:cooked)- expect(output).to include(editor: nil)+ expect(output).to include(editor: nil, revision: nil)expect(output).to match_node_output_schema(described_class)endenddiff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_lifecycle_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_lifecycle_spec.rbindex 8d5c217126c..1efeb8adad1 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_lifecycle_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_lifecycle_spec.rb@@ -46,8 +46,13 @@ RSpec.describe DiscourseWorkflows::Nodes::PostLifecycle dousername: post.user.username,category_id: category.id,tags: ["availability"],+ url: "#{Discourse.base_url}#{post.url}",+ )+ expect(output[:topic]).to include(+ id: topic.id,+ title: topic.title,+ username: topic.user.username,)- expect(output[:topic]).to include(id: topic.id, title: topic.title)expect(output[:user]).to include(id: actor.id, username: actor.username)expect(output).to match_node_output_schema(klass)enddiff --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 52500d1bf9e..f0aaea3c997 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@@ -650,6 +650,28 @@ RSpec.describe DiscourseWorkflows::Nodes::Post::V1 do)end+ it "lists posts with their reply_to_post_id" do+ topic = Fabricate(:topic, category: category, user: user)+ first_post = Fabricate(:post, topic: topic, user: user, post_number: 1)+ reply = Fabricate(:post, topic: topic, user: user, post_number: 2, reply_to_post_number: 1)++ result =+ execute_node_output(+ configuration: {+ "operation" => "list",+ "topics" => topic.id.to_s,+ "limit" => "10",+ },+ item: item,+ ).first++ expect(+ result.to_h do |output_item|+ output_item.dig("json", "post").values_at("id", "reply_to_post_id")+ end,+ ).to eq(first_post.id => nil, reply.id => first_post.id)+ end+it "lists posts matching the query field" dotopic = Fabricate(:topic, category: category, user: user, title: "Query field topic")matching_post = Fabricate(:post, topic: topic, user: user, post_number: 1, raw: "query body")diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/reviewable_approved_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/reviewable_approved_spec.rbindex cad947d2e62..0e29f3bbe4b 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/reviewable_approved_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/reviewable_approved_spec.rb@@ -43,22 +43,9 @@ RSpec.describe DiscourseWorkflows::Nodes::ReviewableApproved::V1 dodescribe "#output" doit "returns reviewable data", :aggregate_failures doreviewable.update!(status: :approved)- trigger = described_class.new(:approved, reviewable)- output = trigger.output+ output = described_class.new(:approved, reviewable).output- expect(output).to eq(- reviewable: {- id: reviewable.id,- type: "ReviewableFlaggedPost",- status: "approved",- target_type: "Post",- target_id: reviewable.target_id,- topic_id: reviewable.topic_id,- category_id: reviewable.category_id,- score: reviewable.score,- created_at: reviewable.created_at.iso8601,- },- )+ expect(output[:reviewable]).to include(status: "approved")expect(output).to match_node_output_schema(described_class)endenddiff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/reviewable_created_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/reviewable_created_spec.rbindex c09403ddef7..a4b88c4ad30 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/reviewable_created_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/reviewable_created_spec.rb@@ -39,18 +39,11 @@ RSpec.describe DiscourseWorkflows::Nodes::ReviewableCreated::V1 doit "returns reviewable data", :aggregate_failures dooutput = described_class.new(reviewable).output- expect(output).to eq(- reviewable: {- id: reviewable.id,- type: "ReviewableFlaggedPost",- status: "pending",- target_type: "Post",- target_id: reviewable.target_id,- topic_id: reviewable.topic_id,- category_id: reviewable.category_id,- score: reviewable.score,- created_at: reviewable.created_at.iso8601,- },+ expect(output[:reviewable]).to include(+ id: reviewable.id,+ status: "pending",+ url: "#{Discourse.base_url}/review/#{reviewable.id}",+ chat_channel_id: nil,)expect(output).to match_node_output_schema(described_class)enddiff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/reviewable_status_changed_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/reviewable_status_changed_spec.rbindex bb759581420..6dd73f18785 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/reviewable_status_changed_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/reviewable_status_changed_spec.rb@@ -42,6 +42,16 @@ RSpec.describe DiscourseWorkflows::Nodes::ReviewableStatusChanged::V1 doendend+ describe "#output" do+ it "uses the target account for user reviewables" do+ reviewable_user = Fabricate(:reviewable_user)++ output = described_class.new(:rejected, reviewable_user).output++ expect(output[:reviewable][:target_user]).to include(id: reviewable_user.target.id)+ end+ end+describe "#matches?" doit "filters by outcome and reviewable type" dotrigger = described_class.new(:rejected, reviewable)diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/schedule/payload_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/schedule/payload_spec.rbindex ba26e17d9aa..188d1f1c7f4 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/schedule/payload_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/schedule/payload_spec.rb@@ -22,6 +22,9 @@ RSpec.describe DiscourseWorkflows::Nodes::Schedule::Payload do"time" => "14:00:00",)expect(payload).to match_node_output_schema(DiscourseWorkflows::Nodes::Schedule::V1)+ expect(+ DiscourseWorkflows::Nodes::Schedule::V1::OUTPUT_SCHEMA["properties"].keys,+ ).to match_array(payload.keys)endit "formats fields in the resolved workflow timezone" dodiff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/send_personal_message_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/send_personal_message_spec.rbindex 341c8e193d7..7460495945d 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/send_personal_message_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/send_personal_message_spec.rb@@ -43,6 +43,8 @@ RSpec.describe DiscourseWorkflows::Nodes::SendPersonalMessage::V1 do"user_id" => sender.id,"username" => sender.username,)+ expect(result.dig("topic", "first_post_id")).to eq(post.id)+ expect(result).to match_node_output_schema(described_class)endit "resolves dynamic recipients and message body", :aggregate_failures dodiff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_category_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_category_spec.rbindex 1b56350f6f5..2107191fefa 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_category_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_category_spec.rb@@ -16,6 +16,8 @@ RSpec.describe DiscourseWorkflows::Nodes::TopicCategory::V1 doexpect(result["topic_id"]).to eq(topic.id)expect(result["category_id"]).to eq(other_category.id)expect(result["old_category_id"]).to eq(category.id)+ expect(result.dig("topic", "category_id")).to eq(other_category.id)+ expect(result).to match_node_output_schema(described_class)expect(topic.reload.category_id).to eq(other_category.id)enddiff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_created_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_created_spec.rbindex 978cbf41712..043e9d13d1d 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_created_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_created_spec.rb@@ -52,6 +52,8 @@ RSpec.describe DiscourseWorkflows::Nodes::TopicCreated::V1 doexpect(output[:topic][:tags].map { |topic_tag| topic_tag[:name] }).to eq(["test-tag"])expect(output[:topic][:category_id]).to eq(topic.category_id)expect(output[:topic][:posters].map { |poster| poster[:user_id] }).to include(topic.user_id)+ expect(output[:user]).to include(id: user.id, trust_level: user.trust_level)+ expect(output).to match_node_output_schema(described_class)endit "includes assignment data when assign is available" dodiff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_pin_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_pin_spec.rbindex 022e3329ee5..f2fb2a927e8 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_pin_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_pin_spec.rb@@ -17,6 +17,7 @@ RSpec.describe DiscourseWorkflows::Nodes::TopicPin::V1 doexpect(result["pinned"]).to eq(true)expect(result["pinned_globally"]).to eq(false)+ expect(result.dig("topic", "id")).to eq(topic.id)expect(result).to match_node_output_schema(described_class, configuration: config)topic.reloaddiff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_spec.rbindex 73cd51a27c8..af9cb82a937 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_spec.rb@@ -104,6 +104,7 @@ RSpec.describe DiscourseWorkflows::Nodes::Topic::V1 doexpect(result).to include("post_id" => topic.first_post.id, "post_number" => 1)expect(result.dig("post", "id")).to eq(topic.first_post.id)expect(result.dig("post", "trust_level")).to eq(admin.trust_level)+ expect(result).to match_node_output_schema(described_class)endit "creates a topic as the system user when actor_username is 'system'" do@@ -730,24 +731,23 @@ RSpec.describe DiscourseWorkflows::Nodes::Topic::V1 dofab!(:post) { Fabricate(:post, topic: topic, user: user) }it "sets topic custom fields as the configured actor" do- result =- execute_node(- configuration: {- "operation" => "set_custom_fields",- "topic_id" => topic.id.to_s,- "custom_fields" =>- custom_field_entries(- { "key" => "foo", "value" => "bar" },- { "key" => "answer", "value" => "42" },- ),- "actor_username" => admin.username,- },- item: item,- )+ config = {+ "operation" => "set_custom_fields",+ "topic_id" => topic.id.to_s,+ "custom_fields" =>+ custom_field_entries(+ { "key" => "foo", "value" => "bar" },+ { "key" => "answer", "value" => "42" },+ ),+ "actor_username" => admin.username,+ }++ result = execute_node(configuration: config, item: item)expect(topic.reload.custom_fields["foo"]).to eq("bar")expect(topic.custom_fields["answer"]).to eq("42")expect(result["topic"]["custom_fields"]).to eq("foo" => "bar", "answer" => "42")+ expect(result).to match_node_output_schema(described_class, configuration: config)endit "resolves expressions in custom field values" dodiff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/user_moderation_changed_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/user_moderation_changed_spec.rbindex ccf8f035236..bac2cdfc79d 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/user_moderation_changed_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/user_moderation_changed_spec.rb@@ -3,6 +3,7 @@RSpec.describe DiscourseWorkflows::Nodes::UserModerationChanged::V1 dofab!(:user)fab!(:admin)+ fab!(:post) { Fabricate(:post, user: user) }it "dispatches moderation changes with safe actor data and filters selected changes" dofreeze_time@@ -18,9 +19,24 @@ RSpec.describe DiscourseWorkflows::Nodes::UserModerationChanged::V1 doendFabricate(:discourse_workflows_workflow, created_by: admin, published: true, **graph)- UserSuspender.new(user, by_user: admin, reason: "Spam", suspended_till: expiry).suspend+ UserSuspender.new(+ user,+ by_user: admin,+ reason: "Spam",+ message: "Bye",+ post_id: post.id,+ suspended_till: expiry,+ ).suspendUserSuspender.unsuspend(user, by_user: admin)- UserSilencer.silence(user, admin, reason: "Spam", silenced_till: expiry, keep_posts: true)+ UserSilencer.silence(+ user,+ admin,+ reason: "Spam",+ message_body: "Hush",+ post_id: post.id,+ silenced_till: expiry,+ keep_posts: true,+ )UserSilencer.unsilence(user, admin)jobs = Jobs::DiscourseWorkflows::ExecuteWorkflow.jobs.map { |job| job["args"].first }@@ -28,6 +44,8 @@ RSpec.describe DiscourseWorkflows::Nodes::UserModerationChanged::V1 doexpect(data.pluck("change")).to eq(%w[suspended unsuspended silenced unsilenced])expect(data.pluck("reason")).to eq(["Spam", nil, "Spam", nil])expect(data.pluck("expires_at")).to eq([expiry.iso8601, nil, expiry.iso8601, nil])+ expect(data.pluck("post_id")).to eq([post.id, nil, post.id, nil])+ expect(data.pluck("message")).to eq(["Bye", nil, "Hush", nil])expect(jobs.filter_map do |job|job["trigger_data"]["change"] if job["trigger_node_id"] == "suspended"@@ -46,7 +64,13 @@ RSpec.describe DiscourseWorkflows::Nodes::UserModerationChanged::V1 dooutput = described_class.from_event(:user_silenced, user: user).output- expect(output).to include(actor: nil, reason: nil, expires_at: user.silenced_till.iso8601)+ expect(output).to include(+ actor: nil,+ reason: nil,+ message: nil,+ post_id: nil,+ expires_at: user.silenced_till.iso8601,+ )expect(output).to match_node_output_schema(described_class)enddiff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/user_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/user_spec.rbindex 97efa6dfa33..d8847bdc9c7 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/user_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/user_spec.rb@@ -434,6 +434,8 @@ RSpec.describe DiscourseWorkflows::Nodes::User::V1 doexpect(result.dig("user", "bio_raw")).to eq("Updated bio")expect(result.dig("user", "title")).to eq("Updated title")expect(result.dig("user", "website")).to eq("https://example.com")+ expect(result.dig("user", "location")).to eq("Paris")+ expect(result).to match_node_output_schema(described_class)endit "only changes fields included in updates", :aggregate_failures dodiff --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 723db0e7dd9..b1a9a1d8fa1 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@@ -87,7 +87,7 @@ RSpec.describe DiscourseWorkflows::Schema doexpect_ledger(described_class::TOPIC_PROPERTIES,serialized_keys(DiscourseWorkflows::TopicListItemSerializer, post.topic),- unemitted: %w[first_post_id visibility_reason_id],+ unemitted: %w[visibility_reason_id],undeclared: topic_undeclared,)end