diff --git a/app/models/organization.rb b/app/models/organization.rb index a23340f..054c0ad 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -181,4 +181,9 @@ class Organization < Profile def allow_invitation_from?(person) (followed_by?(person) && self.allow_members_to_invite) || person.has_permission?('invite-members', self) end + + def is_admin?(user) + self.admins.where(:id => user.id).exists? + end + end diff --git a/test/unit/community_test.rb b/test/unit/community_test.rb index 8d96ce4..c5b10bd 100644 --- a/test/unit/community_test.rb +++ b/test/unit/community_test.rb @@ -393,4 +393,30 @@ class CommunityTest < ActiveSupport::TestCase assert_not_includes community.activities.map { |a| a.klass.constantize.find(a.id) }, article.activity end + + should 'check if a community admin user is really a community admin' do + c = fast_create(Community, :name => 'my test profile', :identifier => 'mytestprofile') + admin = create_user('adminuser').person + c.add_admin(admin) + + assert c.is_admin?(admin) + end + + should 'a member user not be a community admin' do + c = fast_create(Community, :name => 'my test profile', :identifier => 'mytestprofile') + admin = create_user('adminuser').person + c.add_admin(admin) + + member = create_user('memberuser').person + c.add_member(member) + assert !c.is_admin?(member) + end + + should 'a moderator user not be a community admin' do + c = fast_create(Community, :name => 'my test profile', :identifier => 'mytestprofile') + moderator = create_user('moderatoruser').person + c.add_moderator(moderator) + assert !c.is_admin?(moderator) + end + end diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb index 925e3bf..6e9d6fc 100644 --- a/test/unit/enterprise_test.rb +++ b/test/unit/enterprise_test.rb @@ -499,5 +499,30 @@ class EnterpriseTest < ActiveSupport::TestCase assert_equal({:profile => enterprise.identifier, :controller => 'catalog'}, enterprise.catalog_url) end + should 'check if a community admin user is really a community admin' do + c = fast_create(Enterprise, :name => 'my test profile', :identifier => 'mytestprofile') + admin = create_user('adminuser').person + c.add_admin(admin) + + assert c.is_admin?(admin) + end + + should 'a member user not be a community admin' do + c = fast_create(Enterprise, :name => 'my test profile', :identifier => 'mytestprofile') + admin = create_user('adminuser').person + c.add_admin(admin) + + member = create_user('memberuser').person + c.add_member(member) + assert !c.is_admin?(member) + end + + should 'a moderator user not be a community admin' do + c = fast_create(Enterprise, :name => 'my test profile', :identifier => 'mytestprofile') + moderator = create_user('moderatoruser').person + c.add_moderator(moderator) + assert !c.is_admin?(moderator) + end + end diff --git a/test/unit/organization_test.rb b/test/unit/organization_test.rb index 0ce13ca..5aab807 100644 --- a/test/unit/organization_test.rb +++ b/test/unit/organization_test.rb @@ -452,4 +452,29 @@ class OrganizationTest < ActiveSupport::TestCase end end + should 'check if a community admin user is really a community admin' do + c = fast_create(Organization, :name => 'my test profile', :identifier => 'mytestprofile') + admin = create_user('adminuser').person + c.add_admin(admin) + + assert c.is_admin?(admin) + end + + should 'a member user not be a community admin' do + c = fast_create(Organization, :name => 'my test profile', :identifier => 'mytestprofile') + admin = create_user('adminuser').person + c.add_admin(admin) + + member = create_user('memberuser').person + c.add_member(member) + assert !c.is_admin?(member) + end + + should 'a moderator user not be a community admin' do + c = fast_create(Organization, :name => 'my test profile', :identifier => 'mytestprofile') + moderator = create_user('moderatoruser').person + c.add_moderator(moderator) + assert !c.is_admin?(moderator) + end + end -- libgit2 0.21.2