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
Fix setting of mail_reminder and mail_alert in create_from_model_service
Oliver Günther18e4c37cf380
diff --git a/app/services/notifications/create_from_model_service.rb b/app/services/notifications/create_from_model_service.rbindex 474d845a000..d72488b1b2d 100644--- a/app/services/notifications/create_from_model_service.rb+++ b/app/services/notifications/create_from_model_service.rb@@ -69,7 +69,8 @@ class Notifications::CreateFromModelServiceactor: user_with_fallback,reason: reasons.first,read_ian: false,- mail_reminder_sent: false+ mail_reminder_sent: strategy.supports_mail_digest? ? false : nil,+ mail_alert_sent: strategy.supports_mail? ? false : nil}Notifications::CreateServicediff --git a/modules/documents/spec/services/notifications/create_from_model_service_document_spec.rb b/modules/documents/spec/services/notifications/create_from_model_service_document_spec.rbindex 27dac200425..7d59d2bf342 100644--- a/modules/documents/spec/services/notifications/create_from_model_service_document_spec.rb+++ b/modules/documents/spec/services/notifications/create_from_model_service_document_spec.rb@@ -63,7 +63,8 @@ describe Notifications::CreateFromModelService, 'document', with_settings: { jou{read_ian: false,reason: :subscribed,- mail_reminder_sent: false+ mail_alert_sent: false,+ mail_reminder_sent: nil}endend@@ -110,7 +111,8 @@ describe Notifications::CreateFromModelService, 'document', with_settings: { jou{read_ian: false,reason: :subscribed,- mail_reminder_sent: false+ mail_alert_sent: false,+ mail_reminder_sent: nil}endenddiff --git a/spec/factories/notification_factory.rb b/spec/factories/notification_factory.rbindex 70e310cdee7..32fada51a40 100644--- a/spec/factories/notification_factory.rb+++ b/spec/factories/notification_factory.rb@@ -3,7 +3,7 @@ FactoryBot.define dosubject { "MyText" } # rubocop:disable RSpec/EmptyLineAfterSubjectread_ian { false }mail_reminder_sent { false }- alert_reminder_sent { false }+ mail_alert_sent { false }reason { :mentioned }recipient factory: :userproject { association :project }diff --git a/spec/features/forums/message_spec.rb b/spec/features/forums/message_spec.rbindex 07a7c774886..ce7916d01cb 100644--- a/spec/features/forums/message_spec.rb+++ b/spec/features/forums/message_spec.rb@@ -33,17 +33,27 @@ describe 'messages', type: :feature, js: true doFactoryBot.create(:forum)end+ let(:notification_settings_all_false) do+ NotificationSetting+ .all_settings+ .index_with(false)+ end+let(:user) doFactoryBot.create :user,member_in_project: forum.project,member_through_role: role,- notification_settings: [FactoryBot.build(:notification_setting, all: false)]+ notification_settings: [+ FactoryBot.build(:notification_setting, **notification_settings_all_false, watched: true)+ ]endlet(:other_user) doFactoryBot.create(:user,member_in_project: forum.project,member_through_role: role,- notification_settings: [FactoryBot.build(:notification_setting, all: false)]).tap do |u|+ notification_settings: [+ FactoryBot.build(:notification_setting, **notification_settings_all_false, watched: true)+ ]).tap do |u|forum.watcher_users << uendenddiff --git a/spec/features/notifications/reminder_mail_spec.rb b/spec/features/notifications/reminder_mail_spec.rbindex b34dfb59a87..880c04729f2 100644--- a/spec/features/notifications/reminder_mail_spec.rb+++ b/spec/features/notifications/reminder_mail_spec.rb@@ -90,7 +90,7 @@ describe "Reminder email", type: :feature, js: true do}},notification_settings: [- FactoryBot.build(:mail_digest_notification_setting,+ FactoryBot.build(:notification_setting,involved: true,watched: true,mentioned: true,@@ -98,8 +98,7 @@ describe "Reminder email", type: :feature, js: true dowork_package_created: true,work_package_processed: true,work_package_prioritized: true,- work_package_scheduled: true,- all: false)+ work_package_scheduled: true)])enddiff --git a/spec/features/users/notifications/shared_examples.rb b/spec/features/users/notifications/shared_examples.rbindex c1f7d2db3cd..252669f642f 100644--- a/spec/features/users/notifications/shared_examples.rb+++ b/spec/features/users/notifications/shared_examples.rb@@ -35,18 +35,18 @@ shared_examples 'notification settings workflow' douser.reloadnotification_settings = user.notification_settings- expect(notification_settings.count).to eq 9- expect(notification_settings.where(project: project).count).to eq 3-- in_app = notification_settings.find_by(project: project)- expect(in_app.involved).to be_truthy- expect(in_app.mentioned).to be_truthy- expect(in_app.watched).to be_truthy- expect(in_app.work_package_commented).to be_falsey- expect(in_app.work_package_created).to be_falsey- expect(in_app.work_package_processed).to be_falsey- expect(in_app.work_package_prioritized).to be_falsey- expect(in_app.work_package_scheduled).to be_falsey+ expect(notification_settings.count).to eq 3+ expect(notification_settings.where(project: project).count).to eq 1++ project_settings = notification_settings.find_by(project: project)+ expect(project_settings.involved).to be_truthy+ expect(project_settings.mentioned).to be_truthy+ expect(project_settings.watched).to be_truthy+ expect(project_settings.work_package_commented).to be_falsey+ expect(project_settings.work_package_created).to be_falsey+ expect(project_settings.work_package_processed).to be_falsey+ expect(project_settings.work_package_prioritized).to be_falsey+ expect(project_settings.work_package_scheduled).to be_falsey# Trying to add the same project again will not be possible (Regression #38072)click_button 'Add setting for project'diff --git a/spec/mailers/digest_mailer_spec.rb b/spec/mailers/digest_mailer_spec.rbindex e807a4e89bd..6b7ff1b3675 100644--- a/spec/mailers/digest_mailer_spec.rb+++ b/spec/mailers/digest_mailer_spec.rb@@ -61,6 +61,7 @@ describe DigestMailer, type: :mailer dolet(:notifications) do[FactoryBot.build_stubbed(:notification,resource: work_package,+ reason: :commented,journal: journal,project: project1)].tap do |notifications|allow(Notification)diff --git a/spec/models/users/scopes/notified_on_all_spec.rb b/spec/models/users/scopes/notified_on_all_spec.rbdeleted file mode 100644index eee82acaed7..00000000000--- a/spec/models/users/scopes/notified_on_all_spec.rb+++ /dev/null@@ -1,125 +0,0 @@-#-- 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.-#++--require 'spec_helper'--describe Users::Scopes::NotifiedOnAll, type: :model do- describe '.notified_on_all' do- subject(:scope) { ::User.notified_on_all(project) }-- let!(:user) do- FactoryBot.create(:user,- notification_settings: notification_settings)- end- let!(:project) do- FactoryBot.create(:project)- end-- context 'when user is notified about everything' do- let(:notification_settings) do- [- FactoryBot.build(:notification_setting, all: true)- ]- end-- it 'includes the user' do- expect(scope)- .to match_array([user])- end-- context 'with in app notifications disabled' do- let(:notification_settings) do- [- FactoryBot.build(:notification_setting, all: true)- ]- end-- it 'includes the user' do- expect(scope)- .to match_array([user])- end- end-- context 'with mail notifications disabled' do- let(:notification_settings) do- [- FactoryBot.build(:notification_setting, all: false)- ]- end-- it 'includes the user' do- expect(scope)- .to match_array([user])- end- end-- context 'with all disabled' do- let(:notification_settings) do- [- FactoryBot.build(:notification_setting, all: false)- ]- end-- it 'is empty' do- expect(scope)- .to be_empty- end- end-- context 'with all disabled as a default but enabled in the project' do- let(:notification_settings) do- [- FactoryBot.build(:notification_setting, all: false),- FactoryBot.build(:notification_setting, project: project, all: true)- ]- end-- it 'includes the user' do- expect(scope)- .to match_array([user])- end- end-- context 'with all enabled as a default but disabled in the project' do- let(:notification_settings) do- [- FactoryBot.build(:notification_setting, all: true),- FactoryBot.build(:notification_setting, project: project, all: false)- ]- end-- it 'is empty' do- expect(scope)- .to be_empty- end- end- end- end-enddiff --git a/spec/services/notifications/create_from_model_service_comment_spec.rb b/spec/services/notifications/create_from_model_service_comment_spec.rbindex 663c8b0b1ba..88c25c4b7f4 100644--- a/spec/services/notifications/create_from_model_service_comment_spec.rb+++ b/spec/services/notifications/create_from_model_service_comment_spec.rb@@ -68,7 +68,8 @@ describe Notifications::CreateFromModelService, 'comment', with_settings: { jour{read_ian: false,reason: :subscribed,- mail_reminder_sent: false+ mail_reminder_sent: nil,+ mail_alert_sent: false}endend@@ -110,7 +111,8 @@ describe Notifications::CreateFromModelService, 'comment', with_settings: { jour{read_ian: false,reason: :watched,- mail_reminder_sent: false+ mail_reminder_sent: nil,+ mail_alert_sent: false}endenddiff --git a/spec/services/notifications/create_from_model_service_message_spec.rb b/spec/services/notifications/create_from_model_service_message_spec.rbindex 3700b3dee12..1f39558700c 100644--- a/spec/services/notifications/create_from_model_service_message_spec.rb+++ b/spec/services/notifications/create_from_model_service_message_spec.rb@@ -67,9 +67,10 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jourit_behaves_like 'creates notification' dolet(:notification_channel_reasons) do{- read_ian: nil,- reason: false,- mail_reminder_sent: nil+ read_ian: false,+ reason: :subscribed,+ mail_reminder_sent: nil,+ mail_alert_sent: false}endend@@ -109,9 +110,10 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jourit_behaves_like 'creates notification' dolet(:notification_channel_reasons) do{- read_ian: nil,- reason: false,- mail_reminder_sent: nil+ read_ian: false,+ reason: :watched,+ mail_reminder_sent: nil,+ mail_alert_sent: false}endend@@ -155,9 +157,10 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jourit_behaves_like 'creates notification' dolet(:notification_channel_reasons) do{- read_ian: nil,- reason: false,- mail_reminder_sent: nil+ read_ian: false,+ reason: :watched,+ mail_reminder_sent: nil,+ mail_alert_sent: false}endend@@ -196,9 +199,10 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jourit_behaves_like 'creates notification' dolet(:notification_channel_reasons) do{- read_ian: nil,- reason: false,- mail_reminder_sent: nil+ read_ian: false,+ reason: :subscribed,+ mail_reminder_sent: nil,+ mail_alert_sent: false}endend@@ -238,9 +242,10 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jourit_behaves_like 'creates notification' dolet(:notification_channel_reasons) do{- read_ian: nil,- reason: false,- mail_reminder_sent: nil+ read_ian: false,+ reason: :watched,+ mail_reminder_sent: nil,+ mail_alert_sent: false}endend@@ -284,9 +289,10 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jourit_behaves_like 'creates notification' dolet(:notification_channel_reasons) do{- read_ian: nil,- reason: false,- mail_reminder_sent: nil+ read_ian: false,+ reason: :watched,+ mail_reminder_sent: nil,+ mail_alert_sent: false}endenddiff --git a/spec/services/notifications/create_from_model_service_news_spec.rb b/spec/services/notifications/create_from_model_service_news_spec.rbindex c77c23bb190..7ce9da7e03f 100644--- a/spec/services/notifications/create_from_model_service_news_spec.rb+++ b/spec/services/notifications/create_from_model_service_news_spec.rb@@ -61,7 +61,8 @@ describe Notifications::CreateFromModelService, 'news', with_settings: { journal{read_ian: false,reason: :subscribed,- mail_reminder_sent: false+ mail_reminder_sent: nil,+ mail_alert_sent: false}endenddiff --git a/spec/services/notifications/create_from_model_service_wiki_spec.rb b/spec/services/notifications/create_from_model_service_wiki_spec.rbindex d6a758ce080..784f1c521b7 100644--- a/spec/services/notifications/create_from_model_service_wiki_spec.rb+++ b/spec/services/notifications/create_from_model_service_wiki_spec.rb@@ -65,9 +65,9 @@ describe Notifications::CreateFromModelService, 'wiki', with_settings: { journalit_behaves_like 'creates notification' dolet(:notification_channel_reasons) do{- read_ian: nil,- reason: false,- read_mail: false,+ read_ian: false,+ reason: :subscribed,+ mail_alert_sent: false,mail_reminder_sent: nil}end@@ -108,9 +108,9 @@ describe Notifications::CreateFromModelService, 'wiki', with_settings: { journalit_behaves_like 'creates notification' dolet(:notification_channel_reasons) do{- read_ian: nil,- reason: false,- read_mail: false,+ read_ian: false,+ reason: :watched,+ mail_alert_sent: false,mail_reminder_sent: nil}end@@ -158,8 +158,9 @@ describe Notifications::CreateFromModelService, 'wiki', with_settings: { journalit_behaves_like 'creates notification' dolet(:notification_channel_reasons) do{- read_ian: nil,- reason: false,+ read_ian: false,+ reason: :subscribed,+ mail_alert_sent: false,mail_reminder_sent: nil}end@@ -200,9 +201,10 @@ describe Notifications::CreateFromModelService, 'wiki', with_settings: { journalit_behaves_like 'creates notification' dolet(:notification_channel_reasons) do{- read_ian: nil,- reason: false,- mail_reminder_sent: nil+ read_ian: false,+ reason: :watched,+ mail_reminder_sent: nil,+ mail_alert_sent: false}endend@@ -246,8 +248,9 @@ describe Notifications::CreateFromModelService, 'wiki', with_settings: { journalit_behaves_like 'creates notification' dolet(:notification_channel_reasons) do{- read_ian: nil,- reason: false,+ read_ian: false,+ reason: :watched,+ mail_alert_sent: false,mail_reminder_sent: nil}enddiff --git a/spec/services/notifications/create_from_model_service_work_package_spec.rb b/spec/services/notifications/create_from_model_service_work_package_spec.rbindex 0ae9cfced59..72bde2d00fa 100644--- a/spec/services/notifications/create_from_model_service_work_package_spec.rb+++ b/spec/services/notifications/create_from_model_service_work_package_spec.rb@@ -114,6 +114,7 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :assigned,+ mail_alert_sent: false,mail_reminder_sent: false}end@@ -131,30 +132,13 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :assigned,+ mail_alert_sent: false,mail_reminder_sent: false}endendend- context 'assignee has mail notifications disabled' do- let(:recipient_notification_settings) do- [- FactoryBot.build(:notification_setting, **notification_settings_all_false)- ]- end-- it_behaves_like 'creates notification' do- let(:notification_channel_reasons) do- {- read_ian: false,- reason: :assigned,- mail_reminder_sent: nil- }- end- end- end-context 'assignee has all notifications disabled' dolet(:recipient_notification_settings) do[@@ -177,6 +161,7 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :assigned,+ mail_alert_sent: false,mail_reminder_sent: false}end@@ -220,47 +205,12 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :responsible,+ mail_alert_sent: false,mail_reminder_sent: false}endend- context 'when responsible has in app notifications disabled' do- let(:recipient_notification_settings) do- [- FactoryBot.build(:notification_setting, **notification_settings_all_false.merge(involved: false))- ]- end-- it_behaves_like 'creates notification' do- let(:notification_channel_reasons) do- {- read_ian: false,- reason: nil,- mail_reminder_sent: false- }- end- end- end-- context 'when responsible has mail notifications disabled' do- let(:recipient_notification_settings) do- [- FactoryBot.build(:notification_setting, **notification_settings_all_false)- ]- end-- it_behaves_like 'creates notification' do- let(:notification_channel_reasons) do- {- read_ian: false,- reason: :responsible,- mail_reminder_sent: nil- }- end- end- end-context 'when responsible has all notifications disabled' dolet(:recipient_notification_settings) do[@@ -308,6 +258,7 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :watched,+ mail_alert_sent: false,mail_reminder_sent: false}end@@ -325,30 +276,13 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :watched,+ mail_alert_sent: false,mail_reminder_sent: false}endendend- context 'when watcher has mail notifications disabled' do- let(:recipient_notification_settings) do- [- FactoryBot.build(:notification_setting, **notification_settings_all_false)- ]- end-- it_behaves_like 'creates notification' do- let(:notification_channel_reasons) do- {- read_ian: false,- reason: :watched,- mail_reminder_sent: nil- }- end- end- end-context 'when watcher has all notifications disabled' dolet(:recipient_notification_settings) do[@@ -391,6 +325,7 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :created,+ mail_alert_sent: false,mail_reminder_sent: false}end@@ -408,30 +343,13 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :created,+ mail_alert_sent: false,mail_reminder_sent: false}endendend- context 'with mail notifications disabled' do- let(:recipient_notification_settings) do- [- FactoryBot.build(:notification_setting, **notification_settings_all_false)- ]- end-- it_behaves_like 'creates notification' do- let(:notification_channel_reasons) do- {- read_ian: false,- reason: :created,- mail_reminder_sent: nil- }- end- end- end-context 'with all disabled' dolet(:recipient_notification_settings) do[@@ -455,6 +373,7 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :created,+ mail_alert_sent: false,mail_reminder_sent: false}end@@ -504,6 +423,7 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :created,+ mail_alert_sent: false,mail_reminder_sent: false}end@@ -559,6 +479,7 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :commented,+ mail_alert_sent: false,mail_reminder_sent: false}end@@ -607,6 +528,7 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :processed,+ mail_alert_sent: false,mail_reminder_sent: false}end@@ -655,6 +577,7 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :prioritized,+ mail_alert_sent: false,mail_reminder_sent: false}end@@ -703,6 +626,7 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :scheduled,+ mail_alert_sent: false,mail_reminder_sent: false}end@@ -751,6 +675,7 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :scheduled,+ mail_alert_sent: false,mail_reminder_sent: false}end@@ -783,6 +708,7 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :assigned,+ mail_alert_sent: false,mail_reminder_sent: false}end@@ -804,6 +730,7 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :mentioned,+ mail_alert_sent: false,mail_reminder_sent: false}end@@ -835,6 +762,7 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :mentioned,+ mail_alert_sent: false,mail_reminder_sent: false}end@@ -853,6 +781,7 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :mentioned,+ mail_alert_sent: false,mail_reminder_sent: false}end@@ -868,6 +797,7 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :mentioned,+ mail_alert_sent: false,mail_reminder_sent: false}end@@ -882,6 +812,7 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :mentioned,+ mail_alert_sent: false,mail_reminder_sent: false}end@@ -900,6 +831,7 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :mentioned,+ mail_alert_sent: false,mail_reminder_sent: false}end@@ -918,6 +850,7 @@ describe Notifications::CreateFromModelService,{read_ian: false,reason: :mentioned,+ mail_alert_sent: false,mail_reminder_sent: false}enddiff --git a/spec/services/users/set_attributes_service_spec.rb b/spec/services/users/set_attributes_service_spec.rbindex 9a41b298b03..fd03347762d 100644--- a/spec/services/users/set_attributes_service_spec.rb+++ b/spec/services/users/set_attributes_service_spec.rb@@ -88,7 +88,7 @@ describe Users::SetAttributesService, type: :model doit 'initalizes the notification settings' doexpect(call.result.notification_settings.length)- .to eql(3) # one for every channel+ .to be 1expect(call.result.notification_settings).to(all(be_a(NotificationSetting).and(be_new_record)))diff --git a/spec/support/pages/notifications/settings.rb b/spec/support/pages/notifications/settings.rbindex 89a9be4f877..196c45f651c 100644--- a/spec/support/pages/notifications/settings.rb+++ b/spec/support/pages/notifications/settings.rb@@ -37,6 +37,7 @@ module Pagesdef initialize(user)@user = user+ super()enddef path@@ -44,7 +45,7 @@ module Pagesenddef expect_represented- user.notification_settings.where(channel: :in_app).each do |setting|+ user.notification_settings.each do |setting|expect_global_represented(setting)# expect_project_represented(setting)end