Skip to content
This repository was archived by the owner on Jul 14, 2025. It is now read-only.

Commit f15c0fd

Browse files
authored
Revert "FIX: revert chat-integration move to discourse-automation (#214)" (#218)
This reverts commit a1c8f4e.
1 parent 3f8b67d commit f15c0fd

File tree

5 files changed

+16
-150
lines changed

5 files changed

+16
-150
lines changed

admin/assets/javascripts/admin/models/rule.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export default class Rule extends RestModel {
2323
},
2424
];
2525

26+
possible_filters_id = ["thread", "watch", "follow", "mute"];
27+
2628
get available_filters() {
2729
const available = [];
2830
const provider = this.channel.provider;
@@ -46,11 +48,6 @@ export default class Rule extends RestModel {
4648
name: I18n.t("chat_integration.filter.follow"),
4749
icon: "circle",
4850
},
49-
{
50-
id: "tag_added",
51-
name: I18n.t("chat_integration.filter.tag_added"),
52-
icon: "tag",
53-
},
5451
{
5552
id: "mute",
5653
name: I18n.t("chat_integration.filter.mute"),

admin/assets/javascripts/admin/routes/admin-plugins-chat-integration-provider.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { action } from "@ember/object";
2+
import { getOwner } from "@ember/owner";
23
import Group from "discourse/models/group";
34
import DiscourseRoute from "discourse/routes/discourse";
45

@@ -13,14 +14,18 @@ export default class AdminPluginsChatIntegrationProvider extends DiscourseRoute
1314
Group.findAll(),
1415
]);
1516

17+
const enabledFilters =
18+
getOwner(this).lookup("model:rule").possible_filters_id;
1619
channels.forEach((channel) => {
1720
channel.set(
1821
"rules",
19-
channel.rules.map((rule) => {
20-
rule = this.store.createRecord("rule", rule);
21-
rule.set("channel", channel);
22-
return rule;
23-
})
22+
channel.rules
23+
.filter((rule) => enabledFilters.includes(rule.filter))
24+
.map((rule) => {
25+
rule = this.store.createRecord("rule", rule);
26+
rule.set("channel", channel);
27+
return rule;
28+
})
2429
);
2530
});
2631

app/services/manager.rb

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ def self.trigger_notifications(post_id)
1515
# Abort if the post is blank
1616
return if post.blank?
1717

18-
# Abort if post is not either regular, or a 'tags_changed'/'category_changed' small action
18+
# Abort if post is not either regular or a 'category_changed' small action
1919
if (post.post_type != Post.types[:regular]) &&
2020
!(
2121
post.post_type == Post.types[:small_action] &&
22-
%w[tags_changed category_changed].include?(post.action_code)
22+
%w[category_changed].include?(post.action_code)
2323
)
2424
return
2525
end
@@ -55,34 +55,7 @@ def self.trigger_notifications(post_id)
5555
end
5656
end
5757

58-
if post.action_code == "tags_changed"
59-
# Post is a small_action post regarding tags changing for the topic. Check if any tags were _added_
60-
# and if so, corresponding rules with `filter: tag_added`
61-
tags_added = post.custom_fields["tags_added"]
62-
tags_added = [tags_added].compact if !tags_added.is_a?(Array)
63-
return if tags_added.blank?
64-
65-
tags_removed = post.custom_fields["tags_removed"]
66-
tags_removed = [tags_removed].compact if !tags_removed.is_a?(Array)
67-
68-
unchanged_tags = topic.tags.map(&:name) - tags_added - tags_removed
69-
70-
matching_rules =
71-
matching_rules.select do |rule|
72-
# Only rules that match this post, are ones where the filter is "tag_added"
73-
next false if rule.filter != "tag_added"
74-
next true if rule.tags.blank?
75-
76-
# Skip if the topic already has one of the tags in the rule, applied
77-
next false if unchanged_tags.any? && (unchanged_tags & rule.tags).any?
78-
79-
# We don't need to do any additional filtering here because topics are filtered
80-
# by tag later
81-
true
82-
end
83-
else
84-
matching_rules = matching_rules.select { |rule| rule.filter != "tag_added" }
85-
end
58+
matching_rules = matching_rules.select { |rule| rule.filter != "tag_added" } # ignore tag_added rules, now uses Automation
8659

8760
# If tagging is enabled, thow away rules that don't apply to this topic
8861
if SiteSetting.tagging_enabled
@@ -97,7 +70,7 @@ def self.trigger_notifications(post_id)
9770

9871
# Sort by order of precedence
9972
t_prec = { "group_message" => 0, "group_mention" => 1, "normal" => 2 } # Group things win
100-
f_prec = { "mute" => 0, "thread" => 1, "watch" => 2, "follow" => 3, "tag_added" => 4 } #(mute always wins; thread beats watch beats follow)
73+
f_prec = { "mute" => 0, "thread" => 1, "watch" => 2, "follow" => 3 } #(mute always wins; thread beats watch beats follow)
10174
sort_func =
10275
proc { |a, b| [t_prec[a.type], f_prec[a.filter]] <=> [t_prec[b.type], f_prec[b.filter]] }
10376
matching_rules = matching_rules.sort(&sort_func)

