mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 00:32:52 +08:00
FEATURE: limits post created edited trigger to a group (#31523)
This commit allows admins to limit the post created/edited trigger execution to a specific post user group. It's for example useful if you want to auto tag all the topics created by member of a specific group.
This commit is contained in:
@ -162,11 +162,11 @@ en:
|
|||||||
restricted_category:
|
restricted_category:
|
||||||
label: Category
|
label: Category
|
||||||
description: Optional, will trigger only if the post's topic is in this category
|
description: Optional, will trigger only if the post's topic is in this category
|
||||||
restricted_group:
|
restricted_user_group:
|
||||||
label: Group
|
label: Restricted user group
|
||||||
description: Optional, will trigger only if the post's topic is a personal message in this group's inbox
|
description: Optional, will trigger only if the post user is in this group
|
||||||
restricted_groups:
|
restricted_groups:
|
||||||
label: Groups
|
label: Restricted inboxes groups
|
||||||
description: Optional, will trigger only if the post's topic is a personal message in one of the group inboxes
|
description: Optional, will trigger only if the post's topic is a personal message in one of the group inboxes
|
||||||
ignore_group_members:
|
ignore_group_members:
|
||||||
label: Ignore group members
|
label: Ignore group members
|
||||||
|
@ -65,6 +65,9 @@ module DiscourseAutomation
|
|||||||
next if ignore_group_members && post.user.in_any_groups?(restricted_group_ids)
|
next if ignore_group_members && post.user.in_any_groups?(restricted_group_ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
user_group = automation.trigger_field("restricted_user_group")["value"]
|
||||||
|
next if user_group && !post.user.in_any_groups?([user_group])
|
||||||
|
|
||||||
ignore_automated = automation.trigger_field("ignore_automated")
|
ignore_automated = automation.trigger_field("ignore_automated")
|
||||||
next if ignore_automated["value"] && post.incoming_email&.is_auto_generated?
|
next if ignore_automated["value"] && post.incoming_email&.is_auto_generated?
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ DiscourseAutomation::Triggerable.add(DiscourseAutomation::Triggers::POST_CREATED
|
|||||||
field :restricted_category, component: :category
|
field :restricted_category, component: :category
|
||||||
field :restricted_tags, component: :tags
|
field :restricted_tags, component: :tags
|
||||||
field :restricted_groups, component: :groups
|
field :restricted_groups, component: :groups
|
||||||
|
field :restricted_user_group, component: :group
|
||||||
field :ignore_automated, component: :boolean
|
field :ignore_automated, component: :boolean
|
||||||
field :ignore_group_members, component: :boolean
|
field :ignore_group_members, component: :boolean
|
||||||
field :valid_trust_levels, component: :"trust-levels"
|
field :valid_trust_levels, component: :"trust-levels"
|
||||||
|
@ -126,6 +126,38 @@ describe "PostCreatedEdited" do
|
|||||||
expect(list[0]["action"].to_s).to eq("edit")
|
expect(list[0]["action"].to_s).to eq("edit")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when user group is restricted" do
|
||||||
|
fab!(:group)
|
||||||
|
|
||||||
|
before do
|
||||||
|
automation.upsert_field!(
|
||||||
|
"restricted_user_group",
|
||||||
|
"group",
|
||||||
|
{ value: group.id },
|
||||||
|
target: "trigger",
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when user is member of the group" do
|
||||||
|
before { group.add(user) }
|
||||||
|
|
||||||
|
it "fires the trigger" do
|
||||||
|
list = capture_contexts { PostCreator.create(user, basic_topic_params) }
|
||||||
|
|
||||||
|
expect(list.length).to eq(1)
|
||||||
|
expect(list[0]["kind"]).to eq("post_created_edited")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when user is not member of the group" do
|
||||||
|
it "doesn’t fire the trigger" do
|
||||||
|
list = capture_contexts { PostCreator.create(user, basic_topic_params) }
|
||||||
|
|
||||||
|
expect(list).to be_blank
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "when trust_levels are restricted" do
|
context "when trust_levels are restricted" do
|
||||||
before do
|
before do
|
||||||
automation.upsert_field!(
|
automation.upsert_field!(
|
||||||
|
Reference in New Issue
Block a user