BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
7c2b7296
Commit
7c2b7296
authored
Dec 04, 2017
by
Francisco Javier López
Committed by
Douwe Maan
Dec 04, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added default order to UserFinder
parent
c997c95d
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
2 deletions
+44
-2
users_finder.rb
app/finders/users_finder.rb
+1
-1
user.rb
app/models/user.rb
+5
-1
fj-40407-missing-order-paginate.yml
changelogs/unreleased/fj-40407-missing-order-paginate.yml
+5
-0
pagination.rb
lib/api/helpers/pagination.rb
+10
-0
users.rb
lib/api/users.rb
+2
-0
pagination_spec.rb
spec/lib/api/helpers/pagination_spec.rb
+21
-0
No files found.
app/finders/users_finder.rb
View file @
7c2b7296
...
@@ -25,7 +25,7 @@ class UsersFinder
...
@@ -25,7 +25,7 @@ class UsersFinder
end
end
def
execute
def
execute
users
=
User
.
all
users
=
User
.
all
.
order_id_desc
users
=
by_username
(
users
)
users
=
by_username
(
users
)
users
=
by_search
(
users
)
users
=
by_search
(
users
)
users
=
by_blocked
(
users
)
users
=
by_blocked
(
users
)
...
...
app/models/user.rb
View file @
7c2b7296
...
@@ -487,7 +487,11 @@ class User < ActiveRecord::Base
...
@@ -487,7 +487,11 @@ class User < ActiveRecord::Base
end
end
def
two_factor_u2f_enabled?
def
two_factor_u2f_enabled?
u2f_registrations
.
exists?
if
u2f_registrations
.
loaded?
u2f_registrations
.
any?
else
u2f_registrations
.
exists?
end
end
end
def
namespace_uniq
def
namespace_uniq
...
...
changelogs/unreleased/fj-40407-missing-order-paginate.yml
0 → 100644
View file @
7c2b7296
---
title
:
Added default order to UsersFinder
merge_request
:
15679
author
:
type
:
fixed
lib/api/helpers/pagination.rb
View file @
7c2b7296
...
@@ -2,6 +2,8 @@ module API
...
@@ -2,6 +2,8 @@ module API
module
Helpers
module
Helpers
module
Pagination
module
Pagination
def
paginate
(
relation
)
def
paginate
(
relation
)
relation
=
add_default_order
(
relation
)
relation
.
page
(
params
[
:page
]).
per
(
params
[
:per_page
]).
tap
do
|
data
|
relation
.
page
(
params
[
:page
]).
per
(
params
[
:per_page
]).
tap
do
|
data
|
add_pagination_headers
(
data
)
add_pagination_headers
(
data
)
end
end
...
@@ -45,6 +47,14 @@ module API
...
@@ -45,6 +47,14 @@ module API
# Ensure there is in total at least 1 page
# Ensure there is in total at least 1 page
[
paginated_data
.
total_pages
,
1
].
max
[
paginated_data
.
total_pages
,
1
].
max
end
end
def
add_default_order
(
relation
)
if
relation
.
is_a?
(
ActiveRecord
::
Relation
)
&&
relation
.
order_values
.
empty?
relation
=
relation
.
order
(
:id
)
end
relation
end
end
end
end
end
end
end
lib/api/users.rb
View file @
7c2b7296
...
@@ -76,6 +76,8 @@ module API
...
@@ -76,6 +76,8 @@ module API
forbidden!
(
"Not authorized to access /api/v4/users"
)
unless
authorized
forbidden!
(
"Not authorized to access /api/v4/users"
)
unless
authorized
entity
=
current_user
&
.
admin?
?
Entities
::
UserWithAdmin
:
Entities
::
UserBasic
entity
=
current_user
&
.
admin?
?
Entities
::
UserWithAdmin
:
Entities
::
UserBasic
users
=
users
.
preload
(
:identities
,
:u2f_registrations
)
if
entity
==
Entities
::
UserWithAdmin
present
paginate
(
users
),
with:
entity
present
paginate
(
users
),
with:
entity
end
end
...
...
spec/lib/api/helpers/pagination_spec.rb
View file @
7c2b7296
...
@@ -92,6 +92,27 @@ describe API::Helpers::Pagination do
...
@@ -92,6 +92,27 @@ describe API::Helpers::Pagination do
subject
.
paginate
(
resource
)
subject
.
paginate
(
resource
)
end
end
end
end
context
'if order'
do
it
'is not present it adds default order(:id) if no order is present'
do
resource
.
order_values
=
[]
paginated_relation
=
subject
.
paginate
(
resource
)
expect
(
resource
.
order_values
).
to
be_empty
expect
(
paginated_relation
.
order_values
).
to
be_present
expect
(
paginated_relation
.
order_values
.
first
).
to
be_ascending
expect
(
paginated_relation
.
order_values
.
first
.
expr
.
name
).
to
eq
:id
end
it
'is present it does not add anything'
do
paginated_relation
=
subject
.
paginate
(
resource
.
order
(
created_at: :desc
))
expect
(
paginated_relation
.
order_values
).
to
be_present
expect
(
paginated_relation
.
order_values
.
first
).
to
be_descending
expect
(
paginated_relation
.
order_values
.
first
.
expr
.
name
).
to
eq
:created_at
end
end
end
end
context
'when resource empty'
do
context
'when resource empty'
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