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

prevent self notification unless activated

ulfertsc0452ca90e4c
diff --git a/app/services/notifications/journal_wp_notification_service.rb b/app/services/notifications/journal_wp_notification_service.rb
index 0679e24a7a0..f6d6acfc0c9 100644
--- a/app/services/notifications/journal_wp_notification_service.rb
+++ b/app/services/notifications/journal_wp_notification_service.rb
@@ -85,6 +85,8 @@ class Notifications::JournalWpNotificationService
add_receiver(receivers, settings_of_watched(work_package), :watched)
add_receiver(receivers, settings_of_subscribed(journal), :subscribed)
+ remove_self_recipient(receivers, journal)
+
receivers
end
@@ -232,6 +234,10 @@ class Notifications::JournalWpNotificationService
end
end
+ def remove_self_recipient(receivers, journal)
+ receivers.delete(journal.user_id) if receivers[journal.user_id] && !user_with_fallback(journal).pref.self_notified?
+ end
+
def receivers_hash
Hash.new do |hash, user|
hash[user] = Hash.new do |channel_hash, channel|
diff --git a/spec/features/notifications/digest_mail_spec.rb b/spec/features/notifications/digest_mail_spec.rb
index bb1aa1d2213..4ec0838928e 100644
--- a/spec/features/notifications/digest_mail_spec.rb
+++ b/spec/features/notifications/digest_mail_spec.rb
@@ -104,6 +104,6 @@ describe "Digest email", type: :feature, js: true do
expect(ActionMailer::Base.deliveries.first.subject)
.to eql I18n.t(:'mail.digests.work_packages.subject',
date: Time.current.strftime('%m/%d/%Y'),
- number: 2)
+ number: 1)
end
end
diff --git a/spec/services/notifications/journal_wp_notification_service_spec.rb b/spec/services/notifications/journal_wp_notification_service_spec.rb
index c5f7e9ae201..cdbfd5ae67f 100644
--- a/spec/services/notifications/journal_wp_notification_service_spec.rb
+++ b/spec/services/notifications/journal_wp_notification_service_spec.rb
@@ -38,9 +38,13 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
notification_settings: recipient_notification_settings,
member_in_project: project,
member_through_role: role,
- login: recipient_login)
+ login: recipient_login,
+ preferences: {
+ no_self_notified: recipient_no_self_notified
+ })
end
let(:recipient_login) { "johndoe" }
+ let(:recipient_no_self_notified) { true }
let(:other_user) do
FactoryBot.create(:user,
notification_settings: other_user_notification_settings)
@@ -281,6 +285,44 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
it_behaves_like 'creates no notification'
end
+
+ context 'when assignee has all notifications enabled but made the change himself and has deactivated self notification' do
+ let(:recipient_notification_settings) do
+ [
+ FactoryBot.build(:mail_notification_setting, involved: true, all: true),
+ FactoryBot.build(:mail_digest_notification_setting, involved: true, all: true),
+ FactoryBot.build(:in_app_notification_setting, involved: true, all: true)
+ ]
+ end
+ let(:author) { recipient }
+
+ it_behaves_like 'creates no notification'
+ end
+
+ context 'when assignee has all notifications enabled, made the change himself and has activated self notification' do
+ let(:recipient_notification_settings) do
+ [
+ FactoryBot.build(:mail_notification_setting, involved: true, all: true),
+ FactoryBot.build(:mail_digest_notification_setting, involved: true, all: true),
+ FactoryBot.build(:in_app_notification_setting, involved: true, all: true)
+ ]
+ end
+ let(:author) { recipient }
+ let(:recipient_no_self_notified) { false }
+
+ it_behaves_like 'creates notification' do
+ let(:notification_channel_reasons) do
+ {
+ read_ian: false,
+ reason_ian: :involved,
+ read_mail: false,
+ reason_mail: :involved,
+ read_mail_digest: false,
+ reason_mail_digest: :involved
+ }
+ end
+ end
+ end
end
context 'when user is responsible' do
@@ -375,6 +417,44 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
it_behaves_like 'creates no notification'
end
+
+ context 'when responsible has all notifications enabled but made the change himself and has deactivated self notification' do
+ let(:recipient_notification_settings) do
+ [
+ FactoryBot.build(:mail_notification_setting, involved: true, all: true),
+ FactoryBot.build(:mail_digest_notification_setting, involved: true, all: true),
+ FactoryBot.build(:in_app_notification_setting, involved: true, all: true)
+ ]
+ end
+ let(:author) { recipient }
+
+ it_behaves_like 'creates no notification'
+ end
+
+ context 'when responsible has all notifications enabled, made the change himself and has activated self notification' do
+ let(:recipient_notification_settings) do
+ [
+ FactoryBot.build(:mail_notification_setting, involved: true, all: true),
+ FactoryBot.build(:mail_digest_notification_setting, involved: true, all: true),
+ FactoryBot.build(:in_app_notification_setting, involved: true, all: true)
+ ]
+ end
+ let(:author) { recipient }
+ let(:recipient_no_self_notified) { false }
+
+ it_behaves_like 'creates notification' do
+ let(:notification_channel_reasons) do
+ {
+ read_ian: false,
+ reason_ian: :involved,
+ read_mail: false,
+ reason_mail: :involved,
+ read_mail_digest: false,
+ reason_mail_digest: :involved
+ }
+ end
+ end
+ end
end
context 'when user is watcher' do
@@ -463,6 +543,44 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
it_behaves_like 'creates no notification'
end
+
+ context 'when watcher has all notifications enabled but made the change himself and has deactivated self notification' do
+ let(:recipient_notification_settings) do
+ [
+ FactoryBot.build(:mail_notification_setting, watched: true, all: true),
+ FactoryBot.build(:mail_digest_notification_setting, watched: true, all: true),
+ FactoryBot.build(:in_app_notification_setting, watched: true, all: true)
+ ]
+ end
+ let(:author) { recipient }
+
+ it_behaves_like 'creates no notification'
+ end
+
+ context 'when watcher has all notifications enabled, made the change himself and has activated self notification' do
+ let(:recipient_notification_settings) do
+ [
+ FactoryBot.build(:mail_notification_setting, watched: true, all: true),
+ FactoryBot.build(:mail_digest_notification_setting, watched: true, all: true),
+ FactoryBot.build(:in_app_notification_setting, watched: true, all: true)
+ ]
+ end
+ let(:author) { recipient }
+ let(:recipient_no_self_notified) { false }
+
+ it_behaves_like 'creates notification' do
+ let(:notification_channel_reasons) do
+ {
+ read_ian: false,
+ reason_ian: :watched,
+ read_mail: false,
+ reason_mail: :watched,
+ read_mail_digest: false,
+ reason_mail_digest: :watched
+ }
+ end
+ end
+ end
end
context 'when user is notified about everything' do
@@ -593,6 +711,44 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
it_behaves_like 'creates no notification'
end
+
+ context 'when recipient has all notifications enabled but made the change himself and has deactivated self notification' do
+ let(:recipient_notification_settings) do
+ [
+ FactoryBot.build(:mail_notification_setting, all: true),
+ FactoryBot.build(:mail_digest_notification_setting, all: true),
+ FactoryBot.build(:in_app_notification_setting, all: true)
+ ]
+ end
+ let(:author) { recipient }
+
+ it_behaves_like 'creates no notification'
+ end
+
+ context 'when recipient has all notifications enabled, made the change himself and has activated self notification' do
+ let(:recipient_notification_settings) do
+ [
+ FactoryBot.build(:mail_notification_setting, all: true),
+ FactoryBot.build(:mail_digest_notification_setting, all: true),
+ FactoryBot.build(:in_app_notification_setting, all: true)
+ ]
+ end
+ let(:author) { recipient }
+ let(:recipient_no_self_notified) { false }
+
+ it_behaves_like 'creates notification' do
+ let(:notification_channel_reasons) do
+ {
+ read_ian: false,
+ reason_ian: :subscribed,
+ read_mail: false,
+ reason_mail: :subscribed,
+ read_mail_digest: false,
+ reason_mail_digest: :subscribed
+ }
+ end
+ end
+ end
end
context 'when notification for work_package_added disabled' do
@@ -948,6 +1104,36 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
it_behaves_like 'creates no notification'
end
+
+ context 'when the mentioned user made the change himself and has deactivated self notification' do
+ let(:note) do
+ "Hello user:#{recipient.login}, hey user##{recipient.id}"
+ end
+ let(:author) { recipient }
+
+ it_behaves_like 'creates no notification'
+ end
+
+ context 'when the mentioned user made the change himself, but has activated self notification' do
+ let(:note) do
+ "Hello user:#{recipient.login}, hey user##{recipient.id}"
+ end
+ let(:author) { recipient }
+ let(:recipient_no_self_notified) { false }
+
+ it_behaves_like 'creates notification' do
+ let(:notification_channel_reasons) do
+ {
+ read_ian: false,
+ reason_ian: :mentioned,
+ read_mail: false,
+ reason_mail: :mentioned,
+ read_mail_digest: false,
+ reason_mail_digest: :mentioned
+ }
+ end
+ end
+ end
end
context 'for groups' do
@@ -987,6 +1173,17 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
it_behaves_like 'group mention'
end
+
+ context 'with the group member making the change himself and having deactivated self notification' do
+ let(:note) do
+ <<~NOTE
+ Hello <mention class="mention" data-id="#{group.id}" data-type="group" data-text="@#{group.name}">@#{group.name}</mention>
+ NOTE
+ end
+ let(:author) { recipient }
+
+ it_behaves_like 'creates no notification'
+ end
end
end