Commit 59c3968c authored by James Lopez's avatar James Lopez

use update service on ldap call and updated specs and service

parent cf628631
...@@ -7,16 +7,32 @@ module Users ...@@ -7,16 +7,32 @@ module Users
@params = params.dup @params = params.dup
end end
def execute(skip_authorization: false) def execute(skip_authorization: false, &block)
raise Gitlab::Access::AccessDeniedError unless skip_authorization || can_update_user? assign_attributes(skip_authorization, &block)
if @user.update_attributes(params) if @user.save
success success
else else
error('Project could not be updated') error('User could not be updated')
end end
end end
def execute!(skip_authorization: false, &block)
assign_attributes(skip_authorization, &block)
@user.save!
end
private
def assign_attributes(skip_authorization, &block)
raise Gitlab::Access::AccessDeniedError unless skip_authorization || can_update_user?
yield(@user) if block_given?
@user.assign_attributes(params) if params.any?
end
def can_update_user? def can_update_user?
current_user == @user || current_user&.admin? current_user == @user || current_user&.admin?
end end
......
...@@ -32,7 +32,7 @@ module Gitlab ...@@ -32,7 +32,7 @@ module Gitlab
block_after_save = needs_blocking? block_after_save = needs_blocking?
gl_user.save! Users::UpdateService.new(gl_user, gl_user).execute!
gl_user.block if block_after_save gl_user.block if block_after_save
......
...@@ -1900,7 +1900,6 @@ describe User, models: true do ...@@ -1900,7 +1900,6 @@ describe User, models: true do
end end
end end
describe 'audit changes' do describe 'audit changes' do
let!(:user) { create(:user) } let!(:user) { create(:user) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment