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
969f62a8
Commit
969f62a8
authored
Dec 09, 2020
by
Etienne Baqué
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added BilledUsersFinder class
Added rspec accordingly.
parent
77c482e6
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
99 additions
and
60 deletions
+99
-60
ee/app/finders/billed_users_finder.rb
ee/app/finders/billed_users_finder.rb
+26
-0
ee/lib/ee/api/helpers/members_helpers.rb
ee/lib/ee/api/helpers/members_helpers.rb
+0
-7
ee/lib/ee/api/members.rb
ee/lib/ee/api/members.rb
+5
-1
ee/spec/finders/billed_users_finder_spec.rb
ee/spec/finders/billed_users_finder_spec.rb
+58
-0
ee/spec/lib/ee/api/helpers/members_helpers_spec.rb
ee/spec/lib/ee/api/helpers/members_helpers_spec.rb
+0
-52
ee/spec/requests/api/members_spec.rb
ee/spec/requests/api/members_spec.rb
+10
-0
No files found.
ee/app/finders/billed_users_finder.rb
0 → 100644
View file @
969f62a8
# frozen_string_literal: true
class
BilledUsersFinder
def
initialize
(
group
,
search_term:
nil
,
order_by:
'name_asc'
)
@group
=
group
@search_term
=
search_term
@order_by
=
order_by
end
def
execute
return
[]
unless
group_billed_user_ids
.
any?
users
=
::
User
.
id_in
(
group_billed_user_ids
)
users
=
users
.
search
(
search_term
)
if
search_term
users
.
sort_by_attribute
(
order_by
)
end
private
attr_reader
:group
,
:search_term
,
:order_by
def
group_billed_user_ids
@group_billed_user_ids
||=
group
.
billed_user_ids
end
end
ee/lib/ee/api/helpers/members_helpers.rb
View file @
969f62a8
...
@@ -83,13 +83,6 @@ module EE
...
@@ -83,13 +83,6 @@ module EE
action: :create
action: :create
).
for_member
(
member
).
security_event
).
for_member
(
member
).
security_event
end
end
def
billed_users_for
(
group
,
search_term
,
order_by:
'name_asc'
)
users
=
::
User
.
id_in
(
group
.
billed_user_ids
)
users
=
users
.
search
(
search_term
)
if
search_term
users
.
sort_by_attribute
(
order_by
)
end
end
end
end
end
end
end
...
...
ee/lib/ee/api/members.rb
View file @
969f62a8
...
@@ -57,7 +57,11 @@ module EE
...
@@ -57,7 +57,11 @@ module EE
bad_request!
(
nil
)
unless
::
Ability
.
allowed?
(
current_user
,
:admin_group_member
,
group
)
bad_request!
(
nil
)
unless
::
Ability
.
allowed?
(
current_user
,
:admin_group_member
,
group
)
sorting
=
params
[
:sort
]
||
'id_asc'
sorting
=
params
[
:sort
]
||
'id_asc'
users
=
paginate
(
billed_users_for
(
group
,
params
[
:search
],
order_by:
sorting
))
users
=
paginate
(
BilledUsersFinder
.
new
(
group
,
search_term:
params
[
:search
],
order_by:
sorting
).
execute
)
present
users
,
with:
::
API
::
Entities
::
UserBasic
,
current_user:
current_user
present
users
,
with:
::
API
::
Entities
::
UserBasic
,
current_user:
current_user
end
end
...
...
ee/spec/finders/billed_users_finder_spec.rb
0 → 100644
View file @
969f62a8
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
BilledUsersFinder
do
let_it_be
(
:group
)
{
create
(
:group
)
}
let
(
:search_term
)
{
nil
}
let
(
:order_by
)
{
nil
}
describe
'#execute'
do
let_it_be
(
:maria
)
{
create
(
:group_member
,
group:
group
,
user:
create
(
:user
,
name:
'Maria Gomez'
))
}
let_it_be
(
:john_smith
)
{
create
(
:group_member
,
group:
group
,
user:
create
(
:user
,
name:
'John Smith'
))
}
let_it_be
(
:john_doe
)
{
create
(
:group_member
,
group:
group
,
user:
create
(
:user
,
name:
'John Doe'
))
}
let_it_be
(
:sophie
)
{
create
(
:group_member
,
group:
group
,
user:
create
(
:user
,
name:
'Sophie Dupont'
))
}
subject
{
described_class
.
new
(
group
,
search_term:
search_term
,
order_by:
order_by
)
}
context
'when a group does not have any billed users'
do
it
'returns an empty array'
do
allow
(
group
).
to
receive
(
:billed_user_ids
).
and_return
([])
expect
(
subject
.
execute
).
to
be_empty
end
end
context
'when a search parameter is provided'
do
let
(
:search_term
)
{
'John'
}
context
'when a sorting parameter is provided (eg name descending)'
do
let
(
:order_by
)
{
'name_desc'
}
it
'sorts results accordingly'
do
expect
(
subject
.
execute
).
to
eq
([
john_smith
,
john_doe
].
map
(
&
:user
))
end
end
end
context
'when a search parameter is not present'
do
subject
{
described_class
.
new
(
group
)
}
it
'returns expected users in name asc order when a sorting is not provided either'
do
allow
(
group
).
to
receive
(
:billed_user_members
).
and_return
([
john_doe
,
john_smith
,
sophie
,
maria
])
expect
(
subject
.
execute
).
to
eq
([
john_doe
,
john_smith
,
maria
,
sophie
].
map
(
&
:user
))
end
context
'and when a sorting parameter is provided (eg name descending)'
do
let
(
:order_by
)
{
'name_desc'
}
subject
{
described_class
.
new
(
group
,
search_term:
search_term
,
order_by:
order_by
)
}
it
'sorts results accordingly'
do
expect
(
subject
.
execute
).
to
eq
([
sophie
,
maria
,
john_smith
,
john_doe
].
map
(
&
:user
))
end
end
end
end
end
ee/spec/lib/ee/api/helpers/members_helpers_spec.rb
View file @
969f62a8
...
@@ -33,56 +33,4 @@ RSpec.describe EE::API::Helpers::MembersHelpers do
...
@@ -33,56 +33,4 @@ RSpec.describe EE::API::Helpers::MembersHelpers do
let
(
:member
)
{
create
(
:project_member
,
project:
source
,
user:
create
(
:user
))
}
let
(
:member
)
{
create
(
:project_member
,
project:
source
,
user:
create
(
:user
))
}
end
end
end
end
describe
'#billed_users_for'
do
let_it_be
(
:group
)
{
create
(
:group
)
}
let_it_be
(
:maria
)
{
create
(
:group_member
,
group:
group
,
user:
create
(
:user
,
name:
'Maria Gomez'
))
}
let_it_be
(
:john_smith
)
{
create
(
:group_member
,
group:
group
,
user:
create
(
:user
,
name:
'John Smith'
))
}
let_it_be
(
:john_doe
)
{
create
(
:group_member
,
group:
group
,
user:
create
(
:user
,
name:
'John Doe'
))
}
let_it_be
(
:sophie
)
{
create
(
:group_member
,
group:
group
,
user:
create
(
:user
,
name:
'Sophie Dupont'
))
}
let
(
:search_term
)
{
nil
}
let
(
:order_by
)
{
nil
}
subject
{
members_helpers
.
billed_users_for
(
group
,
search_term
,
order_by:
order_by
)
}
context
'when a search parameter is present'
do
let
(
:search_term
)
{
'John'
}
context
'when a sorting parameter is provided (eg name descending)'
do
let
(
:order_by
)
{
'name_desc'
}
it
'sorts results accordingly'
do
expect
(
subject
).
to
eq
([
john_smith
,
john_doe
].
map
(
&
:user
))
end
end
context
'when a sorting parameter is not provided'
do
let
(
:order_by
)
{
nil
}
it
'sorts results by name ascending'
do
expect
(
subject
).
to
eq
([
john_doe
,
john_smith
].
map
(
&
:user
))
end
end
end
context
'when a search parameter is not present'
do
subject
{
members_helpers
.
billed_users_for
(
group
,
search_term
)
}
it
'returns expected users in name asc order'
do
allow
(
group
).
to
receive
(
:billed_user_members
).
and_return
([
john_doe
,
john_smith
,
sophie
,
maria
])
expect
(
subject
).
to
eq
([
john_doe
,
john_smith
,
maria
,
sophie
].
map
(
&
:user
))
end
context
'and when a sorting parameter is provided (eg name descending)'
do
let
(
:order_by
)
{
'name_desc'
}
subject
{
members_helpers
.
billed_users_for
(
group
,
search_term
,
order_by:
order_by
)
}
it
'sorts results accordingly'
do
expect
(
subject
).
to
eq
([
sophie
,
maria
,
john_smith
,
john_doe
].
map
(
&
:user
))
end
end
end
end
end
end
ee/spec/requests/api/members_spec.rb
View file @
969f62a8
...
@@ -399,6 +399,16 @@ RSpec.describe API::Members do
...
@@ -399,6 +399,16 @@ RSpec.describe API::Members do
expect_paginated_array_response
(
*
[
owner
,
maintainer
,
nested_user
,
project_user
,
linked_group_user
].
map
(
&
:id
))
expect_paginated_array_response
(
*
[
owner
,
maintainer
,
nested_user
,
project_user
,
linked_group_user
].
map
(
&
:id
))
end
end
context
'when the current user does not have the :admin_group_member ability'
do
it
'is a bad request'
do
not_an_owner
=
create
(
:user
)
get
api
(
url
,
not_an_owner
),
params:
params
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
end
context
'with seach params provided'
do
context
'with seach params provided'
do
let
(
:params
)
{
{
search:
nested_user
.
name
}
}
let
(
:params
)
{
{
search:
nested_user
.
name
}
}
...
...
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