Used Zammad installation source: (source, package, …) docker-compose
Operating system: Debian 9
Browser + version: curl
Background
I want to use the API to find all users that have a company email adress. My original request was:
/api/v1/users/search?query=email:@ourcompany.tld
But that broke as soon as there were more than 100 results, so I want to use pagination. My request now looks like this (5 results per page for testing):
OK, I’m certain now it’s bugged. The necessary pagination information is passed to User.search which then returns already paginated results, but the # do pagination if needed block afterwards then assumes unpaginated results, and tries to extract the paginated subpart again.
commit cf1626494047f27d8fe094a7b954e04fef0f182b
Author: Martin Edenhofer <me@edenhofer.de>
Date: Fri Apr 13 09:22:55 2018 +0200
Implemented issue #1951 - Allow pagination in search result with more then 100 results.
@martini reworked pagination across multiple controllers and removed the # do pagination if needed block from organizations_controller.rb and tickets_controller.rb, but apparently missed it in users_controller.rb
This fixes it:
zammad@martin.mein-iserv.de ~ (develop) % git diff
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index f39a36ddb..106aa60f9 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -405,12 +405,6 @@ class UsersController < ApplicationController
# do query
user_all = User.search(query_params)
- # do pagination if needed
- if params[:page] && params[:per_page]
- offset = (params[:page].to_i - 1) * params[:per_page].to_i
- user_all = user_all[offset, params[:per_page].to_i] || []
- end
-
if response_expand?
list = []
user_all.each do |user|
I’ll look into writing tests for this and will submit a MR when I’m done.