Skip to content

Commit

Permalink
Fixes #17458 - include user group admins
Browse files Browse the repository at this point in the history
  • Loading branch information
ares authored and tbrisker committed Nov 24, 2016
1 parent 4e6d226 commit a55d7b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/concerns/taxonomix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def inner_select(taxonomy, inner_method = which_ancestry_method)
end

def admin_ids
User.unscoped.where(:admin => true).pluck(:id) if self == User
User.unscoped.only_admin.pluck(:id) if self == User
end

def scope_by_taxable_ids(scope)
Expand Down
13 changes: 13 additions & 0 deletions test/models/taxonomix_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,17 @@ def setup
end
end
end

test "#admin_ids finds admins both assigned the permission directly and through user group" do
direct_admin = group_admin = nil
as_admin do
direct_admin = FactoryGirl.create(:user, :admin)
group = FactoryGirl.create(:usergroup, :admin => true)
group_admin = FactoryGirl.create(:user, :usergroups => [ group ])
end

found_admins = User.admin_ids
assert_includes found_admins, direct_admin.id
assert_includes found_admins, group_admin.id
end
end

0 comments on commit a55d7b6

Please sign in to comment.