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
avoid setting actor and journal on date alert notifications
ulfertsa8c307debd81
diff --git a/lib/open_project/patches/factory_bot_evaluator.rb b/lib/open_project/patches/factory_bot_evaluator.rbnew file mode 100644index 00000000000..13dbc07438f--- /dev/null+++ b/lib/open_project/patches/factory_bot_evaluator.rb@@ -0,0 +1,37 @@+# --copyright+# OpenProject is an open source project management software.+# Copyright (C) 2022 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.+# ++++module OpenProject::Patches+ module FactoryBotEvaluator+ attr_reader :overrides+ end+end++if defined?(FactoryBot::Evaluator)+ FactoryBot::Evaluator.prepend OpenProject::Patches::FactoryBotEvaluator+enddiff --git a/spec/factories/notification_factory.rb b/spec/factories/notification_factory.rbindex b61f39a6e0b..b942d6c7279 100644--- a/spec/factories/notification_factory.rb+++ b/spec/factories/notification_factory.rb@@ -6,14 +6,20 @@ FactoryBot.define domail_alert_sent { false }reason { :mentioned }recipient factory: :user- project { association :project }+ projectresource { association :work_package, project: }- actor { nil }- journal { nil }+ # journal and actor are not listed by intend.+ # They will be set in the after_build callback.+ # But not listing them allows to identify if they have been provided, even if nil has been provided.- callback(:after_build) do |notification, _|- notification.journal ||= notification.resource.journals.last- notification.actor ||= notification.journal.try(:user)+ callback(:after_build) do |notification, evaluator|+ # Default the journal and the actor associations but only if:+ # * it is not a date alert+ # * the values haven't been overridden (including setting them to nil).+ unless notification.reason_date_alert_due_date? || notification.reason_date_alert_start_date?+ notification.journal ||= notification.resource.journals.last unless evaluator.overrides.key?(:journal)+ notification.actor ||= notification.journal.try(:user) unless evaluator.overrides.key?(:actor)+ endendendenddiff --git a/spec/features/notifications/notification_center/notification_center_spec.rb b/spec/features/notifications/notification_center/notification_center_spec.rbindex 5360552af0f..222f09d4ed6 100644--- a/spec/features/notifications/notification_center/notification_center_spec.rb+++ b/spec/features/notifications/notification_center/notification_center_spec.rb@@ -196,8 +196,6 @@ describe "Notification center", js: true, with_settings: { journal_aggregation_trecipient:,resource: starting_soon_work_package,project: project1,- actor: nil,- journal: nil,read_ian: false)endlet(:due_date_notification) do@@ -206,8 +204,6 @@ describe "Notification center", js: true, with_settings: { journal_aggregation_trecipient:,resource: ending_soon_work_package,project: project1,- actor: nil,- journal: nil,read_ian: false)endlet(:overdue_date_notification) do@@ -216,8 +212,6 @@ describe "Notification center", js: true, with_settings: { journal_aggregation_trecipient:,resource: overdue_work_package,project: project1,- actor: nil,- journal: nil,read_ian: false)enddiff --git a/spec/requests/api/v3/notifications/index_resource_spec.rb b/spec/requests/api/v3/notifications/index_resource_spec.rbindex 36f1b5ed9e3..66aeb584daa 100644--- a/spec/requests/api/v3/notifications/index_resource_spec.rb+++ b/spec/requests/api/v3/notifications/index_resource_spec.rb@@ -50,9 +50,7 @@ describe ::API::V3::Notifications::NotificationsAPI,recipient:,reason: :date_alert_start_date,resource: work_package,- project: work_package.project,- journal: nil,- actor: nil)+ project: work_package.project)endlet(:filters) { nil }@@ -250,9 +248,7 @@ describe ::API::V3::Notifications::NotificationsAPI,recipient:,reason: :date_alert_due_date,resource: work_package,- project: work_package.project,- journal: nil,- actor: nil)+ project: work_package.project)endlet(:send_request) do@@ -337,7 +333,7 @@ describe ::API::V3::Notifications::NotificationsAPI,it_behaves_like 'API V3 collection response', 0, 0, 'Notification'end- describe 'as an anyonymous user' do+ describe 'as an anonymous user' dolet(:current_user) { User.anonymous }it 'returns a 403 response' do