diff options
Diffstat (limited to 'app/services/users')
-rw-r--r-- | app/services/users/update_service.rb | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/app/services/users/update_service.rb b/app/services/users/update_service.rb index ac20473b6eb..866eb070913 100644 --- a/app/services/users/update_service.rb +++ b/app/services/users/update_service.rb @@ -7,16 +7,32 @@ module Users @params = params.dup end - def execute(skip_authorization: false) - raise Gitlab::Access::AccessDeniedError unless skip_authorization || can_update_user? + def execute(skip_authorization: false, &block) + assign_attributes(skip_authorization, &block) - if @user.update_attributes(params) + if @user.save success else - error('Project could not be updated') + error('User could not be updated') 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? current_user == @user || current_user&.admin? end |