Skip to content

Commit

Permalink
Merge pull request #5726 from yrudman/allow-deletion-custom-super_admins
Browse files Browse the repository at this point in the history
Fix: allow deletion of custom super_admin users
  • Loading branch information
mzazrivec authored Jun 20, 2019
2 parents 93f7645 + f485a75 commit 5d901af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/ops_controller/ops_rbac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ def tenant_type_title_string(divisible)
# super administrator user with `userid` == "admin" can not be deleted
# and user can not delete himself
def rbac_user_delete_restriction?(user)
user.super_admin_user? || User.current_user == user
user.admin? || User.current_user == user
end

def rbac_user_copy_restriction?(user)
Expand Down
11 changes: 8 additions & 3 deletions spec/controllers/ops_controller/ops_rbac_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -743,11 +743,16 @@
end

describe "#rbac_user_delete_restriction?" do
let(:admin_user) { FactoryBot.create(:user, :role => "super_administrator") }
let(:default_admin_user) { FactoryBot.create(:user, :userid => "admin", :role => "super_administrator") }
let(:custom_admin_user) { FactoryBot.create(:user, :userid => "somename", :role => "super_administrator") }
let(:other_user) { FactoryBot.create(:user) }

it "returns true because user is super admin" do
expect(controller.send(:rbac_user_delete_restriction?, admin_user)).to be_truthy
it "returns true because user is default super admin" do
expect(controller.send(:rbac_user_delete_restriction?, default_admin_user)).to be_truthy
end

it "returns false because user is custom super admin" do
expect(controller.send(:rbac_user_delete_restriction?, custom_admin_user)).to be_falsy
end

it "returns true because user is current user" do
Expand Down

0 comments on commit 5d901af

Please sign in to comment.