Commit 077d5a30 authored by James Lopez's avatar James Lopez

Refactor code based on feedback

parent 27a3ca0b
...@@ -61,7 +61,7 @@ module API ...@@ -61,7 +61,7 @@ module API
scim_error!(message: 'Email has already been taken') if email_taken?(parsed_hash[:email], identity) scim_error!(message: 'Email has already been taken') if email_taken?(parsed_hash[:email], identity)
result = ::Users::UpdateService.new(identity.user, result = ::Users::UpdateService.new(identity.user,
parsed_hash.except(:extern_uid, :provider) parsed_hash.except(:extern_uid)
.merge(user: identity.user)).execute .merge(user: identity.user)).execute
result[:status] == :success result[:status] == :success
......
...@@ -3,7 +3,19 @@ ...@@ -3,7 +3,19 @@
module EE module EE
module Gitlab module Gitlab
module Scim module Scim
class Error < EE::Gitlab::Scim::NotFound class Error < Grape::Entity
expose :schemas
expose :detail, safe: true
expose :status
private
DEFAULT_SCHEMA = 'urn:ietf:params:scim:api:messages:2.0:Error'
def schemas
[DEFAULT_SCHEMA]
end
def status def status
409 409
end end
......
...@@ -3,19 +3,7 @@ ...@@ -3,19 +3,7 @@
module EE module EE
module Gitlab module Gitlab
module Scim module Scim
class NotFound < Grape::Entity class NotFound < EE::Gitlab::Scim::Error
expose :schemas
expose :detail, safe: true
expose :status
private
DEFAULT_SCHEMA = 'urn:ietf:params:scim:api:messages:2.0:Error'
def schemas
[DEFAULT_SCHEMA]
end
def status def status
404 404
end end
......
...@@ -25,11 +25,11 @@ module EE ...@@ -25,11 +25,11 @@ module EE
end end
def deprovision_user? def deprovision_user?
hash[:active] == false data[:active] == false
end end
def to_hash def to_hash
@hash ||= @data ||=
begin begin
hash = {} hash = {}
...@@ -40,8 +40,8 @@ module EE ...@@ -40,8 +40,8 @@ module EE
end end
end end
alias_method :hash, :to_hash alias_method :data, :to_hash
private :hash private :data
private private
......
...@@ -35,7 +35,7 @@ module EE ...@@ -35,7 +35,7 @@ module EE
# We only support a single resource at the moment # We only support a single resource at the moment
def resources def resources
object.present? ? [object] : [] [object].reject(&:empty?)
end end
end end
end end
......
...@@ -105,6 +105,46 @@ describe API::Scim do ...@@ -105,6 +105,46 @@ describe API::Scim do
it 'updates the name' do it 'updates the name' do
expect(user.reload.name).to eq('new_name') expect(user.reload.name).to eq('new_name')
end end
it 'responds with an empty response' do
expect(json_response).to eq({})
end
end
context 'email' do
context 'non existent email' do
before do
params = { Operations: [{ 'op': 'Replace', 'path': 'emails[type eq "work"].value', 'value': 'new@mail.com' }] }.to_query
patch scim_api("scim/v2/groups/#{group.full_path}/Users/#{identity.extern_uid}?#{params}")
end
it 'updates the email' do
expect(user.reload.unconfirmed_email).to eq('new@mail.com')
end
it 'responds with 204' do
expect(response).to have_gitlab_http_status(204)
end
end
context 'existent email' do
before do
create(:user, email: 'new@mail.com')
params = { Operations: [{ 'op': 'Replace', 'path': 'emails[type eq "work"].value', 'value': 'new@mail.com' }] }.to_query
patch scim_api("scim/v2/groups/#{group.full_path}/Users/#{identity.extern_uid}?#{params}")
end
it 'does not update a duplicated email' do
expect(user.reload.unconfirmed_email).not_to eq('new@mail.com')
end
it 'responds with 209' do
expect(response).to have_gitlab_http_status(409)
end
end
end end
context 'Remove user' do context 'Remove user' do
...@@ -138,6 +178,10 @@ describe API::Scim do ...@@ -138,6 +178,10 @@ describe API::Scim do
it 'removes the identity link' do it 'removes the identity link' do
expect { identity.reload }.to raise_error(ActiveRecord::RecordNotFound) expect { identity.reload }.to raise_error(ActiveRecord::RecordNotFound)
end end
it 'responds with an empty response' do
expect(json_response).to eq({})
end
end end
it 'responds with 404 if there is no user' do it 'responds with 404 if there is no user' do
......
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