config/locales/client.en.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ en:
3737
mute: 'Mute'
3838
follow: 'First post only'
3939
watch: 'All posts and replies'
40-
tag_added: 'Tag added to topic'
4140
thread: 'All posts with threaded replies'
4241
rule_table:
4342
filter: "Filter"

spec/services/manager_spec.rb

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -316,38 +316,6 @@
316316
expect(provider.sent_to_channel_ids).to contain_exactly(chan1.id)
317317
end
318318

319-
describe "With `create_post_for_category_and_tag_changes` enabled" do
320-
before(:each) { SiteSetting.create_post_for_category_and_tag_changes = true }
321-
322-
let(:admin) { Fabricate(:admin) }
323-
let(:other_topic) { Fabricate(:topic) }
324-
let(:other_topic_post) { Fabricate(:post, topic: topic) }
325-
326-
it "should trigger follow rules for specific categories when topic category changes" do
327-
DiscourseChatIntegration::Rule.create!(
328-
channel: chan1,
329-
filter: "follow",
330-
category_id: category.id,
331-
)
332-
333-
PostRevisor.new(other_topic_post).revise!(admin, category_id: category.id)
334-
335-
manager.trigger_notifications(topic.ordered_posts.last.id)
336-
337-
expect(provider.sent_to_channel_ids).to contain_exactly(chan1.id)
338-
end
339-
340-
it "shouldn't trigger follow rules with wildcard category match" do
341-
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: "follow", category_id: nil)
342-
343-
PostRevisor.new(other_topic_post).revise!(admin, category_id: category.id)
344-
345-
manager.trigger_notifications(topic.ordered_posts.last.id)
346-
347-
expect(provider.sent_to_channel_ids).to contain_exactly
348-
end
349-
end
350-
351319
describe "with tags enabled" do
352320
let(:tag) { Fabricate(:tag, name: "gsoc") }
353321
let(:tagged_topic) { Fabricate(:topic, category_id: category.id, tags: [tag]) }
@@ -377,82 +345,6 @@
377345

378346
expect(provider.sent_to_channel_ids).to contain_exactly(chan1.id)
379347
end
380-
381-
describe "with create_small_action_post_for_tag_changes enabled" do
382-
fab!(:admin) { Fabricate(:admin, refresh_auto_groups: true) }
383-
fab!(:additional_tag) { Fabricate(:tag) }
384-
385-
before { SiteSetting.create_post_for_category_and_tag_changes = true }
386-
387-
def set_new_tags_and_return_small_action_post(tags)
388-
PostRevisor.new(tagged_first_post).revise!(admin, tags: tags)
389-
390-
tagged_topic.ordered_posts.last
391-
end
392-
393-
it "should notify when rule is set up for tag additions for a category with no tag filter" do
394-
post = set_new_tags_and_return_small_action_post([tag.name, additional_tag.name])
395-
396-
DiscourseChatIntegration::Rule.create!(
397-
channel: chan1,
398-
filter: "tag_added",
399-
category_id: category.id,
400-
)
401-
402-
manager.trigger_notifications(post.id)
403-
expect(provider.sent_to_channel_ids).to contain_exactly(chan1.id)
404-
end
405-
406-
it "notifies when topic has a tag added that matches the rule" do
407-
post = set_new_tags_and_return_small_action_post([tag.name, additional_tag.name])
408-
409-
DiscourseChatIntegration::Rule.create!(
410-
channel: chan1,
411-
filter: "tag_added",
412-
category_id: category.id,
413-
tags: [additional_tag.name],
414-
)
415-
416-
manager.trigger_notifications(post.id)
417-
expect(provider.sent_to_channel_ids).to contain_exactly(chan1.id)
418-
end
419-
420-
it "doesn't notify when a new regular post is created" do
421-
DiscourseChatIntegration::Rule.create!(
422-
channel: chan1,
423-
filter: "tag_added",
424-
category_id: nil,
425-
tags: [tag.name],
426-
)
427-
428-
post = Fabricate(:post, topic: tagged_topic)
429-
manager.trigger_notifications(post.id)
430-
expect(provider.sent_to_channel_ids).to contain_exactly
431-
end
432-
433-
it "doesn't notify when topic has an unchanged tag present in the rule, even if a new tag is added" do
434-
post = set_new_tags_and_return_small_action_post([tag.name, additional_tag.name])
435-
436-
DiscourseChatIntegration::Rule.create!(
437-
channel: chan1,
438-
filter: "tag_added",
439-
category_id: category.id,
440-
tags: [tag.name],
441-
)
442-
443-
manager.trigger_notifications(post.id)
444-
expect(provider.sent_to_channel_ids).to contain_exactly
445-
end
446-
447-
it "doesn't notify for small action 'tags_changed' posts unless a matching rule exists" do
448-
post = set_new_tags_and_return_small_action_post([additional_tag.name])
449-
450-
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: "watch", category_id: nil) # Wildcard watch
451-
452-
manager.trigger_notifications(post.id)
453-
expect(provider.sent_to_channel_ids).to contain_exactly
454-
end
455-
end
456348
end
457349
end
458350
end

0 commit comments

Comments
 (0)