summaryrefslogtreecommitdiff
path: root/app/services/users
diff options
context:
space:
mode:
authorMichael Leopard <mleopard@gitlab.com>2019-06-19 20:27:34 +0000
committerStan Hu <stanhu@gmail.com>2019-06-19 20:27:34 +0000
commit8cf85b4bb50d0b116cb50699831f3ec049ae4ad4 (patch)
tree9dc2a9627e70860ed4ffd8ec938f58d4c48ad15f /app/services/users
parent4a5bda06900b2b623f7f9fcdce6b36cdcf73bc51 (diff)
downloadgitlab-ce-8cf85b4bb50d0b116cb50699831f3ec049ae4ad4.tar.gz
Updating CE repo to include new EE users API changes
Updated users API documentation Moved API level changes to the service level
Diffstat (limited to 'app/services/users')
-rw-r--r--app/services/users/build_service.rb10
-rw-r--r--app/services/users/update_service.rb17
2 files changed, 20 insertions, 7 deletions
diff --git a/app/services/users/build_service.rb b/app/services/users/build_service.rb
index 30f7743c56e..026bcfcdaf4 100644
--- a/app/services/users/build_service.rb
+++ b/app/services/users/build_service.rb
@@ -5,10 +5,12 @@ module Users
delegate :user_default_internal_regex_enabled?,
:user_default_internal_regex_instance,
to: :'Gitlab::CurrentSettings.current_application_settings'
+ attr_reader :identity_params
def initialize(current_user, params = {})
@current_user = current_user
@params = params.dup
+ @identity_params = params.slice(*identity_attributes)
end
def execute(skip_authorization: false)
@@ -26,10 +28,8 @@ module Users
end
end
- identity_attrs = params.slice(*identity_params)
-
- unless identity_attrs.empty?
- user.identities.build(identity_attrs)
+ unless identity_params.empty?
+ user.identities.build(identity_params)
end
user
@@ -37,7 +37,7 @@ module Users
private
- def identity_params
+ def identity_attributes
[:extern_uid, :provider]
end
diff --git a/app/services/users/update_service.rb b/app/services/users/update_service.rb
index 0b00bd135eb..15c13a452ad 100644
--- a/app/services/users/update_service.rb
+++ b/app/services/users/update_service.rb
@@ -3,11 +3,13 @@
module Users
class UpdateService < BaseService
include NewUserNotifier
+ attr_reader :user, :identity_params
def initialize(current_user, params = {})
@current_user = current_user
@user = params.delete(:user)
@status_params = params.delete(:status)
+ @identity_params = params.slice(*identity_attributes)
@params = params.dup
end
@@ -15,8 +17,8 @@ module Users
yield(@user) if block_given?
user_exists = @user.persisted?
-
assign_attributes
+ assign_identity
if @user.save(validate: validate) && update_status
notify_success(user_exists)
@@ -55,7 +57,18 @@ module Users
params.reject! { |key, _| read_only.include?(key.to_sym) }
end
- @user.assign_attributes(params) unless params.empty?
+ @user.assign_attributes(params.except(*identity_attributes)) unless params.empty? # rubocop: disable CodeReuse/ActiveRecord
+ end
+
+ def assign_identity
+ return unless identity_params.present?
+
+ identity = user.identities.find_or_create_by(provider: identity_params[:provider]) # rubocop: disable CodeReuse/ActiveRecord
+ identity.update(identity_params)
+ end
+
+ def identity_attributes
+ [:provider, :extern_uid]
end
end
end