mirror of
https://github.com/discourse/discourse.git
synced 2024-11-21 16:38:15 -06:00
FEATURE: Add user to topic_tags_changed event (#28714)
* FEATURE: Add user to topic_tags_changed event Add user to topic_tags_changed event context Update automation plugin with new arguments in event Update tests for new arguments relates to https://github.com/discourse/discourse-chat-integration/pull/214 * DEV: change variable name for better readability changed `tags` to be payload and used `values_at` to get the values of the keys
This commit is contained in:
parent
5f5680dbaf
commit
a98d3d40f2
@ -212,6 +212,7 @@ module DiscourseTagging
|
||||
topic,
|
||||
old_tag_names: old_tag_names,
|
||||
new_tag_names: topic.tags.map(&:name),
|
||||
user: guardian.user,
|
||||
)
|
||||
|
||||
true
|
||||
|
@ -218,7 +218,7 @@ module DiscourseAutomation
|
||||
end
|
||||
end
|
||||
|
||||
def self.handle_topic_tags_changed(topic, old_tag_names, new_tag_names)
|
||||
def self.handle_topic_tags_changed(topic, old_tag_names, new_tag_names, user)
|
||||
name = DiscourseAutomation::Triggers::TOPIC_TAGS_CHANGED
|
||||
|
||||
DiscourseAutomation::Automation
|
||||
@ -248,6 +248,7 @@ module DiscourseAutomation
|
||||
"topic" => topic,
|
||||
"removed_tags" => removed_tags,
|
||||
"added_tags" => added_tags,
|
||||
"user" => user,
|
||||
"placeholders" => {
|
||||
"topic_url" => topic.relative_url,
|
||||
"topic_title" => topic.title,
|
||||
|
@ -182,11 +182,14 @@ after_initialize do
|
||||
DiscourseAutomation::EventHandlers.handle_pm_created(topic) if topic.private_message?
|
||||
end
|
||||
|
||||
on(:topic_tags_changed) do |topic, tags|
|
||||
on(:topic_tags_changed) do |topic, payload|
|
||||
old_tag_names, new_tag_names, user = payload.values_at(:old_tag_names, :new_tag_names, :user)
|
||||
|
||||
DiscourseAutomation::EventHandlers.handle_topic_tags_changed(
|
||||
topic,
|
||||
tags[:old_tag_names],
|
||||
tags[:new_tag_names],
|
||||
old_tag_names,
|
||||
new_tag_names,
|
||||
user,
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -55,6 +55,7 @@ describe DiscourseAutomation::Triggers::TOPIC_TAGS_CHANGED do
|
||||
|
||||
expect(list.length).to eq(1)
|
||||
expect(list[0]["kind"]).to eq(DiscourseAutomation::Triggers::TOPIC_TAGS_CHANGED)
|
||||
expect(list[0]["user"]).to eq(user)
|
||||
end
|
||||
|
||||
it "should fire the trigger if the tag is removed" do
|
||||
@ -65,6 +66,7 @@ describe DiscourseAutomation::Triggers::TOPIC_TAGS_CHANGED do
|
||||
|
||||
expect(list.length).to eq(1)
|
||||
expect(list[0]["kind"]).to eq(DiscourseAutomation::Triggers::TOPIC_TAGS_CHANGED)
|
||||
expect(list[0]["user"]).to eq(user)
|
||||
end
|
||||
|
||||
it "should not fire if the tag is not present" do
|
||||
|
@ -949,16 +949,16 @@ RSpec.describe DiscourseTagging do
|
||||
|
||||
it "sends a discourse event when the staff adds a staff-only tag" do
|
||||
old_tag_names = topic.tags.pluck(:name)
|
||||
admin_guardian = Guardian.new(admin)
|
||||
tag_changed_event =
|
||||
DiscourseEvent
|
||||
.track_events do
|
||||
DiscourseTagging.tag_topic_by_names(topic, Guardian.new(admin), ["alpha"])
|
||||
end
|
||||
.track_events { DiscourseTagging.tag_topic_by_names(topic, admin_guardian, ["alpha"]) }
|
||||
.last
|
||||
expect(tag_changed_event[:event_name]).to eq(:topic_tags_changed)
|
||||
expect(tag_changed_event[:params].first).to eq(topic)
|
||||
expect(tag_changed_event[:params].second[:old_tag_names]).to eq(old_tag_names)
|
||||
expect(tag_changed_event[:params].second[:new_tag_names]).to eq(["alpha"])
|
||||
expect(tag_changed_event[:params].second[:user]).to eq(admin_guardian.user)
|
||||
end
|
||||
|
||||
context "with non-staff users in tag group groups" do
|
||||
|
Loading…
Reference in New Issue
Block a user