summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFrancisco Javier López <fjlopez@gitlab.com>2017-12-04 09:49:53 +0000
committerDouwe Maan <douwe@gitlab.com>2017-12-04 09:49:53 +0000
commit7c2b7296d4e623ba4eaa19cf03405ee7f2ae1ca9 (patch)
tree80784f83c52313797b8cf7e78ccf8db66f0880d8 /lib
parentc997c95dfca2c3d30f8c7b8ef5f0fd95c1356226 (diff)
downloadgitlab-ce-7c2b7296d4e623ba4eaa19cf03405ee7f2ae1ca9.tar.gz
Added default order to UserFinder
Diffstat (limited to 'lib')
-rw-r--r--lib/api/helpers/pagination.rb10
-rw-r--r--lib/api/users.rb2
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/api/helpers/pagination.rb b/lib/api/helpers/pagination.rb
index 95108292aac..bb70370ba77 100644
--- a/lib/api/helpers/pagination.rb
+++ b/lib/api/helpers/pagination.rb
@@ -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
diff --git a/lib/api/users.rb b/lib/api/users.rb
index 0cd89b1bcf8..e5de31ad51b 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -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