diff options
author | Go MAEDA <maeda@farend.jp> | 2023-10-15 01:42:07 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2023-10-15 01:42:07 +0000 |
commit | ff93ee3cfaf4aae92e826c8e879e1bb648c0dddd (patch) | |
tree | b1b723612da5549ff0e2e2380f87ed340b839e08 /app/models/user_query.rb | |
parent | 26c392d3c368af689df8c0c95863e3e0298d462a (diff) | |
download | redmine-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 'app/models/user_query.rb')
-rw-r--r-- | app/models/user_query.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/app/models/user_query.rb b/app/models/user_query.rb index 477c071e0..dbbb0eccb 100644 --- a/app/models/user_query.rb +++ b/app/models/user_query.rb @@ -51,6 +51,7 @@ class UserQuery < Query type: :list_optional, values: ->{ Redmine::Twofa.available_schemes.map {|s| [I18n.t("twofa__#{s}__name"), s] } } end + add_available_filter "name", type: :text, label: :field_name_or_email_or_login add_available_filter "login", type: :string add_available_filter "firstname", type: :string add_available_filter "lastname", type: :string @@ -165,4 +166,31 @@ class UserQuery < Query joins.any? ? joins.join(' ') : nil end + + def sql_for_name_field(field, operator, value) + case operator + when '*' + '1=1' + when '!*' + '1=0' + else + # match = (operator == '~') + match = !operator.start_with?('!') + matching_operator = operator.sub /^\!/, '' + name_sql = %w(login firstname lastname).map{|field| sql_for_field(:name, operator, value, User.table_name, field)} + + emails = EmailAddress.table_name + email_sql = <<-SQL + #{match ? "EXISTS" : "NOT EXISTS"} + (SELECT 1 FROM #{emails} WHERE + #{emails}.user_id = #{User.table_name}.id AND + #{sql_for_field(:name, matching_operator, value, emails, 'address')}) + SQL + + conditions = name_sql + [email_sql] + op = match ? " OR " : " AND " + "(#{conditions.map{|s| "(#{s})"}.join(op)})" + end + + end end |