From 6e584774c435067b8290d2119d84541239de178e Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Thu, 25 Jan 2024 12:57:08 +0000 Subject: [PATCH] Merged r22623, r22624 and r22625 from trunk to 5.1-stable (#40099). git-svn-id: https://svn.redmine.org/redmine/branches/5.1-stable@22632 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/users_controller.rb | 4 ++-- app/models/user_query.rb | 2 +- test/integration/api_test/users_test.rb | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 067564bd3..2c274091b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -47,8 +47,8 @@ class UsersController < ApplicationController # API backwards compatibility: handle legacy filter parameters unless request.format.html? - if status_id = params[:status].presence - @query.add_filter 'status', '=', [status_id] + if params.include?(:status) && params[:status].blank? + @query.add_filter 'status', '*' end if name = params[:name].presence @query.add_filter 'name', '~', [name] diff --git a/app/models/user_query.rb b/app/models/user_query.rb index cd3a5172b..d300bd850 100644 --- a/app/models/user_query.rb +++ b/app/models/user_query.rb @@ -40,7 +40,7 @@ class UserQuery < Query def initialize_available_filters add_available_filter "status", - type: :list, values: ->{ user_statuses_values } + type: :list_optional, values: ->{ user_statuses_values } add_available_filter "auth_source_id", type: :list_optional, values: ->{ auth_sources_values } add_available_filter "is_member_of_group", diff --git a/test/integration/api_test/users_test.rb b/test/integration/api_test/users_test.rb index 1a1682f32..2020b1644 100644 --- a/test/integration/api_test/users_test.rb +++ b/test/integration/api_test/users_test.rb @@ -90,6 +90,20 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base users = User.where(status: 3) assert_equal users.size, json['users'].size + get '/users.json', headers: credentials('admin'), params: { status: '*' } + assert_response :success + json = ActiveSupport::JSON.decode(response.body) + assert json.key?('users') + users = User.logged + assert_equal users.size, json['users'].size + + get '/users.json', headers: credentials('admin'), params: { status: ''} + assert_response :success + json = ActiveSupport::JSON.decode(response.body) + assert json.key?('users') + users = User.logged + 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) @@ -120,6 +134,15 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base assert_equal 0, json['users'].size end + test "GET /users.json with short filters" do + get '/users.json', headers: credentials('admin'), params: { status: "1|3" } + assert_response :success + json = ActiveSupport::JSON.decode(response.body) + assert json.key?('users') + users = User.where(status: [1,3]) + assert_equal users.size, 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 -- 2.39.5