mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 01:16:38 -06:00
FIX: remove parent tag from tag group
Having a tag be a member of a tag group and the group's parent tag at the same time causes some unexpected behavior. When a tag is assigned as the parent, remove it from the group.
This commit is contained in:
parent
ad2ec5b65e
commit
7c27f9bba9
@ -13,6 +13,7 @@ class TagGroup < ActiveRecord::Base
|
||||
|
||||
before_create :init_permissions
|
||||
before_save :apply_permissions
|
||||
before_save :remove_parent_from_group
|
||||
|
||||
after_commit { DiscourseTagging.clear_cache! }
|
||||
|
||||
@ -73,6 +74,10 @@ class TagGroup < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def remove_parent_from_group
|
||||
tags.delete(parent_tag) if tags.include?(parent_tag)
|
||||
end
|
||||
|
||||
def self.visible(guardian)
|
||||
if guardian.is_staff?
|
||||
TagGroup
|
||||
|
@ -101,6 +101,22 @@ describe TagGroup do
|
||||
expect_same_tag_names(tag_group.reload.tags, [tag, 'new-tag'])
|
||||
end
|
||||
|
||||
it "removes parent tag as group member" do
|
||||
parent = Fabricate(:tag)
|
||||
tag_group.tags = [tag, parent]
|
||||
tag_group.update!(parent_tag: parent)
|
||||
tag_group.reload
|
||||
expect_same_tag_names(tag_group.tags, [tag])
|
||||
expect_same_tag_names([tag_group.parent_tag], [parent])
|
||||
end
|
||||
|
||||
it "removes parent tag as group member when creating the group" do
|
||||
parent = Fabricate(:tag)
|
||||
tg = Fabricate(:tag_group, tags: [tag, parent], parent_tag: parent)
|
||||
expect_same_tag_names(tg.tags, [tag])
|
||||
expect_same_tag_names([tg.parent_tag], [parent])
|
||||
end
|
||||
|
||||
context 'with synonyms' do
|
||||
fab!(:synonym) { Fabricate(:tag, name: 'synonym', target_tag: tag) }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user