Skip to content
This repository has been archived by the owner on Jan 7, 2018. It is now read-only.

Commit

Permalink
Allow limited admins to assign the "api-umbrella-key-creator" role.
Browse files Browse the repository at this point in the history
  • Loading branch information
GUI committed Dec 8, 2014
1 parent 2b88bc7 commit d8123bb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/policies/api_user_role_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ def show?
allowed = false
if(user.superuser?)
allowed = true
elsif(record == "api-umbrella-key-creator")
allowed = true
elsif(record.start_with?("api-umbrella"))
allowed = false
else
Expand Down
21 changes: 19 additions & 2 deletions spec/controllers/api/v1/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,24 @@
end.to_not change { ApiUser.count }
end

it "forbids limited admins from assigning a new role beginning with 'api-umbrella'" do
it "allows limited admins to assign the 'api-umbrella-key-creator' role" do
admin_token_auth(@google_admin)
attributes = FactoryGirl.attributes_for(:api_user, {
:roles => [
"api-umbrella-key-creator",
],
})

expect do
send(method, action, params.merge(:user => attributes))
response.status.should eql(success_response_status)
data = MultiJson.load(response.body)
user = ApiUser.find(data["user"]["id"])
user.roles.should eql(attributes[:roles])
end.to change { ApiUser.count }.by(success_record_change_count)
end

it "forbids limited admins from assigning other new roles beginning with 'api-umbrella'" do
admin_token_auth(@google_admin)
attributes = FactoryGirl.attributes_for(:api_user, {
:roles => [
Expand All @@ -179,7 +196,7 @@
end.to_not change { ApiUser.count }
end

it "allows superuser admins to assign a new role beginning with 'api-umbrella'" do
it "allows superuser admins to assign other new roles beginning with 'api-umbrella'" do
admin_token_auth(@admin)
attributes = FactoryGirl.attributes_for(:api_user, {
:roles => [
Expand Down

0 comments on commit d8123bb

Please sign in to comment.