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
778f2456
Commit
778f2456
authored
Dec 04, 2020
by
Etienne Baqué
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Applied maintainer reviewer recommendation
Reorganized code based on review.
parent
e592e1fb
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
67 additions
and
69 deletions
+67
-69
app/models/members/group_member.rb
app/models/members/group_member.rb
+0
-1
ee/app/models/ee/group.rb
ee/app/models/ee/group.rb
+6
-14
ee/lib/ee/api/helpers/members_helpers.rb
ee/lib/ee/api/helpers/members_helpers.rb
+12
-5
ee/lib/ee/api/members.rb
ee/lib/ee/api/members.rb
+1
-1
ee/spec/lib/ee/api/helpers/members_helpers_spec.rb
ee/spec/lib/ee/api/helpers/members_helpers_spec.rb
+48
-0
ee/spec/models/group_spec.rb
ee/spec/models/group_spec.rb
+0
-48
No files found.
app/models/members/group_member.rb
View file @
778f2456
...
...
@@ -22,7 +22,6 @@ class GroupMember < Member
scope
:of_ldap_type
,
->
{
where
(
ldap:
true
)
}
scope
:count_users_by_group_id
,
->
{
group
(
:source_id
).
count
}
scope
:with_user
,
->
(
user
)
{
where
(
user:
user
)
}
scope
:get_user_id
,
->
{
pluck
(
:user_id
)
}
after_create
:update_two_factor_requirement
,
unless: :invite?
after_destroy
:update_two_factor_requirement
,
unless: :invite?
...
...
ee/app/models/ee/group.rb
View file @
778f2456
...
...
@@ -8,7 +8,6 @@ module EE
module
Group
extend
ActiveSupport
::
Concern
extend
::
Gitlab
::
Utils
::
Override
include
::
SortingHelper
prepended
do
include
TokenAuthenticatable
...
...
@@ -449,13 +448,6 @@ module EE
)
end
def
billed_users_for
(
search_term
,
order_by
)
users
=
::
User
.
id_in
(
billed_user_ids
)
users
=
users
.
search
(
search_term
)
if
search_term
users
.
sort_by_attribute
(
order_by
||
sort_value_name
)
end
private
def
custom_project_templates_group_allowed
...
...
ee/lib/ee/api/helpers/members_helpers.rb
View file @
778f2456
...
...
@@ -7,6 +7,14 @@ module EE
extend
ActiveSupport
::
Concern
extend
::
Gitlab
::
Utils
::
Override
class
<<
self
include
::
SortingHelper
def
member_sort_options
member_sort_options_hash
.
keys
end
end
prepended
do
params
:optional_filter_params_ee
do
optional
:with_saml_identity
,
type:
Grape
::
API
::
Boolean
,
desc:
"List only members with linked SAML identity"
...
...
@@ -76,12 +84,11 @@ module EE
).
for_member
(
member
).
security_event
end
class
<<
self
include
::
SortingHelper
def
billed_users_for
(
group
,
search_term
,
order_by
)
users
=
::
User
.
id_in
(
group
.
billed_user_ids
)
users
=
users
.
search
(
search_term
)
if
search_term
def
member_sort_options
member_sort_options_hash
.
keys
end
users
.
sort_by_attribute
(
order_by
||
'name_asc'
)
end
end
end
...
...
ee/lib/ee/api/members.rb
View file @
778f2456
...
...
@@ -59,7 +59,7 @@ module EE
bad_request!
(
nil
)
unless
::
Ability
.
allowed?
(
current_user
,
:admin_group_member
,
group
)
sorting
=
params
[
:sort
]
||
'id_asc'
users
=
paginate
(
group
.
billed_users_for
(
params
[
:search
],
sorting
))
users
=
paginate
(
billed_users_for
(
group
,
params
[
:search
],
sorting
))
present
users
,
with:
::
API
::
Entities
::
UserBasic
,
current_user:
current_user
end
...
...
ee/spec/lib/ee/api/helpers/members_helpers_spec.rb
View file @
778f2456
...
...
@@ -33,4 +33,52 @@ RSpec.describe EE::API::Helpers::MembersHelpers do
let
(
:member
)
{
create
(
:project_member
,
project:
source
,
user:
create
(
:user
))
}
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
)
}
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
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'
}
it
'sorts results accordingly'
do
expect
(
subject
).
to
eq
([
sophie
,
maria
,
john_smith
,
john_doe
].
map
(
&
:user
))
end
end
end
end
end
ee/spec/models/group_spec.rb
View file @
778f2456
...
...
@@ -1223,52 +1223,4 @@ RSpec.describe Group do
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
{
group
.
billed_users_for
(
search_term
,
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
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'
}
it
'sorts results accordingly'
do
expect
(
subject
).
to
eq
([
sophie
,
maria
,
john_smith
,
john_doe
].
map
(
&
:user
))
end
end
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