[noosfero/noosfero][next] Add is_admin? method to check if a user is a community or enterprise adminsitrator
Leandro Nunes
gitlab at gitlab.com
Thu Apr 9 17:40:03 BRT 2015
Leandro Nunes pushed to next at Noosfero / noosfero
Commits:
fbb18e91 by Leandro Nunes dos Santos at 2015-04-09T17:40:15Z
Add is_admin? method to check if a user is a community or enterprise adminsitrator
- - - - -
4 changed files:
- app/models/organization.rb
- test/unit/community_test.rb
- test/unit/enterprise_test.rb
- test/unit/organization_test.rb
Changes:
=====================================
app/models/organization.rb
=====================================
--- 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
=====================================
test/unit/community_test.rb
=====================================
--- 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
=====================================
test/unit/enterprise_test.rb
=====================================
--- 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
=====================================
test/unit/organization_test.rb
=====================================
--- 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
View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/fbb18e91844763fce1f2107ad1eb76d253bbb4d5
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150409/7996fa7d/attachment-0001.html>
More information about the Noosfero-dev
mailing list