Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
077d5a30
Commit
077d5a30
authored
Mar 26, 2019
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor code based on feedback
parent
27a3ca0b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
64 additions
and
20 deletions
+64
-20
ee/lib/api/scim.rb
ee/lib/api/scim.rb
+1
-1
ee/lib/ee/gitlab/scim/error.rb
ee/lib/ee/gitlab/scim/error.rb
+13
-1
ee/lib/ee/gitlab/scim/not_found.rb
ee/lib/ee/gitlab/scim/not_found.rb
+1
-13
ee/lib/ee/gitlab/scim/params_parser.rb
ee/lib/ee/gitlab/scim/params_parser.rb
+4
-4
ee/lib/ee/gitlab/scim/users.rb
ee/lib/ee/gitlab/scim/users.rb
+1
-1
ee/spec/requests/api/scim_spec.rb
ee/spec/requests/api/scim_spec.rb
+44
-0
No files found.
ee/lib/api/scim.rb
View file @
077d5a30
...
...
@@ -61,7 +61,7 @@ module API
scim_error!
(
message:
'Email has already been taken'
)
if
email_taken?
(
parsed_hash
[
:email
],
identity
)
result
=
::
Users
::
UpdateService
.
new
(
identity
.
user
,
parsed_hash
.
except
(
:extern_uid
,
:provider
)
parsed_hash
.
except
(
:extern_uid
)
.
merge
(
user:
identity
.
user
)).
execute
result
[
:status
]
==
:success
...
...
ee/lib/ee/gitlab/scim/error.rb
View file @
077d5a30
...
...
@@ -3,7 +3,19 @@
module
EE
module
Gitlab
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
409
end
...
...
ee/lib/ee/gitlab/scim/not_found.rb
View file @
077d5a30
...
...
@@ -3,19 +3,7 @@
module
EE
module
Gitlab
module
Scim
class
NotFound
<
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
class
NotFound
<
EE
::
Gitlab
::
Scim
::
Error
def
status
404
end
...
...
ee/lib/ee/gitlab/scim/params_parser.rb
View file @
077d5a30
...
...
@@ -25,11 +25,11 @@ module EE
end
def
deprovision_user?
hash
[
:active
]
==
false
data
[
:active
]
==
false
end
def
to_hash
@
hash
||=
@
data
||=
begin
hash
=
{}
...
...
@@ -40,8 +40,8 @@ module EE
end
end
alias_method
:
hash
,
:to_hash
private
:
hash
alias_method
:
data
,
:to_hash
private
:
data
private
...
...
ee/lib/ee/gitlab/scim/users.rb
View file @
077d5a30
...
...
@@ -35,7 +35,7 @@ module EE
# We only support a single resource at the moment
def
resources
object
.
present?
?
[
object
]
:
[]
[
object
].
reject
(
&
:empty?
)
end
end
end
...
...
ee/spec/requests/api/scim_spec.rb
View file @
077d5a30
...
...
@@ -105,6 +105,46 @@ describe API::Scim do
it
'updates the name'
do
expect
(
user
.
reload
.
name
).
to
eq
(
'new_name'
)
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
context
'Remove user'
do
...
...
@@ -138,6 +178,10 @@ describe API::Scim do
it
'removes the identity link'
do
expect
{
identity
.
reload
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
end
it
'responds with an empty response'
do
expect
(
json_response
).
to
eq
({})
end
end
it
'responds with 404 if there is no user'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment