FIX: Error when moving the group default notification state (#28910)

This commit is contained in:
Jan Cernik 2024-09-13 16:01:20 -03:00 committed by GitHub
parent e7e9c99568
commit 0c019b2e45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 8 deletions

View File

@ -19,7 +19,7 @@
<TagChooser <TagChooser
@tags={{this.model.watching_tags}} @tags={{this.model.watching_tags}}
@blacklist={{this.selectedTags}} @blockedTags={{this.selectedTags}}
@everyTag={{true}} @everyTag={{true}}
@unlimitedTagCount={{true}} @unlimitedTagCount={{true}}
@options={{hash allowAny=false}} @options={{hash allowAny=false}}
@ -36,7 +36,7 @@
<TagChooser <TagChooser
@tags={{this.model.tracking_tags}} @tags={{this.model.tracking_tags}}
@blacklist={{this.selectedTags}} @blockedTags={{this.selectedTags}}
@everyTag={{true}} @everyTag={{true}}
@unlimitedTagCount={{true}} @unlimitedTagCount={{true}}
@options={{hash allowAny=false}} @options={{hash allowAny=false}}
@ -53,7 +53,7 @@
<TagChooser <TagChooser
@tags={{this.model.watching_first_post_tags}} @tags={{this.model.watching_first_post_tags}}
@blacklist={{this.selectedTags}} @blockedTags={{this.selectedTags}}
@everyTag={{true}} @everyTag={{true}}
@unlimitedTagCount={{true}} @unlimitedTagCount={{true}}
@options={{hash allowAny=false}} @options={{hash allowAny=false}}
@ -70,7 +70,7 @@
<TagChooser <TagChooser
@tags={{this.model.regular_tags}} @tags={{this.model.regular_tags}}
@blacklist={{this.selectedTags}} @blockedTags={{this.selectedTags}}
@everyTag={{true}} @everyTag={{true}}
@unlimitedTagCount={{true}} @unlimitedTagCount={{true}}
@options={{hash allowAny=false}} @options={{hash allowAny=false}}
@ -87,7 +87,7 @@
<TagChooser <TagChooser
@tags={{this.model.muted_tags}} @tags={{this.model.muted_tags}}
@blacklist={{this.selectedTags}} @blockedTags={{this.selectedTags}}
@everyTag={{true}} @everyTag={{true}}
@unlimitedTagCount={{true}} @unlimitedTagCount={{true}}
@options={{hash allowAny=false}} @options={{hash allowAny=false}}

View File

@ -34,9 +34,14 @@ class GroupTagNotificationDefault < ActiveRecord::Base
changed = true changed = true
end end
(tag_ids - old_ids).each do |id| new_records_attrs =
self.create!(group: group, tag_id: id, notification_level: notification_levels[level]) (tag_ids - old_ids).map do |tag_id|
changed = true { group_id: group.id, tag_id: tag_id, notification_level: notification_levels[level] }
end
unless new_records_attrs.empty?
result = GroupTagNotificationDefault.insert_all(new_records_attrs)
changed = true if result.rows.length > 0
end end
changed changed

View File

@ -1380,6 +1380,24 @@ RSpec.describe Group do
expect(GroupTagNotificationDefault.lookup(group, :watching)).to be_empty expect(GroupTagNotificationDefault.lookup(group, :watching)).to be_empty
end end
it "can change the notification level for a tag" do
GroupTagNotificationDefault.create!(
group: group,
tag: tag1,
notification_level: GroupTagNotificationDefault.notification_levels[:watching],
)
group.watching_tags = [tag1.name]
group.save!
expect(GroupTagNotificationDefault.lookup(group, :watching).pluck(:tag_id)).to eq([tag1.id])
group.watching_tags = []
group.tracking_tags = [tag1.name]
group.save!
expect(GroupTagNotificationDefault.lookup(group, :watching)).to be_empty
expect(GroupTagNotificationDefault.lookup(group, :tracking).pluck(:tag_id)).to eq([tag1.id])
end
it "can apply default notifications for admins group" do it "can apply default notifications for admins group" do
group = Group.find(Group::AUTO_GROUPS[:admins]) group = Group.find(Group::AUTO_GROUPS[:admins])
group.tracking_category_ids = [category1.id] group.tracking_category_ids = [category1.id]