diff options
author | Douwe Maan <douwe@gitlab.com> | 2016-09-12 08:47:11 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2016-09-12 08:47:11 +0000 |
commit | 6c8516db241e20ecc678e394edbde1e618ad59ad (patch) | |
tree | 4f0ec69fb18179de97b6ffaf6726e069eddfcf8d /lib/api | |
parent | 3a59efd562d22ec3148101d794d99889ccc9b82b (diff) | |
parent | 45fc8b73ed1875cc9766e5735d4411fd5c8872be (diff) | |
download | gitlab-ce-6c8516db241e20ecc678e394edbde1e618ad59ad.tar.gz |
Merge branch 'fix-api-sorting' into 'master'
Fix API issues sorting
## What does this MR do?
Fix the sorting of issues in the API.
## Are there points in the code the reviewer needs to double check?
Instead of removing the '_at' suffix manually, we could add those versions to the `Sortable` concern instead.
## Why was this MR needed?
There were a couple of bugs:
* The global and project-specific issues endpoints wouldn't sort at all.
* Group sorting would work, but only if you applied two undocumented workarounds:
* Always pass both `order_by` and `sort` (both are optional, so only one should be needed to change ordering).
* Instead of passing `created_at` or `updated_at`, you needed to pass `created` or `updated`.
This makes the API implementation match the docs.
## Does this MR meet the acceptance criteria?
- [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added
- [x] API support added
- Tests
- [x] Added for this feature/bug
- [ ] All builds are passing
- [x] Conform by the [merge request performance guides](http://docs.gitlab.com/ce/development/merge_request_performance_guidelines.html)
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)
## What are the relevant issue numbers?
Closes https://gitlab.com/gitlab-org/gitlab-ee/issues/983.
See merge request !6281
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/issues.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 556684187d8..c9689e6f8ef 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -41,7 +41,8 @@ module API issues = current_user.issues.inc_notes_with_associations issues = filter_issues_state(issues, params[:state]) unless params[:state].nil? issues = filter_issues_labels(issues, params[:labels]) unless params[:labels].nil? - issues.reorder(issuable_order_by => issuable_sort) + issues = issues.reorder(issuable_order_by => issuable_sort) + present paginate(issues), with: Entities::Issue, current_user: current_user end end @@ -73,7 +74,11 @@ module API params[:group_id] = group.id params[:milestone_title] = params.delete(:milestone) params[:label_name] = params.delete(:labels) - params[:sort] = "#{params.delete(:order_by)}_#{params.delete(:sort)}" if params[:order_by] && params[:sort] + + if params[:order_by] || params[:sort] + # The Sortable concern takes 'created_desc', not 'created_at_desc' (for example) + params[:sort] = "#{issuable_order_by.sub('_at', '')}_#{issuable_sort}" + end issues = IssuesFinder.new(current_user, params).execute @@ -113,7 +118,8 @@ module API issues = filter_issues_milestone(issues, params[:milestone]) end - issues.reorder(issuable_order_by => issuable_sort) + issues = issues.reorder(issuable_order_by => issuable_sort) + present paginate(issues), with: Entities::Issue, current_user: current_user end |