diff options
author | Sean McGivern <sean@gitlab.com> | 2016-11-17 12:41:48 +0000 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2016-11-17 18:37:52 +0000 |
commit | 79122896318ae50c835418888f7f781fa2e463f4 (patch) | |
tree | f429b92c3c4747d321d6c1cad0d7573c696f726e /lib/api/groups.rb | |
parent | 50585cddb53c8cc28135a8c7a11f2d1cf02b9593 (diff) | |
download | gitlab-ce-79122896318ae50c835418888f7f781fa2e463f4.tar.gz |
Allow sorting groups in APIsort-api-groups
Allow `order_by` and `sort` parameters to `/api/v3/groups.json`. At
present, only ordering by name and path is supported, and the default
sort is name ascending (alphabetical order).
Diffstat (limited to 'lib/api/groups.rb')
-rw-r--r-- | lib/api/groups.rb | 4 |
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 |