summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2023-10-15 01:42:07 +0000
committerGo MAEDA <maeda@farend.jp>2023-10-15 01:42:07 +0000
commitff93ee3cfaf4aae92e826c8e879e1bb648c0dddd (patch)
treeb1b723612da5549ff0e2e2380f87ed340b839e08 /test
parent26c392d3c368af689df8c0c95863e3e0298d462a (diff)
downloadredmine-ff93ee3cfaf4aae92e826c8e879e1bb648c0dddd.tar.gz
redmine-ff93ee3cfaf4aae92e826c8e879e1bb648c0dddd.zip
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
Diffstat (limited to 'test')
-rw-r--r--test/integration/api_test/users_test.rb38
-rw-r--r--test/unit/user_query_test.rb23
2 files changed, 61 insertions, 0 deletions
diff --git a/test/integration/api_test/users_test.rb b/test/integration/api_test/users_test.rb
index 81ac487ac..5b52f6d3b 100644
--- a/test/integration/api_test/users_test.rb
+++ b/test/integration/api_test/users_test.rb
@@ -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
diff --git a/test/unit/user_query_test.rb b/test/unit/user_query_test.rb
index 9bb9c816d..e5d8dd312 100644
--- a/test/unit/user_query_test.rb
+++ b/test/unit/user_query_test.rb
@@ -108,6 +108,29 @@ class UserQueryTest < ActiveSupport::TestCase
end
end
+ def test_name_or_email_or_login_filter
+ [
+ ['~', 'jsmith', [2]],
+ ['^', 'jsm', [2]],
+ ['$', 'ith', [2]],
+ ['~', 'john', [2]],
+ ['~', 'smith', [2]],
+ ['~', 'somenet', [1, 2, 3, 4]],
+ ['!~', 'somenet', [7, 8, 9]],
+ ['^', 'dlop', [3]],
+ ['$', 'bar', [7, 8, 9]],
+ ['=', 'bar', []],
+ ['=', 'someone@foo.bar', [7]],
+ ['*', '', [1, 2, 3, 4, 7, 8, 9]],
+ ['!*', '', []],
+ ].each do |op, string, result|
+ q = UserQuery.new name: '_'
+ q.add_filter('name', op, [string])
+ users = find_users_with_query q
+ assert_equal result, users.map(&:id).sort, "#{op} #{string} should have found #{result}"
+ end
+ end
+
def test_group_filter
q = UserQuery.new name: '_'
q.add_filter('is_member_of_group', '=', ['10', '99'])