summaryrefslogtreecommitdiff
path: root/app/services/users/update_service.rb
blob: ac20473b6eb34ff5317bec6c14ce061b95b61b56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
module Users
  # Service for creating a new user.
  class UpdateService < BaseService
    def initialize(current_user, user, params = {})
      @current_user = current_user
      @user = user
      @params = params.dup
    end

    def execute(skip_authorization: false)
      raise Gitlab::Access::AccessDeniedError unless skip_authorization || can_update_user?

      if @user.update_attributes(params)
        success
      else
        error('Project could not be updated')
      end
    end

    def can_update_user?
      current_user == @user || current_user&.admin?
    end
  end
end