-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug when removing sudoers rights to non-currently admin users
- Loading branch information
Showing
4 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require_dependency 'users_controller' | ||
|
||
module RedmineSudo | ||
module UsersControllerPatch | ||
extend ActiveSupport::Concern | ||
|
||
def update_sudoer | ||
if @user.present? && params[:user][:admin] == '0' | ||
@user.admin = false | ||
@user.sudoer = false | ||
end | ||
end | ||
|
||
end | ||
end | ||
|
||
class UsersController | ||
include RedmineSudo::UsersControllerPatch | ||
append_before_action :update_sudoer, :only => [:update] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
require 'spec_helper' | ||
|
||
describe UsersController, type: :controller do | ||
render_views | ||
fixtures :users | ||
|
||
let!(:user_7) { User.find(7) } | ||
|
||
before do | ||
@controller = UsersController.new | ||
@request = ActionDispatch::TestRequest.create | ||
@response = ActionDispatch::TestResponse.new | ||
User.current = nil | ||
@request.session[:user_id] = 1 # permissions admin | ||
end | ||
|
||
describe "POST update" do | ||
it "gives both sudoer and admin roles when selecting the option in user form" do | ||
user_7.update_attribute(:admin, false) | ||
expect(user_7).to_not be_admin | ||
expect(user_7).to_not be_sudoer | ||
|
||
patch :update, :params => { :id => 7, :user => { admin: '1', mail: "[email protected]" } } | ||
|
||
user_7.reload | ||
expect(user_7).to be_admin | ||
expect(user_7).to be_sudoer | ||
end | ||
|
||
it "removes both sudoer and admin roles when deselecting the option in user form" do | ||
user_7.update_attribute(:admin, true) | ||
expect(user_7).to be_admin | ||
expect(user_7).to be_sudoer | ||
|
||
patch :update, :params => { :id => 7, :user => { admin: '0', mail: "[email protected]" } } | ||
|
||
user_7.reload | ||
expect(user_7).to_not be_admin | ||
expect(user_7).to_not be_sudoer | ||
end | ||
|
||
it "removes both sudoer and admin roles even when user is not currently admin" do | ||
user_7.update(admin: false, sudoer: true) | ||
expect(user_7).to_not be_admin | ||
expect(user_7).to be_sudoer | ||
|
||
patch :update, :params => { :id => 7, :user => { admin: '0', mail: "[email protected]" } } | ||
|
||
user_7.reload | ||
expect(user_7).to_not be_admin | ||
expect(user_7).to_not be_sudoer | ||
end | ||
end | ||
|
||
end |