Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Add workflow action for changing site settings (#43516)

Gabriel Grubbab81bee142d36
diff --git a/plugins/discourse-workflows/USE_CASES.md b/plugins/discourse-workflows/USE_CASES.md
index 3ca63b81882..34d0ebeb5e2 100644
--- a/plugins/discourse-workflows/USE_CASES.md
+++ b/plugins/discourse-workflows/USE_CASES.md
@@ -50,6 +50,7 @@ For each run, record:
| `category-changed-chat` | `when a topic is moved into Support, message General chat with a link to the topic` | `trigger:topic_category_changed -> action:send_chat_message` | Should query catalog for old/new category fields before drafting. |
| `badge-grant` | `when a TL1 user posts in General with the word helpful, grant them the Basic badge` | `trigger:post_created -> condition:filter -> action:badge` | Uses declarative filter; resolves badge; no Code node. |
| `group-add` | `when a TL1 user creates a topic in Support, add them to the helpers group` | `trigger:topic_created -> condition:filter -> action:group` | Uses `$json.post.username`; resolves group; no Code node. |
+| `site-setting-yearly` | `every year on 1 January, update the site description to mention the current year` | `trigger:schedule -> action:site_setting` | Uses `$json.year` from the schedule payload; uses the exact setting name; no Code or HTTP node. |
| `tag-group-add` | `every week, add the current-campaign tag to the Marketing tag group` | `trigger:schedule -> action:tag_group` | Resolves the tag group; creates the tag if needed; no Code node. |
| `deleted-post-chat` | `when a post in Support is deleted, message General chat with the post title` | `trigger:post_destroyed -> action:send_chat_message` | Uses `trigger:post_destroyed`; remembers `$json.user` is whoever deleted the post, not the author. |
| `mirror-post-delete` | `when a post in Support is deleted, delete post 123` | `trigger:post_destroyed -> action:post (delete)` | Uses `action:post` with `operation: delete`, not `action:flag_post` with a review-delete flag type. |
diff --git a/plugins/discourse-workflows/config/locales/client.en.yml b/plugins/discourse-workflows/config/locales/client.en.yml
index 8625ed634a0..c792f640c29 100644
--- a/plugins/discourse-workflows/config/locales/client.en.yml
+++ b/plugins/discourse-workflows/config/locales/client.en.yml
@@ -261,6 +261,7 @@ en:
"condition:time_window": "Time window"
"action:topic_tags": "Topic tags"
"action:tag_group": "Tag group"
+ "action:site_setting": "Site setting"
"action:code": "Code"
"action:topic": "Topic"
"action:post": "Post"
@@ -344,6 +345,7 @@ en:
"condition:time_window": "Branch the workflow based on the current day and time"
"action:topic_tags": "Add or remove tags on a topic"
"action:tag_group": "Add or remove tags in a tag group"
+ "action:site_setting": "Change the value of a site setting"
"action:code": "Run custom JavaScript code"
"action:topic": "Create, retrieve, list, close, archive, or set custom fields on topics"
"action:post": "Create, edit, delete, recover, retrieve, or list posts"
@@ -481,6 +483,12 @@ en:
tag_group_id_placeholder: "Select a tag group"
tag_names: "Tags"
actor_username: "Performed by user"
+ site_setting:
+ name: "Setting"
+ name_placeholder: "Select a site setting"
+ value: "Value"
+ value_description: "Enter the value as you would in admin settings. Lists use | between entries; booleans are true or false."
+ actor_username: "Performed by user"
topic_category:
topic_id: "Topic ID"
category_id: "Category"
diff --git a/plugins/discourse-workflows/config/locales/server.en.yml b/plugins/discourse-workflows/config/locales/server.en.yml
index 5c2e99911ee..54d6ff69afd 100644
--- a/plugins/discourse-workflows/config/locales/server.en.yml
+++ b/plugins/discourse-workflows/config/locales/server.en.yml
@@ -137,6 +137,13 @@ en:
no_tag_names: "No tag names provided."
no_valid_tag_names: "No valid tag names provided."
operation_failed: "Tag group operation failed: %{errors}"
+ site_setting:
+ name_required: "No site setting name provided."
+ unknown_setting: "Unknown site setting '%{name}'."
+ secret_setting: "Site setting '%{name}' holds a secret and cannot be changed by a workflow."
+ actor_not_admin: "'%{username}' must be an admin to change site settings."
+ update_failed: "Site setting '%{name}' could not be updated: %{errors}"
+ unknown_error: "unknown error"
topic_category:
operation_failed: "Category change failed."
private_message: "Personal messages cannot have a category."
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/ai/tools/workflow_node_catalog.rb b/plugins/discourse-workflows/lib/discourse_workflows/ai/tools/workflow_node_catalog.rb
index 254f1168603..8851e7c049c 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/ai/tools/workflow_node_catalog.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/ai/tools/workflow_node_catalog.rb
@@ -211,6 +211,16 @@ module DiscourseWorkflows
},
},
],
+ "action:site_setting" => [
+ {
+ name: "Set a site setting to a templated value",
+ parameters: {
+ name: "site_description",
+ value: "=The friendliest community of {{ $json.year }}",
+ actor_username: "system",
+ },
+ },
+ ],
"action:topic_category" => [
{
name: "Move the trigger topic to another category",
@@ -253,6 +263,8 @@ module DiscourseWorkflows
"ai agent bot llm classify summarize generate sentiment triage runner run as permissions uploads attachments",
"action:group" => "group membership member belongs friend friends",
"action:tag_group" => "tag group tags taxonomy add remove organize",
+ "action:site_setting" =>
+ "site setting settings configuration config admin toggle enable disable change update value",
"action:flag_user" =>
"flag user report spammer spam suspect review queue moderation approve reject account signup",
"trigger:user_added_to_group" => "joined added to group membership member",
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/ai_workflow_author.rb b/plugins/discourse-workflows/lib/discourse_workflows/ai_workflow_author.rb
index 848178939da..55b04302ca8 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/ai_workflow_author.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/ai_workflow_author.rb
@@ -91,6 +91,7 @@ module DiscourseWorkflows
- For simple checks on trigger fields, such as trust level comparisons, text contains, tags, category, staff/admin/moderator flags, use condition:filter instead of a Code node. Use condition:if only when the workflow needs separate true/false branches.
- For requests phrased as "when someone posts" or "when anyone posts", use trigger:post_created for all regular posts, including first posts and replies, unless the admin explicitly asks for only new topics or only replies. Do not ask to distinguish replies vs topic starters for a generic "posts" request.
- For group membership checks, resolve the named group with workflow_resolve_entity(kind: "group", ...), then use action:group with operation "check_membership", group_id set to the resolved group id, and username ={{ $json.user.username }} when the input schema includes user.username, otherwise use the exact username field from the current input schema. The node adds $json.group_membership.in_group and keeps the original item fields. If the workflow needs different member and non-member paths, add condition:if after the group node and compare $json.group_membership.in_group to true or false.
+ - For changing a site setting, use action:site_setting with name set to the exact setting name (snake_case, as shown in admin settings) and value as the admin would type it (lists joined with |, booleans as true or false); never use action:http_request against the site's own admin API for this. Secret settings cannot be changed.
- For tag group membership changes, resolve the named tag group with workflow_resolve_entity(kind: "tag_group", ...), then use action:tag_group with operation "add" or "remove", tag_group_id set to the resolved tag group id, and tag_names set to the tag names to change.
- For personal messages, private messages, DMs, direct messages, or PM-style notifications, use action:send_personal_message. Resolve named user recipients with workflow_resolve_entity(kind: "user") and set recipient_usernames to an array containing the resolved username. Resolve named group recipients with workflow_resolve_entity(kind: "group") and set recipient_group_names to an array containing the resolved group name, not the group id. Use leading-= template strings for title/raw when including dynamic post or topic links.
- When using an output_contracts schema, use the exact documented path (for example $json.user.trust_level, $json.user.username, $json.post.raw, or $json.post.post_url). Do not generate fallback chains for undocumented aliases such as $json.user.trustLevel or $json.trust_level.
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/site_setting_update/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/site_setting_update/v1.rb
new file mode 100644
index 00000000000..f8ab7469b92
--- /dev/null
+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/site_setting_update/v1.rb
@@ -0,0 +1,212 @@
+# frozen_string_literal: true
+
+module DiscourseWorkflows
+ module Nodes
+ module SiteSettingUpdate
+ class V1 < NodeType
+ description(
+ name: "action:site_setting",
+ version: "1.0",
+ defaults: {
+ icon: "sliders",
+ color: "orange",
+ },
+ group: "discourse_actions",
+ capabilities: {
+ run_scope: "per_item",
+ },
+ output_contracts: [
+ {
+ schema: {
+ "$schema" => Schema::DRAFT_URI,
+ "type" => "object",
+ "properties" => {
+ "name" => {
+ "type" => "string",
+ },
+ "value" => {
+ "type" => "string",
+ },
+ "previous_value" => {
+ "type" => "string",
+ },
+ "changed" => {
+ "type" => "boolean",
+ },
+ },
+ },
+ },
+ ],
+ properties: {
+ name: {
+ type: :string,
+ required: true,
+ type_options: {
+ load_options_method: "site_settings",
+ },
+ ui: {
+ control: :combo_box,
+ },
+ control_options: {
+ value_property: "id",
+ name_property: "name",
+ filterable: true,
+ none: "discourse_workflows.site_setting.name_placeholder",
+ },
+ },
+ value: {
+ type: :string,
+ required: false,
+ default: "",
+ },
+ actor_username: {
+ type: :string,
+ required: false,
+ default: "system",
+ ui: {
+ control: :actor,
+ },
+ },
+ },
+ )
+
+ def self.load_options_context(context)
+ case context.method_name
+ when "site_settings"
+ settable_setting_names
+ .select { |name| context.matches_filter?(name) }
+ .map { |name| { id: name, name: name } }
+ end
+ end
+
+ # Mirrors what the admin settings UI lets an admin change, minus secrets:
+ # a workflow stores its parameters in plain text, so secret values must
+ # never flow through one.
+ def self.settable_setting_names
+ hidden = ::SiteSetting.hidden_settings
+ deprecated =
+ SiteSettings::DeprecatedSettings::SETTINGS.map { |old_name, *| old_name.to_sym }
+
+ ::SiteSetting
+ .defaults
+ .all
+ .keys
+ .reject do |name|
+ hidden.include?(name) || ::SiteSetting.secret_settings.include?(name) ||
+ ::SiteSetting.shadowed_settings.include?(name) || ::SiteSetting.themeable[name] ||
+ deprecated.include?(name) || unconfigurable_plugin_setting?(name)
+ end
+ .map(&:to_s)
+ .sort
+ end
+
+ def self.unconfigurable_plugin_setting?(name)
+ plugin_name = ::SiteSetting.plugins[name]
+ plugin_name.present? && !Discourse.plugins_by_name[plugin_name].configurable?
+ end
+
+ def execute(exec_ctx)
+ items =
+ exec_ctx.input_items.map.with_index do |_item, item_index|
+ config = {
+ "name" => exec_ctx.get_node_parameter("name", item_index),
+ "value" => exec_ctx.get_node_parameter("value", item_index, default: ""),
+ }
+
+ wrap(process(exec_ctx, config, item_index))
+ end
+
+ [items]
+ end
+
+ private
+
+ def process(exec_ctx, config, item_index)
+ name = config["name"].to_s.strip
+ if name.blank?
+ raise_node_error!(I18n.t("discourse_workflows.errors.site_setting.name_required"))
+ end
+ ensure_settable!(name)
+
+ actor = exec_ctx.actor_from_parameter("actor_username", item_index)
+ previous_value = ::SiteSetting.public_send(name)
+ output = nil
+
+ ::SiteSetting::Update.call(
+ guardian: actor.guardian,
+ params: {
+ settings: [{ setting_name: name, value: config["value"].to_s }],
+ },
+ ) do
+ on_success { output = output_for(name, previous_value) }
+ on_failed_policy(:current_user_is_admin) do
+ raise_node_error!(
+ I18n.t(
+ "discourse_workflows.errors.site_setting.actor_not_admin",
+ username: actor.username,
+ ),
+ )
+ end
+ on_failed_policy(:settings_are_not_deprecated) do |policy|
+ raise_node_error!(policy.reason)
+ end
+ on_failed_policy(:settings_are_unshadowed_globally) do |policy|
+ raise_node_error!(policy.reason)
+ end
+ on_failed_policy(:settings_are_visible) { |policy| raise_node_error!(policy.reason) }
+ on_failed_policy(:settings_are_configurable) do |policy|
+ raise_node_error!(policy.reason)
+ end
+ on_failed_contract do |contract|
+ raise_update_failed!(name, contract.errors.full_messages.join(", "))
+ end
+ on_exceptions { |error| raise_update_failed!(name, error.message) }
+ on_failure { raise_update_failed!(name, nil) }
+ end
+
+ output
+ end
+
+ def ensure_settable!(name)
+ unless ::SiteSetting.has_setting?(name)
+ raise_node_error!(
+ I18n.t("discourse_workflows.errors.site_setting.unknown_setting", name: name),
+ )
+ end
+
+ if ::SiteSetting.secret_settings.include?(name.to_sym)
+ raise_node_error!(
+ I18n.t("discourse_workflows.errors.site_setting.secret_setting", name: name),
+ )
+ end
+ end
+
+ def raise_update_failed!(name, errors)
+ raise_node_error!(
+ I18n.t(
+ "discourse_workflows.errors.site_setting.update_failed",
+ name: name,
+ errors:
+ errors.presence || I18n.t("discourse_workflows.errors.site_setting.unknown_error"),
+ ),
+ )
+ end
+
+ def output_for(name, previous_value)
+ current_value = ::SiteSetting.public_send(name)
+
+ {
+ name: name,
+ value: display_value(current_value),
+ previous_value: display_value(previous_value),
+ changed: current_value != previous_value,
+ }
+ end
+
+ def display_value(value)
+ Array.wrap(value).map { |entry| entry.is_a?(::Upload) ? entry.url : entry.to_s }.join("|")
+ end
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-workflows/plugin.rb b/plugins/discourse-workflows/plugin.rb
index 10be13bf565..41c39fd7b8e 100644
--- a/plugins/discourse-workflows/plugin.rb
+++ b/plugins/discourse-workflows/plugin.rb
@@ -56,6 +56,7 @@ register_svg_icon "layer-group"
register_svg_icon "copy"
register_svg_icon "paste"
register_svg_icon "scissors"
+register_svg_icon "sliders"
add_admin_route "discourse_workflows.admin.title", "discourse-workflows", use_new_show_route: true
diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/site_setting_update_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/site_setting_update_spec.rb
new file mode 100644
index 00000000000..e4433be379b
--- /dev/null
+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/site_setting_update_spec.rb
@@ -0,0 +1,146 @@
+# frozen_string_literal: true
+
+RSpec.describe DiscourseWorkflows::Nodes::SiteSettingUpdate::V1 do
+ fab!(:admin)
+ fab!(:moderator)
+
+ describe ".load_options_context" do
+ def options_for(filter: nil)
+ context = DiscourseWorkflows::LoadOptionsContext.new(method_name: "site_settings", filter:)
+ described_class.load_options_context(context)
+ end
+
+ it "lists settings an admin could change in the admin UI, sorted by name" do
+ names = options_for.map { |option| option[:id] }
+
+ expect(names).to include("title", "site_description", "enable_badges")
+ expect(names).to eq(names.sort)
+ expect(options_for.first).to eq(id: names.first, name: names.first)
+ end
+
+ it "excludes hidden, secret, and shadowed settings" do
+ SiteSetting.shadowed_settings << :site_description
+ names = options_for.map { |option| option[:id] }
+
+ expect(names).not_to include(*SiteSetting.hidden_settings.map(&:to_s))
+ expect(names).not_to include(*SiteSetting.secret_settings.map(&:to_s))
+ expect(names).not_to include("site_description")
+ ensure
+ SiteSetting.shadowed_settings.delete(:site_description)
+ end
+
+ it "filters by the typed text" do
+ expect(options_for(filter: "site_desc")).to include(
+ { id: "site_description", name: "site_description" },
+ )
+ expect(options_for(filter: "site_desc")).not_to include({ id: "title", name: "title" })
+ end
+ end
+
+ describe "#execute" do
+ let(:item) { { "json" => { "year" => "2026" } } }
+ let(:history_scope) { UserHistory.where(action: UserHistory.actions[:change_site_setting]) }
+
+ it "updates a string setting, logs it, and reports the change" do
+ SiteSetting.site_description = "Old description"
+ config = { "name" => "site_description", "value" => "=Community since {{ $json.year }}" }
+
+ expect { @result = execute_node(configuration: config, item: item) }.to change {
+ history_scope.count
+ }.by(1)
+
+ expect(SiteSetting.site_description).to eq("Community since 2026")
+ expect(@result).to eq(
+ "name" => "site_description",
+ "value" => "Community since 2026",
+ "previous_value" => "Old description",
+ "changed" => true,
+ )
+ expect(history_scope.last).to have_attributes(
+ acting_user_id: Discourse.system_user.id,
+ subject: "site_description",
+ previous_value: "Old description",
+ new_value: "Community since 2026",
+ )
+ end
+
+ it "coerces typed values the way the admin UI does" do
+ SiteSetting.enable_badges = true
+ config = { "name" => "enable_badges", "value" => "false", "actor_username" => admin.username }
+
+ result = execute_node(configuration: config, item: item)
+
+ expect(SiteSetting.enable_badges).to eq(false)
+ expect(result).to include("value" => "false", "previous_value" => "true", "changed" => true)
+ expect(history_scope.last.acting_user_id).to eq(admin.id)
+ end
+
+ it "reports no change and writes no log when the value is already set" do
+ SiteSetting.site_description = "Same"
+ config = { "name" => "site_description", "value" => "Same" }
+
+ expect { @result = execute_node(configuration: config, item: item) }.not_to change {
+ history_scope.count
+ }
+
+ expect(@result).to include("changed" => false)
+ end
+
+ it "surfaces core validation errors as node errors" do
+ config = { "name" => "min_password_length", "value" => "not a number" }
+
+ expect { execute_node(configuration: config, item: item) }.to raise_error(
+ DiscourseWorkflows::NodeError,
+ /min_password_length/,
+ )
+ end
+
+ it "rejects unknown settings" do
+ config = { "name" => "definitely_not_a_setting", "value" => "x" }
+
+ expect { execute_node(configuration: config, item: item) }.to raise_error(
+ DiscourseWorkflows::NodeError,
+ /Unknown site setting/,
+ )
+ end
+
+ it "rejects secret settings" do
+ secret_name = SiteSetting.secret_settings.first.to_s
+
+ expect {
+ execute_node(configuration: { "name" => secret_name, "value" => "x" }, item: item)
+ }.to raise_error(DiscourseWorkflows::NodeError, /holds a secret/)
+ end
+
+ it "rejects hidden settings" do
+ hidden_name = SiteSetting.hidden_settings.first.to_s
+
+ expect {
+ execute_node(configuration: { "name" => hidden_name, "value" => "x" }, item: item)
+ }.to raise_error(DiscourseWorkflows::NodeError)
+ end
+
+ it "requires the actor to be an admin" do
+ config = {
+ "name" => "site_description",
+ "value" => "Nope",
+ "actor_username" => moderator.username,
+ }
+
+ expect { execute_node(configuration: config, item: item) }.to raise_error(
+ DiscourseWorkflows::NodeError,
+ /must be an admin/,
+ )
+ expect(SiteSetting.site_description).not_to eq("Nope")
+ end
+
+ it "does not let the anonymous actor change settings" do
+ config = { "name" => "site_description", "value" => "Nope", "actor_username" => "anonymous" }
+
+ expect { execute_node(configuration: config, item: item) }.to raise_error(
+ DiscourseWorkflows::NodeError,
+ /must be an admin/,
+ )
+ end
+ end
+end
diff --git a/plugins/discourse-workflows/spec/requests/discourse_workflows/dynamic_node_parameters_controller_spec.rb b/plugins/discourse-workflows/spec/requests/discourse_workflows/dynamic_node_parameters_controller_spec.rb
index 7ed23d8d91d..9d75478c1fd 100644
--- a/plugins/discourse-workflows/spec/requests/discourse_workflows/dynamic_node_parameters_controller_spec.rb
+++ b/plugins/discourse-workflows/spec/requests/discourse_workflows/dynamic_node_parameters_controller_spec.rb
@@ -70,6 +70,29 @@ RSpec.describe DiscourseWorkflows::DynamicNodeParametersController do
)
end
+ it "returns filtered site settings for the Site setting node" do
+ post "/admin/plugins/discourse-workflows/dynamic-node-parameters/options.json",
+ params: {
+ nodeTypeAndVersion: {
+ name: "action:site_setting",
+ version: "1.0",
+ },
+ path: "name",
+ methodName: "site_settings",
+ currentNodeParameters: {
+ },
+ filter: "site_descr",
+ },
+ as: :json
+
+ expect(response).to have_http_status(:ok)
+ expect(response.parsed_body).to include(
+ "id" => "site_description",
+ "name" => "site_description",
+ )
+ expect(response.parsed_body).not_to include("id" => "title", "name" => "title")
+ end
+
it "returns 404 for an unknown node type" do
post "/admin/plugins/discourse-workflows/dynamic-node-parameters/options.json",
params: {
diff --git a/plugins/discourse-workflows/spec/requests/discourse_workflows/node_types_controller_spec.rb b/plugins/discourse-workflows/spec/requests/discourse_workflows/node_types_controller_spec.rb
index b3e3501ec16..dc134ee7076 100644
--- a/plugins/discourse-workflows/spec/requests/discourse_workflows/node_types_controller_spec.rb
+++ b/plugins/discourse-workflows/spec/requests/discourse_workflows/node_types_controller_spec.rb
@@ -40,5 +40,33 @@ RSpec.describe DiscourseWorkflows::NodeTypesController do
)
expect(topic_node.fetch("metadata", {})).not_to have_key("topic_custom_fields")
end
+
+ it "returns Site setting action metadata without hidden or secret settings" do
+ get "/admin/plugins/discourse-workflows/node-types.json"
+
+ node =
+ response.parsed_body["node_types"].find do |node_type|
+ node_type["identifier"] == "action:site_setting"
+ end
+ properties = node["properties"]
+
+ expect(properties["name"]).to include(
+ "type" => "string",
+ "required" => true,
+ "type_options" => include("load_options_method" => "site_settings"),
+ "ui" => include("control" => "combo_box"),
+ )
+ expect(properties["value"]).to include("type" => "string")
+ expect(properties["actor_username"]).to include("ui" => include("control" => "actor"))
+
+ option_ids = node.dig("metadata", "site_settings").map { |option| option["id"] }
+ expect(option_ids).to include("site_description")
+ expect(option_ids).not_to include(SiteSetting.secret_settings.first.to_s)
+ expect(option_ids).not_to include(SiteSetting.hidden_settings.first.to_s)
+ expect(node.dig("output_contracts", 0, "schema", "properties")).to include(
+ "name" => include("type" => "string"),
+ "changed" => include("type" => "boolean"),
+ )
+ end
end
end