summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-09-23 09:13:23 +0000
committerDouwe Maan <douwe@gitlab.com>2015-09-23 09:13:23 +0000
commitb4bedfdfb96b603cd3d97c19dccc32b75c1b26ab (patch)
tree26886325752f0254476944d970bb5ca77404b5ea /lib
parent03fd5919a393b8784c601c76c3ed65912f4b522a (diff)
parentf60eb60473a1dcfd2b874d5ebac6dca60da7c1ea (diff)
downloadgitlab-ce-b4bedfdfb96b603cd3d97c19dccc32b75c1b26ab.tar.gz
Merge branch 'fix-user-identities-api' into 'master'
Fix user identities API Added ability to update or set the identity of an existing user, like the documentation said it was possible, but actually wasn't. @DouweM or @stanhu could you please take a look at my code, and see if its sound? /cc @JobV See merge request !1398
Diffstat (limited to 'lib')
-rw-r--r--lib/api/users.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/api/users.rb b/lib/api/users.rb
index 813cc379e43..a98d668e02d 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -121,6 +121,17 @@ module API
User.where(username: attrs[:username]).
where.not(id: user.id).count > 0
+ identity_attrs = attributes_for_keys [:provider, :extern_uid]
+ if identity_attrs.any?
+ identity = user.identities.find_by(provider: identity_attrs[:provider])
+ if identity
+ identity.update_attributes(identity_attrs)
+ else
+ identity = user.identities.build(identity_attrs)
+ identity.save
+ end
+ end
+
if user.update_attributes(attrs)
present user, with: Entities::UserFull
else