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

add work package commented notification setting

ulfertsf24634601438
diff --git a/app/models/notification.rb b/app/models/notification.rb
index 3643609186e..cfd2645d546 100644
--- a/app/models/notification.rb
+++ b/app/models/notification.rb
@@ -1,7 +1,7 @@
class Notification < ApplicationRecord
- enum reason_ian: { mentioned: 0, involved: 1, watched: 2, subscribed: 3 }, _prefix: :ian
- enum reason_mail: { mentioned: 0, involved: 1, watched: 2, subscribed: 3 }, _prefix: :mail
- enum reason_mail_digest: { mentioned: 0, involved: 1, watched: 2, subscribed: 3 }, _prefix: :mail_digest
+ enum reason_ian: { mentioned: 0, involved: 1, watched: 2, subscribed: 3, commented: 4 }, _prefix: :ian
+ enum reason_mail: { mentioned: 0, involved: 1, watched: 2, subscribed: 3, commented: 4 }, _prefix: :mail
+ enum reason_mail_digest: { mentioned: 0, involved: 1, watched: 2, subscribed: 3, commented: 4 }, _prefix: :mail_digest
belongs_to :recipient, class_name: 'User'
belongs_to :actor, class_name: 'User'
diff --git a/app/services/notifications/journal_wp_notification_service.rb b/app/services/notifications/journal_wp_notification_service.rb
index f6d6acfc0c9..1f3702d39a3 100644
--- a/app/services/notifications/journal_wp_notification_service.rb
+++ b/app/services/notifications/journal_wp_notification_service.rb
@@ -84,6 +84,7 @@ class Notifications::JournalWpNotificationService
add_receiver(receivers, settings_of_involved(journal), :involved)
add_receiver(receivers, settings_of_watched(work_package), :watched)
add_receiver(receivers, settings_of_subscribed(journal), :subscribed)
+ add_receiver(receivers, settings_of_commented(journal), :commented)
remove_self_recipient(receivers, journal)
@@ -120,6 +121,14 @@ class Notifications::JournalWpNotificationService
:watched)
end
+ def settings_of_commented(journal)
+ scope = journal.notes? ? User.all : User.none
+
+ applicable_settings(scope,
+ journal.data.project,
+ :work_package_commented)
+ end
+
def applicable_settings(user_scope, project, reason)
NotificationSetting
.applicable(project)
@@ -164,7 +173,6 @@ class Notifications::JournalWpNotificationService
def send_notification_setting?(journal)
notify_for_wp_added?(journal) ||
notify_for_wp_updated?(journal) ||
- notify_for_notes?(journal) ||
notify_for_status?(journal) ||
notify_for_priority(journal)
end
@@ -198,10 +206,6 @@ class Notifications::JournalWpNotificationService
notification_enabled?('work_package_updated') && !journal.initial?
end
- def notify_for_notes?(journal)
- notification_enabled?('work_package_note_added') && journal.notes.present?
- end
-
def notify_for_status?(journal)
notification_enabled?('status_updated') &&
journal.details.has_key?(:status_id)
diff --git a/app/services/user_preferences/update_service.rb b/app/services/user_preferences/update_service.rb
index c2f57b0e269..1555ae6cf2c 100644
--- a/app/services/user_preferences/update_service.rb
+++ b/app/services/user_preferences/update_service.rb
@@ -83,7 +83,7 @@ module UserPreferences
on_duplicate_key_update: {
conflict_target: conflict_target,
index_predicate: index_predicate,
- columns: %i[watched involved mentioned all]
+ columns: %i[watched involved mentioned work_package_commented all]
},
validate: false
).ids
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 44496dcb977..597dcce7ed8 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1896,7 +1896,6 @@ en:
label_work_package_category_plural: "Work package categories"
label_work_package_hierarchy: "Work package hierarchy"
label_work_package_new: "New work package"
- label_work_package_note_added: "Work package note added"
label_work_package_edit: "Edit work package %{name}"
label_work_package_plural: "Work packages"
label_work_package_priority_updated: "Work package priority updated"
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index f3cc88954c4..e46f659d127 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -582,6 +582,7 @@ en:
involved: 'I am involved'
mentioned: 'I was mentioned'
watched: 'I am watching'
+ work_package_commented: 'Comment on work package'
all: 'All events'
add: 'Add setting for project'
already_selected: 'This project is already selected'
diff --git a/config/settings.yml b/config/settings.yml
index 81c72f01d82..ec686262f49 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -238,7 +238,6 @@ notified_events:
default:
- work_package_added
- work_package_updated
- - work_package_note_added
- status_updated
- work_package_priority_updated
- news_added
diff --git a/db/migrate/20210802114054_add_notification_setting_options.rb b/db/migrate/20210802114054_add_notification_setting_options.rb
new file mode 100644
index 00000000000..5c3adb64c2d
--- /dev/null
+++ b/db/migrate/20210802114054_add_notification_setting_options.rb
@@ -0,0 +1,7 @@
+class AddNotificationSettingOptions < ActiveRecord::Migration[6.1]
+ def change
+ add_column :notification_settings, :work_package_commented, :boolean, default: false
+
+ # TODO: remove existing notification setting from settings
+ end
+end
diff --git a/frontend/src/app/features/user-preferences/notifications-settings/row/notification-setting-row.component.html b/frontend/src/app/features/user-preferences/notifications-settings/row/notification-setting-row.component.html
index f9e7e2bdccb..6f54de5aef8 100644
--- a/frontend/src/app/features/user-preferences/notifications-settings/row/notification-setting-row.component.html
+++ b/frontend/src/app/features/user-preferences/notifications-settings/row/notification-setting-row.component.html
@@ -42,6 +42,16 @@
[attr.aria-label]="text.watched_header"
/>
</td>
+<td>
+ <input
+ type="checkbox"
+ [checked]="setting.workPackageCommented || setting.all"
+ [disabled]="setting.all"
+ (change)="update({ workPackageCommented: $event.target.checked })"
+ data-qa-notification-type="work_package_commented"
+ [attr.aria-label]="text.work_package_commented_header"
+ />
+</td>
<td>
<input
type="checkbox"
diff --git a/frontend/src/app/features/user-preferences/notifications-settings/row/notification-setting-row.component.ts b/frontend/src/app/features/user-preferences/notifications-settings/row/notification-setting-row.component.ts
index 0a7b5ce896e..6e524ac00f0 100644
--- a/frontend/src/app/features/user-preferences/notifications-settings/row/notification-setting-row.component.ts
+++ b/frontend/src/app/features/user-preferences/notifications-settings/row/notification-setting-row.component.ts
@@ -28,6 +28,7 @@ export class NotificationSettingRowComponent implements OnInit {
involved_header: this.I18n.t('js.notifications.settings.involved'),
mentioned_header: this.I18n.t('js.notifications.settings.mentioned'),
watched_header: this.I18n.t('js.notifications.settings.watched'),
+ work_package_commented_header: this.I18n.t('js.notifications.settings.work_package_commented'),
any_event_header: this.I18n.t('js.notifications.settings.all'),
default_all_projects: this.I18n.t('js.notifications.settings.default_all_projects'),
add_setting: this.I18n.t('js.notifications.settings.add'),
diff --git a/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.html b/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.html
index bfb7ebdf6bd..ffe678b02b9 100644
--- a/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.html
+++ b/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.html
@@ -42,6 +42,13 @@
</div>
</div>
</th>
+ <th>
+ <div class="generic-table--sort-header-outer">
+ <div class="generic-table--sort-header">
+ <span [textContent]="text.work_package_commented_header"></span>
+ </div>
+ </div>
+ </th>
<th>
<div class="generic-table--sort-header-outer">
<div class="generic-table--sort-header">
diff --git a/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.ts b/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.ts
index cc6e58c7b24..179e0898360 100644
--- a/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.ts
+++ b/frontend/src/app/features/user-preferences/notifications-settings/table/notification-settings-table.component.ts
@@ -34,6 +34,7 @@ export class NotificationSettingsTableComponent {
channel_header: this.I18n.t('js.notifications.channel'),
mentioned_header: this.I18n.t('js.notifications.settings.mentioned'),
watched_header: this.I18n.t('js.notifications.settings.watched'),
+ work_package_commented_header: this.I18n.t('js.notifications.settings.work_package_commented'),
any_event_header: this.I18n.t('js.notifications.settings.all'),
default_all_projects: this.I18n.t('js.notifications.settings.default_all_projects'),
};
diff --git a/frontend/src/app/features/user-preferences/state/notification-setting.model.ts b/frontend/src/app/features/user-preferences/state/notification-setting.model.ts
index eef5ee2d8e8..9b7faf091ee 100644
--- a/frontend/src/app/features/user-preferences/state/notification-setting.model.ts
+++ b/frontend/src/app/features/user-preferences/state/notification-setting.model.ts
@@ -8,6 +8,7 @@ export interface NotificationSetting {
watched:boolean;
involved:boolean;
mentioned:boolean;
+ workPackageCommented:boolean;
all:boolean;
}
@@ -22,6 +23,7 @@ export function buildNotificationSetting(project:null|HalSourceLink, params:Part
involved: true,
mentioned: true,
watched: true,
+ workPackageCommented: true,
all: false,
channel: 'in_app',
...params,
diff --git a/lib/api/v3/user_preferences/notification_setting_representer.rb b/lib/api/v3/user_preferences/notification_setting_representer.rb
index ec9b07efa5e..5590201c4de 100644
--- a/lib/api/v3/user_preferences/notification_setting_representer.rb
+++ b/lib/api/v3/user_preferences/notification_setting_representer.rb
@@ -39,6 +39,7 @@ module API
property :involved
property :mentioned
property :all
+ property :work_package_commented
associated_resource :project,
skip_render: ->(*) { true },
diff --git a/lib/open_project/notifiable.rb b/lib/open_project/notifiable.rb
index 8d91cbe25a8..bd949dd3a67 100644
--- a/lib/open_project/notifiable.rb
+++ b/lib/open_project/notifiable.rb
@@ -32,7 +32,6 @@ module OpenProject
NOTIFIABLE = [
%w(work_package_added),
%w(work_package_updated),
- %w(work_package_note_added work_package_updated),
%w(status_updated work_package_updated),
%w(work_package_priority_updated work_package_updated),
%w(news_added),
diff --git a/spec/factories/notification_setting_factory.rb b/spec/factories/notification_setting_factory.rb
index 19d1586a9a9..21a4510195e 100644
--- a/spec/factories/notification_setting_factory.rb
+++ b/spec/factories/notification_setting_factory.rb
@@ -5,6 +5,7 @@ FactoryBot.define do
involved { true }
mentioned { true }
watched { true }
+ work_package_commented { true }
project { nil } # Default settings
user
diff --git a/spec/features/notifications/digest_mail_spec.rb b/spec/features/notifications/digest_mail_spec.rb
index 4ec0838928e..59b9cf96f4c 100644
--- a/spec/features/notifications/digest_mail_spec.rb
+++ b/spec/features/notifications/digest_mail_spec.rb
@@ -18,16 +18,19 @@ describe "Digest email", type: :feature, js: true do
involved: false,
watched: false,
mentioned: false,
+ work_package_commented: false,
all: false),
FactoryBot.build(:in_app_notification_setting,
involved: false,
watched: false,
mentioned: false,
+ work_package_commented: false,
all: false),
FactoryBot.build(:mail_digest_notification_setting,
involved: true,
watched: true,
mentioned: true,
+ work_package_commented: true,
all: false)
]
end
@@ -49,6 +52,7 @@ describe "Digest email", type: :feature, js: true do
involved: true,
mentioned: true,
watched: true,
+ work_package_commented: true,
all: false
notification_settings_page.configure_channel :mail_digest,
@@ -56,6 +60,7 @@ describe "Digest email", type: :feature, js: true do
involved: false,
mentioned: true,
watched: true,
+ work_package_commented: false,
all: false
notification_settings_page.add_row(mute_project)
@@ -65,6 +70,7 @@ describe "Digest email", type: :feature, js: true do
involved: false,
mentioned: false,
watched: false,
+ work_package_commented: false,
all: false
notification_settings_page.save
@@ -99,7 +105,7 @@ describe "Digest email", type: :feature, js: true do
perform_enqueued_jobs
expect(ActionMailer::Base.deliveries.length)
- .to eql 1
+ .to be 1
expect(ActionMailer::Base.deliveries.first.subject)
.to eql I18n.t(:'mail.digests.work_packages.subject',
diff --git a/spec/features/users/notifications/shared_examples.rb b/spec/features/users/notifications/shared_examples.rb
index 43cfc13fa88..80c679343a7 100644
--- a/spec/features/users/notifications/shared_examples.rb
+++ b/spec/features/users/notifications/shared_examples.rb
@@ -17,6 +17,7 @@ shared_examples 'notification settings workflow' do
involved: true,
mentioned: true,
watched: true,
+ work_package_commented: true,
all: false
# Set settings for project email
@@ -25,6 +26,7 @@ shared_examples 'notification settings workflow' do
involved: true,
mentioned: true,
watched: false,
+ work_package_commented: false,
all: false
# Set settings for project email digest
@@ -33,6 +35,7 @@ shared_examples 'notification settings workflow' do
involved: false,
mentioned: true,
watched: false,
+ work_package_commented: true,
all: true
settings_page.save
@@ -47,18 +50,21 @@ shared_examples 'notification settings workflow' do
expect(in_app.mentioned).to be_truthy
expect(in_app.watched).to be_falsey
expect(in_app.all).to be_falsey
+ expect(in_app.work_package_commented).to be_falsey
- in_app = notification_settings.find_by(project: project, channel: :mail)
- expect(in_app.involved).to be_truthy
- expect(in_app.mentioned).to be_truthy
- expect(in_app.watched).to be_truthy
- expect(in_app.all).to be_falsey
+ mail = notification_settings.find_by(project: project, channel: :mail)
+ expect(mail.involved).to be_truthy
+ expect(mail.mentioned).to be_truthy
+ expect(mail.watched).to be_truthy
+ expect(mail.all).to be_falsey
+ expect(mail.work_package_commented).to be_truthy
- in_app = notification_settings.find_by(project: project, channel: :mail_digest)
- expect(in_app.involved).to be_falsey
- expect(in_app.mentioned).to be_truthy
- expect(in_app.watched).to be_falsey
- expect(in_app.all).to be_truthy
+ mail_digest = notification_settings.find_by(project: project, channel: :mail_digest)
+ expect(mail_digest.involved).to be_falsey
+ expect(mail_digest.mentioned).to be_truthy
+ expect(mail_digest.watched).to be_falsey
+ expect(mail_digest.all).to be_truthy
+ expect(mail_digest.work_package_commented).to be_truthy
# Trying to add the same project again will not be possible (Regression #38072)
click_button 'Add setting for project'
diff --git a/spec/lib/api/v3/user_preferences/notification_setting_representer_rendering_spec.rb b/spec/lib/api/v3/user_preferences/notification_setting_representer_rendering_spec.rb
new file mode 100644
index 00000000000..b330ede57cd
--- /dev/null
+++ b/spec/lib/api/v3/user_preferences/notification_setting_representer_rendering_spec.rb
@@ -0,0 +1,105 @@
+#-- 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 docs/COPYRIGHT.rdoc for more details.
+#++
+
+require 'spec_helper'
+
+describe ::API::V3::UserPreferences::NotificationSettingRepresenter, 'rendering' do
+ include ::API::V3::Utilities::PathHelper
+
+ subject(:generated) { representer.to_json }
+
+ let(:project) { FactoryBot.build_stubbed :project }
+ let(:notification_setting) { FactoryBot.build_stubbed(:notification_setting, project: project) }
+
+ let(:representer) do
+ described_class.create notification_setting,
+ current_user: current_user,
+ embed_links: embed_links
+ end
+
+ let(:embed_links) { true }
+
+ current_user { FactoryBot.build_stubbed(:user) }
+
+ describe '_links' do
+ describe 'self' do
+ # No self link as the representer is rendered as part of the user preferences.
+ it_behaves_like 'has no link' do
+ let(:link) { 'self' }
+ end
+ end
+
+ describe 'project' do
+ it_behaves_like 'has a titled link' do
+ let(:link) { 'project' }
+ let(:href) { api_v3_paths.project(project.id) }
+ let(:title) { project.name }
+ end
+ end
+ end
+
+ describe 'properties' do
+ it 'has no _type' do
+ expect(generated)
+ .not_to have_json_path('_type')
+ end
+
+ it_behaves_like 'property', :channel do
+ let(:value) { notification_setting.channel }
+ end
+
+ it_behaves_like 'property', :watched do
+ let(:value) { notification_setting.watched }
+ end
+
+ it_behaves_like 'property', :involved do
+ let(:value) { notification_setting.involved }
+ end
+
+ it_behaves_like 'property', :mentioned do
+ let(:value) { notification_setting.mentioned }
+ end
+
+ it_behaves_like 'property', :all do
+ let(:value) { notification_setting.all }
+ end
+
+ it_behaves_like 'property', :workPackageCommented do
+ let(:value) { notification_setting.work_package_commented }
+ end
+ end
+
+ describe '_embedded' do
+ describe 'project' do
+ it 'skips embedding the project' do
+ expect(generated)
+ .not_to have_json_path('_embedded/project')
+ end
+ end
+ end
+end
diff --git a/spec/lib/open_project/notifiable_spec.rb b/spec/lib/open_project/notifiable_spec.rb
index 471768267f5..d9c65f57759 100644
--- a/spec/lib/open_project/notifiable_spec.rb
+++ b/spec/lib/open_project/notifiable_spec.rb
@@ -32,9 +32,9 @@ require 'spec_helper'
describe OpenProject::Notifiable do
describe '#all' do
it 'matches expected list' do
- expected = %w(work_package_added work_package_updated work_package_note_added
- status_updated work_package_priority_updated news_added news_comment_added
- file_added message_posted wiki_content_added wiki_content_updated membership_added membership_updated)
+ expected = %w(work_package_added work_package_updated
+ status_updated work_package_priority_updated news_added news_comment_added
+ file_added message_posted wiki_content_added wiki_content_updated membership_added membership_updated)
expect(described_class.all.map(&:name))
.to match_array(expected)
diff --git a/spec/services/notifications/journal_wp_notification_service_spec.rb b/spec/services/notifications/journal_wp_notification_service_spec.rb
index cdbfd5ae67f..e81cfceb875 100644
--- a/spec/services/notifications/journal_wp_notification_service_spec.rb
+++ b/spec/services/notifications/journal_wp_notification_service_spec.rb
@@ -50,6 +50,15 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
notification_settings: other_user_notification_settings)
end
let(:author) { user_property == :author ? recipient : other_user }
+ let(:notification_settings_all_false) do
+ {
+ all: false,
+ involved: false,
+ watched: false,
+ mentioned: false,
+ work_package_commented: false
+ }
+ end
let(:recipient_notification_settings) do
[
FactoryBot.build(:mail_notification_setting, all: true),
@@ -59,18 +68,20 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
end
let(:other_user_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, all: false, involved: false, watched: false, mentioned: false),
- FactoryBot.build(:in_app_notification_setting, all: false, involved: false, watched: false, mentioned: false),
- FactoryBot.build(:mail_digest_notification_setting, all: false, involved: false, watched: false, mentioned: false)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false)
]
end
let(:user_property) { nil }
let(:work_package) do
- wp_attributes = { project: project,
- author: other_user,
- responsible: other_user,
- assigned_to: other_user,
- type: project.types.first }
+ wp_attributes = {
+ project: project,
+ author: other_user,
+ responsible: other_user,
+ assigned_to: other_user,
+ type: project.types.first
+ }
if %i[responsible assigned_to].include?(user_property)
FactoryBot.create(:work_package,
@@ -107,7 +118,7 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
end
let(:send_notifications) { true }
let(:notification_setting) do
- %w(work_package_added work_package_updated work_package_note_added status_updated work_package_priority_updated)
+ %w(work_package_added work_package_updated status_updated work_package_priority_updated)
end
def call
@@ -174,9 +185,9 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
let(:user_property) { :assigned_to }
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, involved: true),
- FactoryBot.build(:in_app_notification_setting, involved: true),
- FactoryBot.build(:mail_digest_notification_setting, involved: true)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(involved: true)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(involved: true)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(involved: true))
]
end
@@ -193,12 +204,12 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
end
end
- context 'assignee has in app notifications disabled' do
+ context 'when assignee has in app notifications disabled' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, involved: false, all: true),
- FactoryBot.build(:mail_digest_notification_setting, involved: true),
- FactoryBot.build(:in_app_notification_setting, involved: false)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(involved: false, all: true)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(involved: false)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(involved: true))
]
end
@@ -219,9 +230,9 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
context 'assignee has mail notifications disabled' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, involved: false),
- FactoryBot.build(:mail_digest_notification_setting, involved: false),
- FactoryBot.build(:in_app_notification_setting, involved: true)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(involved: true)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false)
]
end
@@ -242,9 +253,9 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
context 'assignee has all notifications disabled' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, involved: false),
- FactoryBot.build(:mail_digest_notification_setting, involved: false),
- FactoryBot.build(:in_app_notification_setting, involved: false)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false)
]
end
@@ -254,9 +265,9 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
context 'assignee has all in app notifications enabled but only involved for mail' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, involved: true),
- FactoryBot.build(:mail_digest_notification_setting, involved: true),
- FactoryBot.build(:in_app_notification_setting, involved: false, watched: false, mentioned: false, all: true)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(involved: true)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(involved: false, all: true)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(involved: true))
]
end
@@ -289,9 +300,9 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
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)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(involved: true, all: true)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(involved: true, all: true)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(involved: false, all: true))
]
end
let(:author) { recipient }
@@ -302,9 +313,9 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
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)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(involved: true, all: true)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(involved: true, all: true)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(involved: true, all: true))
]
end
let(:author) { recipient }
@@ -329,9 +340,9 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
let(:user_property) { :responsible }
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, involved: true),
- FactoryBot.build(:mail_digest_notification_setting, involved: true),
- FactoryBot.build(:in_app_notification_setting, involved: true)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(involved: true)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(involved: true)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(involved: true))
]
end
@@ -351,9 +362,9 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
context 'when responsible has in app notifications disabled' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, involved: false, all: true),
- FactoryBot.build(:mail_digest_notification_setting, involved: false, all: true),
- FactoryBot.build(:in_app_notification_setting, involved: false)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(involved: false, all: true)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(all: true))
]
end
@@ -374,9 +385,9 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
context 'when responsible has mail notifications disabled' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, involved: false),
- FactoryBot.build(:mail_digest_notification_setting, involved: false),
- FactoryBot.build(:in_app_notification_setting, involved: true)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(involved: true)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false)
]
end
@@ -397,9 +408,9 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
context 'when responsible has all notifications disabled' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, involved: false),
- FactoryBot.build(:mail_digest_notification_setting, involved: false),
- FactoryBot.build(:in_app_notification_setting, involved: false)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false)
]
end
@@ -461,9 +472,9 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
let(:user_property) { :watcher }
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, watched: true),
- FactoryBot.build(:mail_digest_notification_setting, watched: true),
- FactoryBot.build(:in_app_notification_setting, watched: true)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(watched: true)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(watched: true)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(watched: true))
]
end
@@ -483,9 +494,9 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
context 'when watcher has in app notifications disabled' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, watched: true),
- FactoryBot.build(:mail_digest_notification_setting, watched: true),
- FactoryBot.build(:in_app_notification_setting, watched: false)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(watched: true)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(watched: true))
]
end
@@ -506,9 +517,9 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
context 'when watcher has mail notifications disabled' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, watched: false),
- FactoryBot.build(:mail_digest_notification_setting, watched: false),
- FactoryBot.build(:in_app_notification_setting, watched: true)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(watched: true)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false)
]
end
@@ -529,9 +540,9 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
context 'when watcher has all notifications disabled' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, watched: false),
- FactoryBot.build(:mail_digest_notification_setting, watched: false),
- FactoryBot.build(:in_app_notification_setting, watched: false)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false)
]
end
@@ -547,9 +558,9 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
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)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(watched: true, all: true)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(watched: true, all: true)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(watched: true, all: true))
]
end
let(:author) { recipient }
@@ -560,9 +571,9 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
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)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(watched: true, all: true)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(watched: true, all: true)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(watched: true, all: true))
]
end
let(:author) { recipient }
@@ -610,9 +621,9 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
context 'with in app notifications disabled' 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: false)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(all: true)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(all: true)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false)
]
end
@@ -633,9 +644,9 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
context 'with mail notifications disabled' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, all: false),
- FactoryBot.build(:mail_digest_notification_setting, all: false),
- FactoryBot.build(:in_app_notification_setting, all: true)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(all: true))
]
end
@@ -656,9 +667,9 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
context 'with all disabled' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, all: false),
- FactoryBot.build(:mail_digest_notification_setting, all: false),
- FactoryBot.build(:in_app_notification_setting, all: false)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false)
]
end
@@ -668,12 +679,13 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
context 'with all disabled as a default but enabled in the project' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, all: false),
- FactoryBot.build(:mail_digest_notification_setting, all: false),
- FactoryBot.build(:in_app_notification_setting, all: false),
- FactoryBot.build(:mail_notification_setting, project: project, all: true),
- FactoryBot.build(:mail_digest_notification_setting, project: project, all: true),
- FactoryBot.build(:in_app_notification_setting, project: project, all: true)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false),
+ FactoryBot.build(:mail_notification_setting, project: project, **notification_settings_all_false.merge(all: true)),
+ FactoryBot.build(:mail_digest_notification_setting, project: project, **notification_settings_all_false
+ .merge(all: true)),
+ FactoryBot.build(:in_app_notification_setting, project: project, **notification_settings_all_false.merge(all: true))
]
end
@@ -694,12 +706,12 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
context 'with all enabled as a default but disabled in the project' 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),
- FactoryBot.build(:mail_notification_setting, project: project, all: false),
- FactoryBot.build(:mail_digest_notification_setting, project: project, all: false),
- FactoryBot.build(:in_app_notification_setting, project: project, all: false)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(all: true)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(all: true)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(all: true)),
+ FactoryBot.build(:mail_notification_setting, project: project, **notification_settings_all_false),
+ FactoryBot.build(:mail_digest_notification_setting, project: project, **notification_settings_all_false),
+ FactoryBot.build(:in_app_notification_setting, project: project, **notification_settings_all_false)
]
end
@@ -752,7 +764,7 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
end
context 'when notification for work_package_added disabled' do
- let(:notification_setting) { %w(work_package_updated work_package_note_added) }
+ let(:notification_setting) { %w(work_package_updated) }
let(:user_property) { :assigned_to }
it_behaves_like 'creates no notification'
@@ -760,46 +772,62 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
context 'when the journal has a note' do
let(:journal) { journal_2_with_notes }
- let(:user_property) { :assigned_to }
-
- context 'notification for work_package_updated and work_package_note_added disabled' do
- let(:notification_setting) { %w(work_package_added status_updated work_package_priority_updated) }
-
- it_behaves_like 'creates no notification'
- end
- context 'notification for work_package_updated enabled' do
- let(:notification_setting) { %w(work_package_updated) }
+ context 'when the user has commented notifications activated' do
+ let(:recipient_notification_settings) do
+ [
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false
+ .merge(work_package_commented: true)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false
+ .merge(work_package_commented: true)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false
+ .merge(work_package_commented: true))
+ ]
+ end
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
read_ian: false,
- reason_ian: :involved,
+ reason_ian: :commented,
read_mail: false,
- reason_mail: :involved,
+ reason_mail: :commented,
read_mail_digest: false,
- reason_mail_digest: :involved
+ reason_mail_digest: :commented
}
end
end
end
- context 'notification for work_package_note_added enabled' do
- let(:notification_setting) { %w(work_package_note_added) }
+ context 'when the user has commented notifications deactivated' do
+ let(:recipient_notification_settings) do
+ [
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false)
+ ]
+ end
- 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
+ it_behaves_like 'creates no notification'
+ end
+ end
+
+ context 'when the journal has no note' do
+ let(:journal) { journal_2_with_status }
+
+ context 'with the user having commented notifications activated' do
+ let(:recipient_notification_settings) do
+ [
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false
+ .merge(work_package_commented: true)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false
+ .merge(work_package_commented: true)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false
+ .merge(work_package_commented: true))
+ ]
end
+
+ it_behaves_like 'creates no notification'
end
end
@@ -808,7 +836,7 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
let(:user_property) { :assigned_to }
context 'notification for work_package_updated and status_updated disabled' do
- let(:notification_setting) { %w(work_package_added work_package_note_added work_package_priority_updated) }
+ let(:notification_setting) { %w(work_package_added work_package_priority_updated) }
it_behaves_like 'creates no notification'
end
@@ -853,7 +881,7 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
let(:user_property) { :assigned_to }
context 'notification for work_package_updated and work_package_priority_updated disabled' do
- let(:notification_setting) { %w(work_package_added work_package_note_added status_updated) }
+ let(:notification_setting) { %w(work_package_added status_updated) }
it_behaves_like 'creates no notification'
end
@@ -920,9 +948,9 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
context 'when user is mentioned' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, mentioned: true),
- FactoryBot.build(:mail_digest_notification_setting, mentioned: true),
- FactoryBot.build(:in_app_notification_setting, mentioned: true)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(mentioned: true)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(mentioned: true)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(mentioned: true))
]
end
@@ -946,9 +974,9 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
context 'user disabled mention notifications' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, mentioned: false),
- FactoryBot.build(:mail_digest_notification_setting, mentioned: false),
- FactoryBot.build(:in_app_notification_setting, mentioned: false)
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(mentioned: false)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(mentioned: false)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(mentioned: false))
]
end
@@ -982,121 +1010,118 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
end
shared_examples_for 'mentioned' do
- context 'for users' do
- context "mentioned is allowed to view the work package" do
- context "The added text contains a login name" do
- let(:note) { "Hello user:\"#{recipient_login}\"" }
-
- context "that is pretty normal word" do
- 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
+ context 'with users' do
+ context "when the added text contains a login name as a pretty normal word" do
+ let(:note) { "Hello user:\"#{recipient_login}\"" }
- context "that is an email address" do
- let(:recipient_login) { "[email protected]" }
-
- 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
+ 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
+
+ context "when the added text contains an email login" do
+ let(:note) { "Hello user:\"#{recipient_login}\"" }
+ let(:recipient_login) { "[email protected]" }
- context "The added text contains a user ID" do
- let(:note) { "Hello user##{recipient.id}" }
-
- 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
+ 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
- context "The added text contains a user mention tag in one way" do
- let(:note) do
- <<~NOTE
- Hello <mention class="mention" data-id="#{recipient.id}" data-type="user" data-text="@#{recipient.name}">@#{recipient.name}</mention>
- NOTE
- end
+ context "when the added text contains a user ID" do
+ let(:note) { "Hello user##{recipient.id}" }
- 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
+ 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
- context "The added text contains a user mention tag in the other way" do
- let(:note) do
- <<~NOTE
- Hello <mention class="mention" data-type="user" data-id="#{recipient.id}" data-text="@#{recipient.name}">@#{recipient.name}</mention>
- NOTE
- end
+ context "when the added text contains a user mention tag in one way" do
+ let(:note) do
+ <<~NOTE
+ Hello <mention class="mention" data-id="#{recipient.id}" data-type="user" data-text="@#{recipient.name}">@#{recipient.name}</mention>
+ NOTE
+ end
- 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
+ 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
- context "the recipient turned off mention notifications" do
- let(:recipient_notification_settings) do
- [
- FactoryBot.build(:mail_notification_setting, mentioned: false),
- FactoryBot.build(:mail_digest_notification_setting, mentioned: false),
- FactoryBot.build(:in_app_notification_setting, mentioned: false)
- ]
- end
+ context "when the added text contains a user mention tag in the other way" do
+ let(:note) do
+ <<~NOTE
+ Hello <mention class="mention" data-type="user" data-id="#{recipient.id}" data-text="@#{recipient.name}">@#{recipient.name}</mention>
+ NOTE
+ end
- let(:note) do
- "Hello user:\"#{recipient.login}\", hey user##{recipient.id}"
+ 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
- it_behaves_like 'creates no notification'
+ context "when the recipient turned off mention notifications" do
+ let(:recipient_notification_settings) do
+ [
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(mentioned: false)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(mentioned: false)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(mentioned: false))
+ ]
+ end
+
+ let(:note) do
+ "Hello user:\"#{recipient.login}\", hey user##{recipient.id}"
end
+
+ it_behaves_like 'creates no notification'
end
- context "mentioned user is not allowed to view the work package" do
+ context "with the mentioned user not being allowed to view the work package" do
let(:role) { FactoryBot.create(:role, permissions: []) }
let(:note) do
"Hello user:#{recipient.login}, hey user##{recipient.id}"
diff --git a/spec/services/user_preferences/update_service_integration_spec.rb b/spec/services/user_preferences/update_service_integration_spec.rb
index 6321089293a..963fbc5a089 100644
--- a/spec/services/user_preferences/update_service_integration_spec.rb
+++ b/spec/services/user_preferences/update_service_integration_spec.rb
@@ -52,7 +52,14 @@ describe UserPreferences::UpdateService, 'integration', type: :model do
let(:attributes) do
{
notification_settings: [
- { project_id: nil, channel: 'in_app', all: false, watched: false, involved: true }
+ {
+ project_id: nil,
+ channel: 'in_app',
+ all: false,
+ watched: false,
+ involved: true,
+ work_package_commented: false
+ }
]
}
end
@@ -65,6 +72,7 @@ describe UserPreferences::UpdateService, 'integration', type: :model do
expect(default_ian.watched).to eq true
expect(default_ian.mentioned).to eq true
expect(default_ian.involved).to eq true
+ expect(default_ian.work_package_commented).to eq true
expect(subject.count).to eq 1
expect(subject.first.project_id).to eq nil
@@ -73,6 +81,7 @@ describe UserPreferences::UpdateService, 'integration', type: :model do
expect(subject.first.mentioned).to eq false
expect(subject.first.watched).to eq false
expect(subject.first.involved).to eq true
+ expect(subject.first.work_package_commented).to eq false
expect(subject.first).to eq(default_ian.reload)
expect(current_user.notification_settings.count).to eq(1)
@@ -101,6 +110,7 @@ describe UserPreferences::UpdateService, 'integration', type: :model do
expect(subject.first.mentioned).to eq false
expect(subject.first.watched).to eq false
expect(subject.first.involved).to eq false
+ expect(subject.first.work_package_commented).to eq false
expect(current_user.notification_settings.count).to eq(1)