API compatibility to legacy status and name query params (#39181, #37674)

- adds 'name' filter that mimics the old behavior of matching on email, login, first- or lastname
- maps the 'status' url parameter to the status_id filter, and the 'name' url parameter to the new name filter

Patch by Jens Krämer.


git-svn-id: https://svn.redmine.org/redmine/trunk@22343 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA
2023-10-15 01:42:07 +00:00
parent 26c392d3c3
commit ff93ee3cfa
5 changed files with 103 additions and 0 deletions

View File

@@ -82,6 +82,44 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
end
end
test "GET /users.json with legacy filter params" do
get '/users.json', :headers => credentials('admin'), params: { status: 3 }
assert_response :success
json = ActiveSupport::JSON.decode(response.body)
assert json.key?('users')
users = User.where(status: 3)
assert_equal users.size, json['users'].size
get '/users.json', :headers => credentials('admin'), params: { name: 'jsmith' }
assert_response :success
json = ActiveSupport::JSON.decode(response.body)
assert json.key?('users')
assert_equal 1, json['users'].size
assert_equal 2, json['users'][0]['id']
get '/users.json', :headers => credentials('admin'), params: { group_id: '10' }
assert_response :success
json = ActiveSupport::JSON.decode(response.body)
assert json.key?('users')
assert_equal 1, json['users'].size
assert_equal 8, json['users'][0]['id']
# there should be an implicit filter for status = 1
User.where(id: [2, 8]).update_all status: 3
get '/users.json', :headers => credentials('admin'), params: { name: 'jsmith' }
assert_response :success
json = ActiveSupport::JSON.decode(response.body)
assert json.key?('users')
assert_equal 0, json['users'].size
get '/users.json', :headers => credentials('admin'), params: { group_id: '10' }
assert_response :success
json = ActiveSupport::JSON.decode(response.body)
assert json.key?('users')
assert_equal 0, json['users'].size
end
test "GET /users/:id.xml should return the user" do
Redmine::Configuration.with 'avatar_server_url' => 'https://gravatar.com' do
with_settings :gravatar_enabled => '1', :gravatar_default => 'robohash' do