FIX: Only serialize group membership domains for administrators (#6771)

This commit is contained in:
David Taylor 2018-12-14 15:47:00 +00:00 committed by GitHub
parent a19f69590a
commit 9f3e2a9e34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -42,6 +42,14 @@ class BasicGroupSerializer < ApplicationSerializer
staff?
end
def include_automatic_membership_email_domains?
scope.is_admin?
end
def include_automatic_membership_retroactive?
scope.is_admin?
end
def include_has_messages?
staff? || scope.can_see_group_messages?(object)
end

View File

@ -43,6 +43,24 @@ describe BasicGroupSerializer do
end
end
describe '#automatic_membership_email_domains' do
let(:group) { Fabricate(:group, automatic_membership_email_domains: 'ilovediscourse.com', automatic_membership_retroactive: true) }
let(:admin_guardian) { Guardian.new(Fabricate(:admin)) }
it 'should include email domains for admin' do
subject = described_class.new(group, scope: admin_guardian, root: false, owner_group_ids: [group.id])
expect(subject.as_json[:automatic_membership_email_domains]).to eq('ilovediscourse.com')
expect(subject.as_json[:automatic_membership_retroactive]).to eq(true)
end
it 'should not include email domains for other users' do
subject = described_class.new(group, scope: guardian, root: false, owner_group_ids: [group.id])
expect(subject.as_json[:automatic_membership_email_domains]).to eq(nil)
expect(subject.as_json[:automatic_membership_retroactive]).to eq(nil)
end
end
describe '#has_messages' do
let(:group) { Fabricate(:group, has_messages: true) }