Skip to content

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

FEATURE: Expose content and user locales to workflows (#45163)

Régis Hanolffa10987ae2b
diff --git a/plugins/discourse-workflows/app/serializers/discourse_workflows/post_serializer.rb b/plugins/discourse-workflows/app/serializers/discourse_workflows/post_serializer.rb
index 8240d00b8b2..1698655b8ab 100644
--- a/plugins/discourse-workflows/app/serializers/discourse_workflows/post_serializer.rb
+++ b/plugins/discourse-workflows/app/serializers/discourse_workflows/post_serializer.rb
@@ -26,6 +26,7 @@ module DiscourseWorkflows
:category_slug,
:tags,
:upload_ids,
+ :locale,
:raw,
:cooked
diff --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.rb
index 018cb9b0ca9..f7cd15ea54d 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
@@ -15,5 +15,13 @@ module DiscourseWorkflows
def first_post_id
object.first_post&.id
end
+
+ def include_fancy_title_localized?
+ true
+ end
+
+ def include_locale?
+ true
+ end
end
end
diff --git a/plugins/discourse-workflows/app/serializers/discourse_workflows/topic_serializer.rb b/plugins/discourse-workflows/app/serializers/discourse_workflows/topic_serializer.rb
index e41ed42d6d7..3a826e47b3f 100644
--- a/plugins/discourse-workflows/app/serializers/discourse_workflows/topic_serializer.rb
+++ b/plugins/discourse-workflows/app/serializers/discourse_workflows/topic_serializer.rb
@@ -102,6 +102,14 @@ module DiscourseWorkflows
object.private_message?
end
+ def include_fancy_title_localized?
+ true
+ end
+
+ def include_locale?
+ true
+ end
+
def include_visibility_reason_id?
object.visibility_reason_id.present?
end
diff --git a/plugins/discourse-workflows/app/serializers/discourse_workflows/user_serializer.rb b/plugins/discourse-workflows/app/serializers/discourse_workflows/user_serializer.rb
index 3bf5efb5fc5..2181cde14e8 100644
--- a/plugins/discourse-workflows/app/serializers/discourse_workflows/user_serializer.rb
+++ b/plugins/discourse-workflows/app/serializers/discourse_workflows/user_serializer.rb
@@ -15,7 +15,8 @@ module DiscourseWorkflows
:silenced,
:suspended,
:uploaded_avatar_id,
- :avatar_template
+ :avatar_template,
+ :locale
def trust_level_name
TrustLevel.name(object.trust_level)
@@ -32,5 +33,9 @@ module DiscourseWorkflows
def suspended
object.suspended?
end
+
+ def locale
+ object.effective_locale
+ end
end
end
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic/v1.rb
index ac2ff39ebcc..3eb558d546c 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic/v1.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic/v1.rb
@@ -33,6 +33,7 @@ module DiscourseWorkflows
"reply_to_post_id",
"reply_to_username",
"url",
+ "locale",
),
"WebHookPostSerializer payload",
)
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/schema.rb b/plugins/discourse-workflows/lib/discourse_workflows/schema.rb
index 8180627ac6a..c2b7b05eece 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/schema.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/schema.rb
@@ -48,6 +48,7 @@ module DiscourseWorkflows
"id": { "type": "integer" },
"title": { "type": "string" },
"fancy_title": { "type": "string" },
+ "fancy_title_localized": { "type": "boolean", "description": "Whether fancy_title is a translation" },
"slug": { "type": "string" },
"url": { "type": "string", "description": "Absolute URL of the topic" },
"archetype": { "type": "string", "description": "regular for topics, private_message for PMs" },
@@ -55,6 +56,7 @@ module DiscourseWorkflows
"category_id": { "type": ["integer", "null"] },
"user_id": { "type": "integer" },
"username": { "type": ["string", "null"], "description": "Username of the topic author" },
+ "locale": { "type": ["string", "null"], "description": "Content locale, null until set by the author or detected" },
"tags": {
"type": "array",
"x-optional": true,
@@ -109,7 +111,8 @@ module DiscourseWorkflows
"reply_count": { "type": "integer" },
"score": { "type": ["number", "null"] },
"tags": { "type": "array", "items": { "type": "string" } },
- "upload_ids": { "type": "array", "items": { "type": "integer" } }
+ "upload_ids": { "type": "array", "items": { "type": "integer" } },
+ "locale": { "type": ["string", "null"], "description": "Content locale, null until set by the author or detected" }
}
JSON
@@ -128,7 +131,8 @@ module DiscourseWorkflows
"silenced": { "type": "boolean" },
"suspended": { "type": "boolean" },
"uploaded_avatar_id": { "type": ["integer", "null"] },
- "avatar_template": { "type": "string" }
+ "avatar_template": { "type": "string" },
+ "locale": { "type": "string", "description": "Interface locale, the site default when the user has not chosen one" }
}
JSON
diff --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.rb
index 043e9d13d1d..b7216752477 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
@@ -38,6 +38,9 @@ RSpec.describe DiscourseWorkflows::Nodes::TopicCreated::V1 do
describe "#output" do
it "returns post and topic data" do
+ topic.update_column(:locale, "de")
+ first_post.update_column(:locale, "fr")
+ user.update_column(:locale, "nl")
trigger = described_class.new(topic)
output = trigger.output
@@ -53,6 +56,9 @@ RSpec.describe DiscourseWorkflows::Nodes::TopicCreated::V1 do
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[:topic][:locale]).to eq("de")
+ expect(output[:post][:locale]).to eq("fr")
+ expect(output[:user][:locale]).to eq("nl")
expect(output).to match_node_output_schema(described_class)
end