diff --git a/app/models/tag_user.rb b/app/models/tag_user.rb index ecb781673da..b1e62ca7792 100644 --- a/app/models/tag_user.rb +++ b/app/models/tag_user.rb @@ -11,7 +11,7 @@ class TagUser < ActiveRecord::Base .joins("LEFT OUTER JOIN tag_group_permissions ON tag_group_memberships.tag_group_id = tag_group_permissions.tag_group_id") .joins("LEFT OUTER JOIN group_users on group_users.user_id = tag_users.user_id") .where("(tag_group_permissions.group_id IS NULL - OR tag_group_permissions.group_id = group_users.group_id + OR tag_group_permissions.group_id IN (0, group_users.group_id) OR group_users.group_id = :staff_group_id) AND tag_users.notification_level IN (:notification_levels)", staff_group_id: Group::AUTO_GROUPS[:staff], diff --git a/spec/models/tag_user_spec.rb b/spec/models/tag_user_spec.rb index 5fa07068278..0b6c67dd5b2 100644 --- a/spec/models/tag_user_spec.rb +++ b/spec/models/tag_user_spec.rb @@ -40,12 +40,10 @@ describe TagUser do it "scopes to notification levels visible by tag group permission" do group1 = Fabricate(:group) - tag_group1 = Fabricate(:tag_group, tags: [tag1]) - Fabricate(:tag_group_permission, tag_group: tag_group1, group: group1) + tag_group1 = Fabricate(:tag_group, tags: [tag1], permissions: { group1.name => 1 }) group2 = Fabricate(:group) - tag_group2 = Fabricate(:tag_group, tags: [tag2]) - Fabricate(:tag_group_permission, tag_group: tag_group2, group: group2) + tag_group2 = Fabricate(:tag_group, tags: [tag2], permissions: { group2.name => 1 }) Fabricate(:group_user, group: group1, user: user1) @@ -56,8 +54,7 @@ describe TagUser do it "scopes to notification levels visible because user is staff" do group2 = Fabricate(:group) - tag_group2 = Fabricate(:tag_group, tags: [tag2]) - Fabricate(:tag_group_permission, tag_group: tag_group2, group: group2) + tag_group2 = Fabricate(:tag_group, tags: [tag2], permissions: { group2.name => 1 }) staff_group = Group.find(Group::AUTO_GROUPS[:staff]) Fabricate(:group_user, group: staff_group, user: user1) @@ -330,8 +327,7 @@ describe TagUser do it "does not show a tag is tracked if the user does not belong to the tag group with permissions" do group = Fabricate(:group) - tag_group = Fabricate(:tag_group, tags: [tag2]) - Fabricate(:tag_group_permission, tag_group: tag_group, group: group) + tag_group = Fabricate(:tag_group, tags: [tag2], permissions: { group.name => 1 }) expect(TagUser.notification_levels_for(user).keys).to match_array([tag1.name, tag3.name, tag4.name]) end diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index e8e877528bc..8027d38520c 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -1972,6 +1972,7 @@ describe UsersController do } expect(response.status).to eq(200) + expect(response.parsed_body['user']['watched_tags'].count).to eq(2) user.reload @@ -2000,6 +2001,22 @@ describe UsersController do expect(user.card_background_upload).to eq(upload) end + it 'updates watched tags in everyone tag group' do + SiteSetting.tagging_enabled = true + tags = [Fabricate(:tag), Fabricate(:tag)] + group = Fabricate(:group, name: 'group', mentionable_level: Group::ALIAS_LEVELS[:everyone]) + tag_group = Fabricate(:tag_group, tags: tags) + Fabricate(:tag_group_permission, tag_group: tag_group, group: group) + tag_synonym = Fabricate(:tag, target_tag: tags[1]) + + put "/u/#{user.username}.json", params: { + watched_tags: "#{tags[0].name},#{tag_synonym.name}" + } + + expect(response.status).to eq(200) + expect(response.parsed_body['user']['watched_tags'].count).to eq(2) + end + context 'a locale is chosen that differs from I18n.locale' do before do SiteSetting.allow_user_locale = true diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rb index a33cb0df9e0..9fe7c166fa6 100644 --- a/spec/services/post_alerter_spec.rb +++ b/spec/services/post_alerter_spec.rb @@ -1429,8 +1429,7 @@ describe PostAlerter do end it "does not notify a user watching a tag with tag group permissions that he does not belong to" do - tag_group = Fabricate(:tag_group, tags: [tag]) - Fabricate(:tag_group_permission, tag_group: tag_group, group: group) + tag_group = Fabricate(:tag_group, tags: [tag], permissions: { group.name => 1 }) TagUser.change(user.id, tag.id, TagUser.notification_levels[notification_level])