Commit f60eb604 authored by Patricio Cano's avatar Patricio Cano

Added ability to update or set the identity of an existing user, like the...

Added ability to update or set the identity of an existing user, like the documentation said it was possible, but actually wasn't.
parent e0a23791
......@@ -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
......
......@@ -7,6 +7,7 @@ describe API::API, api: true do
let(:admin) { create(:admin) }
let(:key) { create(:key, user: user) }
let(:email) { create(:email, user: user) }
let(:omniauth_user) { create(:omniauth_user) }
describe "GET /users" do
context "when unauthenticated" do
......@@ -230,6 +231,19 @@ describe API::API, api: true do
expect(user.reload.username).to eq(user.username)
end
it "should update user's existing identity" do
put api("/users/#{omniauth_user.id}", admin), provider: 'ldapmain', extern_uid: '654321'
expect(response.status).to eq(200)
expect(omniauth_user.reload.identities.first.extern_uid).to eq('654321')
end
it 'should update user with new identity' do
put api("/users/#{user.id}", admin), provider: 'github', extern_uid: '67890'
expect(response.status).to eq(200)
expect(user.reload.identities.first.extern_uid).to eq('67890')
expect(user.reload.identities.first.provider).to eq('github')
end
it "should update admin status" do
put api("/users/#{user.id}", admin), { admin: true }
expect(response.status).to eq(200)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment