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
Merge remote-tracking branch 'origin/dev' into implementation/38884-notifications-send-out-mention-mail-on-mentioning
ulfertsaff788bdf6b0
diff --cc app/helpers/mail_digest_helper.rbindex 5dd649a6c02,af7ad9b6052..3b6afe1309e--- a/app/helpers/mail_digest_helper.rb+++ b/app/helpers/mail_digest_helper.rb@@@ -52,10 -52,10 +52,10 @@@ module MailDigestHelpeenddef digest_comment_text(notification)- if notification.reason_mail_digest === "mentioned"+ if notification.reason_mentioned?- sanitize I18n.t(:'mail.digests.work_packages.mentioned')+ sanitize I18n.t(:'mail.work_packages.mentioned')else- sanitize I18n.t(:'mail.digests.work_packages.comment_added')+ sanitize I18n.t(:'mail.work_packages.comment_added')endend@@@ -65,14 -65,14 +65,14 @@@value = journal.initial? ? "created" : "updated"if extendedsanitize(- "#{I18n.t(:"mail.digests.work_packages.#{value}")} #{I18n.t(:"mail.digests.work_packages.#{value}_at",- user: user,- timestamp: journal.created_at.strftime(- I18n.t(:'time.formats.time')- ))}"+ "#{I18n.t(:"mail.work_packages.#{value}")} #{I18n.t(:"mail.work_packages.#{value}_at",- user: user,- timestamp: journal.created_at.strftime(- I18n.t(:'time.formats.time')- ))}"++ user: user,++ timestamp: journal.created_at.strftime(++ I18n.t(:'time.formats.time')++ ))}")else- sanitize(I18n.t(:"mail.digests.work_packages.#{value}_at",+ sanitize(I18n.t(:"mail.work_packages.#{value}_at",user: user,timestamp: journal.created_at.strftime(I18n.t(:'time.formats.time'))))enddiff --cc app/services/notifications/mail_service/comment_strategy.rbindex 1f6997f5379,41dc42bfd4c..7ac3701cc69--- a/app/services/notifications/mail_service/comment_strategy.rb+++ b/app/services/notifications/mail_service/comment_strategy.rb@@@ -32,9 -32,10 +32,9 @@@ module Notifications::MailService::CommUserMailer.news_comment_added(notification.recipient,- notification.resource,- notification.resource.author || DeletedUser.first+ notification.resource)- .deliver_later+ .deliver_nowendendenddiff --cc app/services/notifications/mail_service/message_strategy.rbindex 9cae28b41ef,93381c3782b..a09e5d8b141--- a/app/services/notifications/mail_service/message_strategy.rb+++ b/app/services/notifications/mail_service/message_strategy.rb@@@ -32,9 -32,10 +32,9 @@@ module Notifications::MailService::MessUserMailer.message_posted(notification.recipient,- notification.resource,- notification.actor || DeletedUser.first+ notification.resource)- .deliver_later+ .deliver_nowendendenddiff --cc app/services/notifications/mail_service/news_strategy.rbindex ed44f33845c,0ca31ee7aff..cb2aebfbf17--- a/app/services/notifications/mail_service/news_strategy.rb+++ b/app/services/notifications/mail_service/news_strategy.rb@@@ -34,9 -34,10 +34,9 @@@ module Notifications::MailService::NewsUserMailer.news_added(notification.recipient,- notification.journal.journable,- notification.journal.user || DeletedUser.first+ notification.journal.journable)- .deliver_later+ .deliver_nowendendenddiff --cc app/services/notifications/mail_service/wiki_content_strategy.rbindex aa575260b82,005908d8343..a0013eca805--- a/app/services/notifications/mail_service/wiki_content_strategy.rb+++ b/app/services/notifications/mail_service/wiki_content_strategy.rb@@@ -34,8 -34,9 +34,8 @@@ module Notifications::MailService::WikiUserMailer.send(method,notification.recipient,- notification.journal.journable,- notification.journal.user || DeletedUser.first)+ notification.journal.journable)- .deliver_later+ .deliver_nowendprivatediff --cc app/services/notifications/mail_service/work_package_strategy.rbindex 143f6eb11ce,00000000000..10f309192a7mode 100644,000000..100644--- a/app/services/notifications/mail_service/work_package_strategy.rb+++ b/app/services/notifications/mail_service/work_package_strategy.rb@@@ -1,40 -1,0 +1,40 @@@+#-- 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.+#++++module Notifications::MailService::WorkPackageStrategy+ class << self+ def send_mail(notification)- return unless notification.ian_mentioned?++ return unless notification.reason_mentioned?+ return unless notification.recipient.pref.immediate_reminders[:mentioned]++ WorkPackageMailer+ .mentioned(notification.recipient, notification.journal)+ .deliver_later+ end+ end+enddiff --cc app/workers/notifications/workflow_job.rbindex f2c68968025,dcb983dd2c0..ff13f869e6d--- a/app/workers/notifications/workflow_job.rb+++ b/app/workers/notifications/workflow_job.rb@@@ -52,21 -52,10 +52,21 @@@ class Notifications::WorkflowJob < Applstate :create_notifications,to: :send_mails do |resource, send_notification|- Notifications::CreateFromModelService- .new(resource)- .call(send_notification)- .all_results+ mentioned, delayed = Notifications::CreateFromModelService+ .new(resource)+ .call(send_notification)+ .all_results- .partition(&:mail_mentioned?)++ .partition(&:reason_mentioned?)++ mentioned- .select { |n| n.read_mail == false }++ .select { |n| n.mail_alert_sent == false }+ .each do |notification|+ Notifications::MailService+ .new(notification)+ .call+ end++ delayed.map(&:id)enddiff --cc spec/features/notifications/immediate_reminder_spec.rbindex 1c38b3df755,a148016a237..2d173435a2c--- a/spec/features/notifications/immediate_reminder_spec.rb+++ b/spec/features/notifications/immediate_reminder_spec.rb@@@ -50,56 -50,4 +50,54 @@@ describe "Immediate reminder settings"it_behaves_like 'immediate reminder settings'end++ describe 'email sending', js: false do+ let(:project) { FactoryBot.create(:project) }+ let(:work_package) { FactoryBot.create(:work_package, project: project) }+ let(:receiver) do+ FactoryBot.create(+ :user,+ preferences: {+ immediate_reminders: {+ mentioned: true+ }+ },+ notification_settings: [- FactoryBot.build(:in_app_notification_setting,- mentioned: true),- FactoryBot.build(:mail_notification_setting,++ FactoryBot.build(:notification_setting,+ mentioned: true)+ ],+ member_in_project: project,+ member_with_permissions: %i[view_work_packages]+ )+ end++ current_user do+ FactoryBot.create(:user)+ end++ it 'sends a mail to the mentioned user immediately' do+ perform_enqueued_jobs do+ note = <<~NOTE+ Hey <mention class=\"mention\"+ data-id=\"#{receiver.id}\"+ data-type=\"user\"+ data-text=\"@#{receiver.name}\">+ @#{receiver.name}+ </mention>+ NOTE++ work_package.add_journal(current_user, note)+ work_package.save!+ end++ expect(ActionMailer::Base.deliveries.length)+ .to be 1++ expect(ActionMailer::Base.deliveries.first.subject)+ .to eql I18n.t(:'mail.mention.subject',+ user_name: current_user.name,+ id: work_package.id,+ subject: work_package.subject)+ end+ endenddiff --cc spec/services/notifications/mail_service_spec.rbindex 89029307198,a22d18c3100..c632ba3d6af--- a/spec/services/notifications/mail_service_spec.rb+++ b/spec/services/notifications/mail_service_spec.rb@@@ -46,84 -40,6 +46,84 @@@ describe Notifications::MailService, tyFactoryBot.build_stubbed(:user)endlet(:instance) { described_class.new(notification) }+ let(:immediate_reminders_mentioned) { true }++ context 'with a work package journal notification' do+ let(:journal) do+ FactoryBot.build_stubbed(:work_package_journal).tap do |j|+ allow(j)+ .to receive(:initial?)+ .and_return(journal_initial)+ end+ end+ let(:read_ian) { false }- let(:reason_ian) { :mentioned }++ let(:reason) { :mentioned }+ let(:notification) do+ FactoryBot.build_stubbed(:notification,+ journal: journal,+ recipient: recipient,+ actor: actor,- reason_ian: reason_ian,++ reason: reason,+ read_ian: read_ian)+ end+ let(:journal_initial) { false }++ let(:mail) do+ mail = instance_double(ActionMailer::MessageDelivery)++ allow(WorkPackageMailer)+ .to receive(:mentioned)+ .and_return(mail)++ allow(mail)+ .to receive(:deliver_later)++ end++ before do+ end++ shared_examples_for 'sends a mentioned mail' do+ it 'sends a mail' do+ call++ expect(WorkPackageMailer)+ .to have_received(:mentioned)+ .with(recipient,+ journal)++ expect(mail)+ .to have_received(:deliver_later)+ end+ end++ shared_examples_for 'sends no mentioned mail' do+ it 'sends no mail' do+ call++ expect(WorkPackageMailer)+ .not_to have_received(:mentioned)+ end+ end++ context 'with the notification mentioning the user' do+ it_behaves_like 'sends a mentioned mail'+ end++ context 'with the notification not mentioning the user' do- let(:reason_ian) { false }++ let(:reason) { false }++ it_behaves_like 'sends no mentioned mail'+ end++ context 'with the notification mentioning the user but with the recipient having deactivated the mail' do+ let(:immediate_reminders_mentioned) { false }++ it_behaves_like 'sends no mentioned mail'+ end+ endcontext 'with a wiki_content journal notification' dolet(:journal) do@@@ -174,10 -90,11 +174,10 @@@expect(UserMailer).to have_received(:wiki_content_added).with(recipient,- journal.journable,- journal.user)+ journal.journable)expect(mail)- .to have_received(:deliver_later)+ .to have_received(:deliver_now)endend@@@ -190,10 -107,11 +190,10 @@@expect(UserMailer).to have_received(:wiki_content_updated).with(recipient,- journal.journable,- journal.user)+ journal.journable)expect(mail)- .to have_received(:deliver_later)+ .to have_received(:deliver_now)endend@@@ -253,10 -171,11 +253,10 @@@expect(UserMailer).to have_received(:news_added).with(recipient,- journal.journable,- journal.user)+ journal.journable)expect(mail)- .to have_received(:deliver_later)+ .to have_received(:deliver_now)endend@@@ -311,10 -230,11 +311,10 @@@expect(UserMailer).to have_received(:message_posted).with(recipient,- journal.journable,- actor)+ journal.journable)expect(mail)- .to have_received(:deliver_later)+ .to have_received(:deliver_now)endcontext 'with the notification read in app already' dodiff --cc spec/workers/notifications/workflow_job_spec.rbindex b8e9d378a66,c10f630cc0c..c58bae9ad47--- a/spec/workers/notifications/workflow_job_spec.rb+++ b/spec/workers/notifications/workflow_job_spec.rb@@@ -38,13 -38,8 +38,13 @@@ describe Notifications::WorkflowJob, tylet(:send_notification) { true }let(:notifications) do- [FactoryBot.build_stubbed(:notification, reason_ian: :assigned, reason_mail: :assigned),- [FactoryBot.build_stubbed(:notification),- FactoryBot.build_stubbed(:notification)]++ [FactoryBot.build_stubbed(:notification, reason: :assigned),+ mentioned_notification,- FactoryBot.build_stubbed(:notification, reason_ian: :watched, reason_mail: :watched)]++ FactoryBot.build_stubbed(:notification, reason: :watched)]+ end++ let(:mentioned_notification) do- FactoryBot.build_stubbed(:notification, reason_ian: :mentioned, reason_mail: :mentioned)++ FactoryBot.build_stubbed(:notification, reason: :mentioned)enddescribe '#perform' do