summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2016-11-17 21:50:02 +0000
committerSean McGivern <sean@mcgivern.me.uk>2016-11-17 21:50:02 +0000
commit8823107e57a4fe6c22b85537bd0fe498af6cbbf8 (patch)
treeca61c97bb34fed519f3cd7c8057b0f316cbd33f2 /lib/api
parent0e1ff0ebd44f5cf0154d9ef5b5b818fb47a82123 (diff)
parent79122896318ae50c835418888f7f781fa2e463f4 (diff)
downloadgitlab-ce-8823107e57a4fe6c22b85537bd0fe498af6cbbf8.tar.gz
Merge branch 'sort-api-groups' into 'master'
Allow sorting groups in API Relates to #20013. See merge request !7529
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/groups.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/api/groups.rb b/lib/api/groups.rb
index 3f57b9ab5bc..48ad3b80ae0 100644
--- a/lib/api/groups.rb
+++ b/lib/api/groups.rb
@@ -19,6 +19,8 @@ module API
optional :skip_groups, type: Array[Integer], desc: 'Array of group ids to exclude from list'
optional :all_available, type: Boolean, desc: 'Show all group that you have access to'
optional :search, type: String, desc: 'Search for a specific group'
+ optional :order_by, type: String, values: %w[name path], default: 'name', desc: 'Order by name or path'
+ optional :sort, type: String, values: %w[asc desc], default: 'asc', desc: 'Sort by asc (ascending) or desc (descending)'
end
get do
groups = if current_user.admin
@@ -31,6 +33,8 @@ module API
groups = groups.search(params[:search]) if params[:search].present?
groups = groups.where.not(id: params[:skip_groups]) if params[:skip_groups].present?
+ groups = groups.reorder(params[:order_by] => params[:sort].to_sym)
+
present paginate(groups), with: Entities::Group
end