Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2017-06-23 12:34:07 +0300
committerJames Lopez <james@jameslopez.es>2017-06-23 12:41:43 +0300
commitb804db26485ea09dc93269898dc969ed692130a2 (patch)
tree48ac76727eed23a2815b14e8c5633bbb056f6972 /app/services/users
parente2e0b175ae43bef44ba5fdc45b4a719aaae83422 (diff)
refactor update user service not to do auth checks
Diffstat (limited to 'app/services/users')
-rw-r--r--app/services/users/update_service.rb17
1 files changed, 5 insertions, 12 deletions
diff --git a/app/services/users/update_service.rb b/app/services/users/update_service.rb
index 36dcc69f8cf..2037664f56a 100644
--- a/app/services/users/update_service.rb
+++ b/app/services/users/update_service.rb
@@ -1,14 +1,13 @@
module Users
# Service for updating a user.
class UpdateService < BaseService
- def initialize(current_user, user, params = {})
- @current_user = current_user
+ def initialize(user, params = {})
@user = user
@params = params.dup
end
- def execute(skip_authorization: false, validate: true, &block)
- assign_attributes(skip_authorization, &block)
+ def execute(validate: true, &block)
+ assign_attributes(&block)
if @user.save(validate: validate)
success
@@ -20,23 +19,17 @@ module Users
def execute!(*args, &block)
result = execute(*args, &block)
- raise ActiveRecord::RecordInvalid(result[:message]) unless result[:status] == :success
+ raise ActiveRecord::RecordInvalid.new(@user) unless result[:status] == :success
true
end
private
- def assign_attributes(skip_authorization, &block)
- raise Gitlab::Access::AccessDeniedError unless skip_authorization || can_update_user?
-
+ def assign_attributes(&block)
yield(@user) if block_given?
@user.assign_attributes(params) if params.any?
end
-
- def can_update_user?
- current_user == @user || current_user&.admin?
- end
end
end