FIX: default_tags_muted setting should work for anonymous users too.

This commit is contained in:
Vinoth Kannan 2020-08-20 10:40:03 +05:30
parent 54cf3c6766
commit 89fcb75af2
2 changed files with 22 additions and 2 deletions

View File

@ -908,11 +908,18 @@ class TopicQuery
end
def remove_muted_tags(list, user, opts = nil)
if user.nil? || !SiteSetting.tagging_enabled || SiteSetting.remove_muted_tags_from_latest == 'never'
if !SiteSetting.tagging_enabled || SiteSetting.remove_muted_tags_from_latest == 'never'
return list
end
muted_tag_ids = []
if user.present?
muted_tag_ids = TagUser.lookup(user, :muted).pluck(:tag_id)
else
muted_tag_ids = SiteSetting.default_tags_muted.split("|").map(&:to_i)
end
if muted_tag_ids.blank?
return list
end

View File

@ -281,6 +281,19 @@ describe TopicQuery do
end
end
context 'remove_muted_tags' do
fab!(:topic) { Fabricate(:topic, tags: [tag]) }
before do
SiteSetting.remove_muted_tags_from_latest = 'always'
SiteSetting.default_tags_muted = tag.id.to_s
end
it 'removes default muted tag topics for anonymous users' do
expect(TopicQuery.new(nil).list_latest.topics.map(&:id)).not_to include(topic.id)
end
end
context "and categories too" do
let(:category1) { Fabricate(:category_with_definition) }
let(:category2) { Fabricate(:category_with_definition) }