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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
introduce resourceId and resourceType filter
ulferts34467120c32e
diff --git a/app/models/queries/notifications.rb b/app/models/queries/notifications.rbindex 40143482e51..a7b7acdf978 100644--- a/app/models/queries/notifications.rb+++ b/app/models/queries/notifications.rb@@ -29,18 +29,18 @@#++module Queries::Notifications- Queries::Register.filter Queries::Notifications::NotificationQuery,- Queries::Notifications::Filters::ReadIanFilter+ [Queries::Notifications::Filters::ReadIanFilter,+ Queries::Notifications::Filters::IdFilter,+ Queries::Notifications::Filters::ResourceIdFilter,+ Queries::Notifications::Filters::ResourceTypeFilter].each do |filter|+ Queries::Register.filter Queries::Notifications::NotificationQuery,+ filter+ end- Queries::Register.filter Queries::Notifications::NotificationQuery,- Queries::Notifications::Filters::IdFilter-- Queries::Register.order Queries::Notifications::NotificationQuery,- Queries::Notifications::Orders::DefaultOrder-- Queries::Register.order Queries::Notifications::NotificationQuery,- Queries::Notifications::Orders::ReasonOrder-- Queries::Register.order Queries::Notifications::NotificationQuery,- Queries::Notifications::Orders::ReadIanOrder+ [Queries::Notifications::Orders::DefaultOrder,+ Queries::Notifications::Orders::ReasonOrder,+ Queries::Notifications::Orders::ReadIanOrder].each do |order|+ Queries::Register.order Queries::Notifications::NotificationQuery,+ order+ endenddiff --git a/app/models/queries/notifications/filters/resource_id_filter.rb b/app/models/queries/notifications/filters/resource_id_filter.rbnew file mode 100644index 00000000000..80f369d733b--- /dev/null+++ b/app/models/queries/notifications/filters/resource_id_filter.rb@@ -0,0 +1,41 @@+#-- 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::Notifications::Filters::ResourceIdFilter < Queries::Notifications::Filters::NotificationFilter+ def allowed_values+ WorkPackage+ .visible(User.current)+ .pluck(:id, :id)+ end++ def type+ :list+ end+enddiff --git a/app/models/queries/notifications/filters/resource_type_filter.rb b/app/models/queries/notifications/filters/resource_type_filter.rbnew file mode 100644index 00000000000..f49164354b5--- /dev/null+++ b/app/models/queries/notifications/filters/resource_type_filter.rb@@ -0,0 +1,39 @@+#-- 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::Notifications::Filters::ResourceTypeFilter < Queries::Notifications::Filters::NotificationFilter+ def allowed_values+ [[WorkPackage.name, WorkPackage.name]]+ end++ def type+ :list+ end+enddiff --git a/spec/requests/api/v3/notifications/index_resource_spec.rb b/spec/requests/api/v3/notifications/index_resource_spec.rbindex 3d7093da8ed..9d1ac2f76d7 100644--- a/spec/requests/api/v3/notifications/index_resource_spec.rb+++ b/spec/requests/api/v3/notifications/index_resource_spec.rb@@ -37,9 +37,14 @@ describe ::API::V3::Notifications::NotificationsAPI,include API::V3::Utilities::PathHelper- shared_let(:recipient) { FactoryBot.create :user }- shared_let(:notification1) { FactoryBot.create :notification, recipient: recipient }- shared_let(:notification2) { FactoryBot.create :notification, recipient: recipient }+ shared_let(:work_package) { FactoryBot.create :work_package }+ shared_let(:recipient) do+ FactoryBot.create :user,+ member_in_project: work_package.project,+ member_with_permissions: %i[view_work_packages]+ end+ shared_let(:notification1) { FactoryBot.create :notification, recipient: recipient, resource: work_package }+ shared_let(:notification2) { FactoryBot.create :notification, recipient: recipient, resource: work_package }let(:notifications) { [notification1, notification2] }@@ -96,6 +101,34 @@ describe ::API::V3::Notifications::NotificationsAPI,endendend++ context 'with a resource filter' do+ let(:notification3) { FactoryBot.create :notification, recipient: recipient }+ let(:notifications) { [notification1, notification2, notification3] }++ let(:filters) do+ [+ {+ 'resourceId' => {+ 'operator' => '=',+ 'values' => [work_package.id.to_s]+ }+ },+ {+ 'resourceType' => {+ 'operator' => '=',+ 'values' => [WorkPackage.name.to_s]+ }+ }+ ]+ end++ context 'with the filter being set to false' do+ it_behaves_like 'API V3 collection response', 2, 2, 'Notification' do+ let(:elements) { [notification2, notification1] }+ end+ end+ endenddescribe 'admin user' do