Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Add any name attribute filter to principal resource collection (#9170)

Benjamin Bädorf3f3e831f6a85
diff --git a/app/models/queries/principals.rb b/app/models/queries/principals.rb
index 1b29e433c67..fd3c3d6a8ac 100644
--- a/app/models/queries/principals.rb
+++ b/app/models/queries/principals.rb
@@ -38,6 +38,7 @@ module Queries::Principals
register.filter query, filters::MemberFilter
register.filter query, filters::StatusFilter
register.filter query, filters::NameFilter
+ register.filter query, filters::AnyNameAttributeFilter
register.filter query, filters::IdFilter
register.order query, orders::NameOrder
diff --git a/app/models/queries/principals/filters/any_name_attribute_filter.rb b/app/models/queries/principals/filters/any_name_attribute_filter.rb
new file mode 100644
index 00000000000..226e6843aa7
--- /dev/null
+++ b/app/models/queries/principals/filters/any_name_attribute_filter.rb
@@ -0,0 +1,33 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+class Queries::Principals::Filters::AnyNameAttributeFilter < Queries::Principals::Filters::NameFilter
+ include Queries::Filters::Shared::AnyUserNameAttributeFilter
+end
diff --git a/docs/api/apiv3/endpoints/principals.apib b/docs/api/apiv3/endpoints/principals.apib
index 23bf1c1cb84..20f8f479a72 100644
--- a/docs/api/apiv3/endpoints/principals.apib
+++ b/docs/api/apiv3/endpoints/principals.apib
@@ -148,6 +148,7 @@ List all principals. The client can choose to filter the principals similar to h
+ type: filters principals by their type (*User*, *Group*, *PlaceholderUser*).
+ member: filters principals by the projects they are members in.
+ name: filters principals by the user or group name.
+ + any_name_attribute: filters principals by the user or group first- and last name, email or login.
+ status: filters principals by their status number (active = *1*, registered = *2*, locked = *3*, invited = *4*)
+ Response 200 (application/hal+json)
diff --git a/spec/requests/api/v3/principals/principals_resource_spec.rb b/spec/requests/api/v3/principals/principals_resource_spec.rb
index 888fbbd27a2..5327317266d 100644
--- a/spec/requests/api/v3/principals/principals_resource_spec.rb
+++ b/spec/requests/api/v3/principals/principals_resource_spec.rb
@@ -60,7 +60,8 @@ describe 'API v3 Principals resource', type: :request do
user = FactoryBot.create(:user,
member_in_project: project,
member_through_role: role,
- lastname: 'Aaaa')
+ lastname: 'Aaaa',
other_project.add_member! user, role
@@ -172,5 +173,15 @@ describe 'API v3 Principals resource', type: :request do
let(:response) { last_response }
end
end
+
+ context 'provide filter for any name attribute' do
+ let(:filter) do
+ [{ any_name_attribute: { operator: '~', values: ['[email protected]'] } }]
+ end
+
+ it_behaves_like 'API V3 collection response', 1, 1, 'User' do
+ let(:response) { last_response }
+ end
+ end
end
end
diff --git a/spec/support/components/work_packages/columns.rb b/spec/support/components/work_packages/columns.rb
index fcb4a9867a8..f5023d34bc8 100644
--- a/spec/support/components/work_packages/columns.rb
+++ b/spec/support/components/work_packages/columns.rb
@@ -26,6 +26,8 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
+require_relative '../ng_select_autocomplete_helpers'
+
module Components
module WorkPackages
class Columns