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
b694cfae
Commit
b694cfae
authored
Nov 24, 2020
by
Etienne Baqué
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated group member search
Added search and sort params. Updated rspec accordingly.
parent
7757f7e8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
87 additions
and
7 deletions
+87
-7
ee/lib/ee/api/helpers/members_helpers.rb
ee/lib/ee/api/helpers/members_helpers.rb
+20
-2
ee/lib/ee/api/members.rb
ee/lib/ee/api/members.rb
+3
-1
ee/spec/lib/ee/api/helpers/members_helpers_spec.rb
ee/spec/lib/ee/api/helpers/members_helpers_spec.rb
+40
-1
ee/spec/requests/api/members_spec.rb
ee/spec/requests/api/members_spec.rb
+24
-3
No files found.
ee/lib/ee/api/helpers/members_helpers.rb
View file @
b694cfae
...
...
@@ -6,6 +6,7 @@ module EE
module
MembersHelpers
extend
ActiveSupport
::
Concern
extend
::
Gitlab
::
Utils
::
Override
include
::
SortingHelper
prepended
do
params
:optional_filter_params_ee
do
...
...
@@ -76,8 +77,10 @@ module EE
).
for_member
(
member
).
security_event
end
def
paginate_billable_from_user_ids
(
user_ids
)
paginated
=
paginate
(
::
Kaminari
.
paginate_array
(
user_ids
.
sort
))
def
paginate_billable_from_user_ids
(
user_ids
,
params
=
{})
sorted_ids
=
params
[
:search
].
present?
?
user_ids
:
user_ids
.
sort
paginated
=
paginate
(
::
Kaminari
.
paginate_array
(
sorted_ids
))
users_as_hash
=
::
User
.
id_in
(
paginated
).
index_by
(
&
:id
)
...
...
@@ -85,6 +88,21 @@ module EE
# instead of creating a new non-paginatable array
paginated
.
map!
{
|
user_id
|
users_as_hash
[
user_id
]
}
end
def
group_billed_user_ids_for
(
group
,
params
)
if
params
[
:search
].
present?
sorting
=
params
[
:sort
]
||
sort_value_name
::
GroupMember
.
with_user
(
group
.
billed_user_ids
)
.
search
(
params
[
:search
])
.
sort_by_attribute
(
sorting
)
.
map
(
&
:user_id
)
.
uniq
else
group
.
billed_user_ids
end
end
end
end
end
...
...
ee/lib/ee/api/members.rb
View file @
b694cfae
...
...
@@ -47,6 +47,8 @@ module EE
end
params
do
use
:pagination
optional
:search
,
type:
String
,
desc:
'The name of the subscribed member'
optional
:sort
,
type:
String
,
desc:
'The sorting option'
end
get
":id/billable_members"
do
group
=
find_group!
(
params
[
:id
])
...
...
@@ -56,7 +58,7 @@ module EE
bad_request!
(
nil
)
if
group
.
subgroup?
bad_request!
(
nil
)
unless
::
Ability
.
allowed?
(
current_user
,
:admin_group_member
,
group
)
users
=
paginate_billable_from_user_ids
(
group
.
billed_user_id
s
)
users
=
paginate_billable_from_user_ids
(
group
_billed_user_ids_for
(
group
,
params
),
param
s
)
present
users
,
with:
::
API
::
Entities
::
UserBasic
,
current_user:
current_user
end
...
...
ee/spec/lib/ee/api/helpers/members_helpers_spec.rb
View file @
b694cfae
...
...
@@ -2,7 +2,7 @@
require
'spec_helper'
RSpec
.
describe
EE
::
API
::
Helpers
::
MembersHelpers
do
subjec
t
(
:members_helpers
)
{
Class
.
new
.
include
(
described_class
).
new
}
le
t
(
:members_helpers
)
{
Class
.
new
.
include
(
described_class
).
new
}
before
do
allow
(
members_helpers
).
to
receive
(
:current_user
).
and_return
(
create
(
:user
))
...
...
@@ -21,6 +21,8 @@ RSpec.describe EE::API::Helpers::MembersHelpers do
end
describe
'#log_audit_event'
do
subject
{
members_helpers
}
it_behaves_like
'creates security_event'
,
'group'
do
let
(
:source
)
{
create
(
:group
)
}
let
(
:member
)
{
create
(
:group_member
,
:owner
,
group:
source
,
user:
create
(
:user
))
}
...
...
@@ -65,4 +67,41 @@ RSpec.describe EE::API::Helpers::MembersHelpers do
end
end
end
describe
'#group_billed_user_ids_for'
do
let_it_be
(
:group
)
{
create
(
:group
)
}
let_it_be
(
:gm_1
)
{
create
(
:group_member
,
group:
group
,
user:
create
(
:user
,
name:
'Maria Gomez'
))
}
let_it_be
(
:gm_2
)
{
create
(
:group_member
,
group:
group
,
user:
create
(
:user
,
name:
'John Smith'
))
}
let_it_be
(
:gm_3
)
{
create
(
:group_member
,
group:
group
,
user:
create
(
:user
,
name:
'John Doe'
))
}
let_it_be
(
:gm_4
)
{
create
(
:group_member
,
group:
group
,
user:
create
(
:user
,
name:
'Sophie Dupont'
))
}
let
(
:params
)
{
{}
}
subject
{
members_helpers
.
group_billed_user_ids_for
(
group
,
params
).
to_a
}
context
'when a search parameter is present'
do
let
(
:params
)
{
{
search:
'John'
,
sort:
sort
}
}
context
'when a sorting parameter is provided (eg name descending)'
do
let
(
:sort
)
{
'name_desc'
}
it
'sorts results accordingly'
do
expect
(
subject
).
to
eq
([
gm_2
,
gm_3
].
map
(
&
:user_id
))
end
end
context
'when a sorting parameter is not provided'
do
let
(
:sort
)
{
nil
}
it
'sorts results by name ascending'
do
expect
(
subject
).
to
eq
([
gm_3
,
gm_2
].
map
(
&
:user_id
))
end
end
end
context
'when a search parameter is not present'
do
it
'returns the expected group member user ids'
do
expect
(
subject
).
to
eq
([
gm_1
,
gm_2
,
gm_3
,
gm_4
].
map
(
&
:user_id
))
end
end
end
end
ee/spec/requests/api/members_spec.rb
View file @
b694cfae
...
...
@@ -339,7 +339,7 @@ RSpec.describe API::Members do
end
end
let_it_be
(
:nested_user
)
{
create
(
:user
)
}
let_it_be
(
:nested_user
)
{
create
(
:user
,
name:
'Scott Anderson'
)
}
let_it_be
(
:nested_group
)
do
create
(
:group
,
parent:
group
)
do
|
nested_group
|
nested_group
.
add_developer
(
nested_user
)
...
...
@@ -347,9 +347,10 @@ RSpec.describe API::Members do
end
let
(
:url
)
{
"/groups/
#{
group
.
id
}
/billable_members"
}
let
(
:params
)
{
{}
}
subject
do
get
api
(
url
,
owner
)
get
api
(
url
,
owner
)
,
params:
params
json_response
end
...
...
@@ -361,7 +362,7 @@ RSpec.describe API::Members do
end
end
let!
(
:linked_group_user
)
{
create
(
:user
)
}
let!
(
:linked_group_user
)
{
create
(
:user
,
name:
'Scott McNeil'
)
}
let!
(
:linked_group
)
do
create
(
:group
)
do
|
linked_group
|
linked_group
.
add_developer
(
linked_group_user
)
...
...
@@ -375,6 +376,26 @@ RSpec.describe API::Members do
expect_paginated_array_response
(
*
[
owner
,
maintainer
,
nested_user
,
project_user
,
linked_group_user
].
map
(
&
:id
))
end
context
'with seach params provided'
do
let
(
:params
)
{
{
search:
nested_user
.
name
}
}
it
'returns the relevant billable users'
do
subject
expect_paginated_array_response
([
nested_user
.
id
])
end
end
context
'with search and sort params provided'
do
let
(
:params
)
{
{
search:
'Scott'
,
sort:
'name_desc'
}
}
it
'returns the relevant billable users'
do
subject
expect_paginated_array_response
(
*
[
linked_group_user
,
nested_user
].
map
(
&
:id
))
end
end
end
context
'when feature is disabled'
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