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
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
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
2 deletions
+44
-2
app/finders/users_finder.rb
app/finders/users_finder.rb
+1
-1
app/models/user.rb
app/models/user.rb
+5
-1
changelogs/unreleased/fj-40407-missing-order-paginate.yml
changelogs/unreleased/fj-40407-missing-order-paginate.yml
+5
-0
lib/api/helpers/pagination.rb
lib/api/helpers/pagination.rb
+10
-0
lib/api/users.rb
lib/api/users.rb
+2
-0
spec/lib/api/helpers/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
end
def
execute
users
=
User
.
all
users
=
User
.
all
.
order_id_desc
users
=
by_username
(
users
)
users
=
by_search
(
users
)
users
=
by_blocked
(
users
)
...
...
app/models/user.rb
View file @
7c2b7296
...
...
@@ -487,7 +487,11 @@ class User < ActiveRecord::Base
end
def
two_factor_u2f_enabled?
u2f_registrations
.
exists?
if
u2f_registrations
.
loaded?
u2f_registrations
.
any?
else
u2f_registrations
.
exists?
end
end
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
module
Helpers
module
Pagination
def
paginate
(
relation
)
relation
=
add_default_order
(
relation
)
relation
.
page
(
params
[
:page
]).
per
(
params
[
:per_page
]).
tap
do
|
data
|
add_pagination_headers
(
data
)
end
...
...
@@ -45,6 +47,14 @@ module API
# Ensure there is in total at least 1 page
[
paginated_data
.
total_pages
,
1
].
max
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
lib/api/users.rb
View file @
7c2b7296
...
...
@@ -76,6 +76,8 @@ module API
forbidden!
(
"Not authorized to access /api/v4/users"
)
unless
authorized
entity
=
current_user
&
.
admin?
?
Entities
::
UserWithAdmin
:
Entities
::
UserBasic
users
=
users
.
preload
(
:identities
,
:u2f_registrations
)
if
entity
==
Entities
::
UserWithAdmin
present
paginate
(
users
),
with:
entity
end
...
...
spec/lib/api/helpers/pagination_spec.rb
View file @
7c2b7296
...
...
@@ -92,6 +92,27 @@ describe API::Helpers::Pagination do
subject
.
paginate
(
resource
)
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
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