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
ac4f3c52
Commit
ac4f3c52
authored
Feb 21, 2019
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add params parser and spec
parent
a09e572b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
0 deletions
+68
-0
ee/lib/ee/gitlab/scim/params_parser.rb
ee/lib/ee/gitlab/scim/params_parser.rb
+55
-0
ee/spec/lib/gitlab/scim/params_parser_spec.rb
ee/spec/lib/gitlab/scim/params_parser_spec.rb
+13
-0
No files found.
ee/lib/ee/gitlab/scim/params_parser.rb
0 → 100644
View file @
ac4f3c52
# frozen_string_literal: true
module
EE
module
Gitlab
module
Scim
class
ParamsParser
FILTER_OPERATORS
=
%w[eq]
OPERATIONS_OPERATORS
=
%w[Replace Add]
ATTRIBUTE_MAP
=
{
id: :extern_uid
,
'name.formatted'
:
:name
,
'emails[type eq "work".value'
:
:mail
}.
with_indifferent_access
def
initialize
(
params
)
@filter
=
params
[
:filter
]
@operations
=
params
[
:operations
]
@hash
=
{}
end
def
to_hash
process_filter
process_operations
@hash
end
private
def
process_filter
return
unless
@filter
attribute
,
operator
,
value
=
@filter
.
split
return
unless
FILTER_OPERATORS
.
include?
(
operator
)
return
unless
ATTRIBUTE_MAP
[
attribute
]
@hash
[
ATTRIBUTE_MAP
[
attribute
]]
=
value
.
tr
(
'\"'
,
''
)
end
def
process_operations
return
unless
@operations
@operations
.
each
do
|
operation
|
next
unless
OPERATIONS_OPERATORS
.
contains?
(
operation
[
:op
])
attribute
=
ATTRIBUTE_MAP
[
operation
[
:path
]]
@hash
[
attribute
]
=
operation
[
:value
]
if
attribute
end
end
end
end
end
end
ee/spec/lib/gitlab/scim/params_parser_spec.rb
0 → 100644
View file @
ac4f3c52
# frozen_string_literal: true
require
'spec_helper'
describe
EE
::
Gitlab
::
Scim
::
ParamsParser
do
describe
'#to_hash'
do
it
'returns the correct filter attributes'
do
filter
=
'id eq "6ba81b08-77da"'
expect
(
described_class
.
new
(
filter:
filter
).
to_hash
).
to
eq
(
extern_uid:
'6ba81b08-77da'
)
end
end
end
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