FIX: scope memoization of category moderation per category (#17786)

This commit is contained in:
Sam 2022-08-04 08:43:19 +10:00 committed by GitHub
parent 8ab6b17c36
commit ff53f2c7bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -112,8 +112,8 @@ class Guardian
def is_category_group_moderator?(category)
return false unless category
return false unless authenticated?
@is_category_group_moderator ||= begin
@is_category_group_moderator ||= {}
@is_category_group_moderator[category.id] ||= begin
SiteSetting.enable_category_group_moderation? &&
category.present? &&
category.reviewable_by_group_id.present? &&

View File

@ -3953,4 +3953,21 @@ RSpec.describe Guardian do
expect(admin.guardian.can_mention_here?).to eq(true)
end
end
describe "#is_category_group_moderator" do
before do
SiteSetting.enable_category_group_moderation = true
end
fab!(:category) { Fabricate(:category) }
it "should correctly detect category moderation" do
group.add(user)
category.reviewable_by_group_id = group.id
guardian = Guardian.new(user)
expect(guardian.is_category_group_moderator?(category)).to eq(true)
expect(guardian.is_category_group_moderator?(plain_category)).to eq(false)
end
end
end