Commit fbb18e91844763fce1f2107ad1eb76d253bbb4d5
1 parent
82193169
Exists in
master
and in
26 other branches
Add is_admin? method to check if a user is a community or enterprise adminsitrator
Showing
4 changed files
with
81 additions
and
0 deletions
Show diff stats
app/models/organization.rb
@@ -181,4 +181,9 @@ class Organization < Profile | @@ -181,4 +181,9 @@ class Organization < Profile | ||
181 | def allow_invitation_from?(person) | 181 | def allow_invitation_from?(person) |
182 | (followed_by?(person) && self.allow_members_to_invite) || person.has_permission?('invite-members', self) | 182 | (followed_by?(person) && self.allow_members_to_invite) || person.has_permission?('invite-members', self) |
183 | end | 183 | end |
184 | + | ||
185 | + def is_admin?(user) | ||
186 | + self.admins.where(:id => user.id).exists? | ||
187 | + end | ||
188 | + | ||
184 | end | 189 | end |
test/unit/community_test.rb
@@ -393,4 +393,30 @@ class CommunityTest < ActiveSupport::TestCase | @@ -393,4 +393,30 @@ class CommunityTest < ActiveSupport::TestCase | ||
393 | assert_not_includes community.activities.map { |a| a.klass.constantize.find(a.id) }, article.activity | 393 | assert_not_includes community.activities.map { |a| a.klass.constantize.find(a.id) }, article.activity |
394 | end | 394 | end |
395 | 395 | ||
396 | + | ||
397 | + should 'check if a community admin user is really a community admin' do | ||
398 | + c = fast_create(Community, :name => 'my test profile', :identifier => 'mytestprofile') | ||
399 | + admin = create_user('adminuser').person | ||
400 | + c.add_admin(admin) | ||
401 | + | ||
402 | + assert c.is_admin?(admin) | ||
403 | + end | ||
404 | + | ||
405 | + should 'a member user not be a community admin' do | ||
406 | + c = fast_create(Community, :name => 'my test profile', :identifier => 'mytestprofile') | ||
407 | + admin = create_user('adminuser').person | ||
408 | + c.add_admin(admin) | ||
409 | + | ||
410 | + member = create_user('memberuser').person | ||
411 | + c.add_member(member) | ||
412 | + assert !c.is_admin?(member) | ||
413 | + end | ||
414 | + | ||
415 | + should 'a moderator user not be a community admin' do | ||
416 | + c = fast_create(Community, :name => 'my test profile', :identifier => 'mytestprofile') | ||
417 | + moderator = create_user('moderatoruser').person | ||
418 | + c.add_moderator(moderator) | ||
419 | + assert !c.is_admin?(moderator) | ||
420 | + end | ||
421 | + | ||
396 | end | 422 | end |
test/unit/enterprise_test.rb
@@ -499,5 +499,30 @@ class EnterpriseTest < ActiveSupport::TestCase | @@ -499,5 +499,30 @@ class EnterpriseTest < ActiveSupport::TestCase | ||
499 | assert_equal({:profile => enterprise.identifier, :controller => 'catalog'}, enterprise.catalog_url) | 499 | assert_equal({:profile => enterprise.identifier, :controller => 'catalog'}, enterprise.catalog_url) |
500 | end | 500 | end |
501 | 501 | ||
502 | + should 'check if a community admin user is really a community admin' do | ||
503 | + c = fast_create(Enterprise, :name => 'my test profile', :identifier => 'mytestprofile') | ||
504 | + admin = create_user('adminuser').person | ||
505 | + c.add_admin(admin) | ||
506 | + | ||
507 | + assert c.is_admin?(admin) | ||
508 | + end | ||
509 | + | ||
510 | + should 'a member user not be a community admin' do | ||
511 | + c = fast_create(Enterprise, :name => 'my test profile', :identifier => 'mytestprofile') | ||
512 | + admin = create_user('adminuser').person | ||
513 | + c.add_admin(admin) | ||
514 | + | ||
515 | + member = create_user('memberuser').person | ||
516 | + c.add_member(member) | ||
517 | + assert !c.is_admin?(member) | ||
518 | + end | ||
519 | + | ||
520 | + should 'a moderator user not be a community admin' do | ||
521 | + c = fast_create(Enterprise, :name => 'my test profile', :identifier => 'mytestprofile') | ||
522 | + moderator = create_user('moderatoruser').person | ||
523 | + c.add_moderator(moderator) | ||
524 | + assert !c.is_admin?(moderator) | ||
525 | + end | ||
526 | + | ||
502 | 527 | ||
503 | end | 528 | end |
test/unit/organization_test.rb
@@ -452,4 +452,29 @@ class OrganizationTest < ActiveSupport::TestCase | @@ -452,4 +452,29 @@ class OrganizationTest < ActiveSupport::TestCase | ||
452 | end | 452 | end |
453 | end | 453 | end |
454 | 454 | ||
455 | + should 'check if a community admin user is really a community admin' do | ||
456 | + c = fast_create(Organization, :name => 'my test profile', :identifier => 'mytestprofile') | ||
457 | + admin = create_user('adminuser').person | ||
458 | + c.add_admin(admin) | ||
459 | + | ||
460 | + assert c.is_admin?(admin) | ||
461 | + end | ||
462 | + | ||
463 | + should 'a member user not be a community admin' do | ||
464 | + c = fast_create(Organization, :name => 'my test profile', :identifier => 'mytestprofile') | ||
465 | + admin = create_user('adminuser').person | ||
466 | + c.add_admin(admin) | ||
467 | + | ||
468 | + member = create_user('memberuser').person | ||
469 | + c.add_member(member) | ||
470 | + assert !c.is_admin?(member) | ||
471 | + end | ||
472 | + | ||
473 | + should 'a moderator user not be a community admin' do | ||
474 | + c = fast_create(Organization, :name => 'my test profile', :identifier => 'mytestprofile') | ||
475 | + moderator = create_user('moderatoruser').person | ||
476 | + c.add_moderator(moderator) | ||
477 | + assert !c.is_admin?(moderator) | ||
478 | + end | ||
479 | + | ||
455 | end | 480 | end |