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

adding project filter to notifications api

ulferts96c792c0c32d
diff --git a/app/models/queries/notifications.rb b/app/models/queries/notifications.rb
index 03381508756..82863fc2b02 100644
--- a/app/models/queries/notifications.rb
+++ b/app/models/queries/notifications.rb
@@ -31,6 +31,7 @@
module Queries::Notifications
[Queries::Notifications::Filters::ReadIanFilter,
Queries::Notifications::Filters::IdFilter,
+ Queries::Notifications::Filters::ProjectFilter,
Queries::Notifications::Filters::ResourceIdFilter,
Queries::Notifications::Filters::ResourceTypeFilter].each do |filter|
Queries::Register.filter Queries::Notifications::NotificationQuery,
diff --git a/app/models/queries/notifications/filters/project_filter.rb b/app/models/queries/notifications/filters/project_filter.rb
new file mode 100644
index 00000000000..e9762d7c51b
--- /dev/null
+++ b/app/models/queries/notifications/filters/project_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 COPYRIGHT and LICENSE files for more details.
+#++
+
+class Queries::Notifications::Filters::ProjectFilter < Queries::Notifications::Filters::NotificationFilter
+ include Queries::Filters::Shared::ProjectFilter
+end
diff --git a/spec/requests/api/v3/notifications/index_resource_spec.rb b/spec/requests/api/v3/notifications/index_resource_spec.rb
index b71ce7175a0..94bbd87004d 100644
--- a/spec/requests/api/v3/notifications/index_resource_spec.rb
+++ b/spec/requests/api/v3/notifications/index_resource_spec.rb
@@ -140,6 +140,32 @@ describe ::API::V3::Notifications::NotificationsAPI,
end
end
+ context 'with a project filter' do
+ let(:other_work_package) { FactoryBot.create(:work_package) }
+ let(:notification3) do
+ FactoryBot.create :notification,
+ recipient: recipient,
+ resource: other_work_package,
+ project: other_work_package.project
+ end
+ let(:notifications) { [notification1, notification2, notification3] }
+
+ let(:filters) do
+ [
+ {
+ 'project' => {
+ 'operator' => '=',
+ 'values' => [work_package.project_id.to_s]
+ }
+ }
+ ]
+ end
+
+ it_behaves_like 'API V3 collection response', 2, 2, 'Notification' do
+ let(:elements) { [notification2, notification1] }
+ end
+ end
+
context 'with a reason groupBy' do
let(:responsible_notification) { FactoryBot.create :notification, recipient: recipient, reason_ian: :responsible }