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 prioritized notification setting

ulferts09f1a37f3c4f
diff --git a/app/models/notification.rb b/app/models/notification.rb
index a35475c811c..c809f8f18bd 100644
--- a/app/models/notification.rb
+++ b/app/models/notification.rb
@@ -6,7 +6,8 @@ class Notification < ApplicationRecord
subscribed: 3,
commented: 4,
created: 5,
- processed: 6
+ processed: 6,
+ prioritized: 7
}.freeze
enum reason_ian: REASONS, _prefix: :ian
diff --git a/app/services/notifications/journal_wp_notification_service.rb b/app/services/notifications/journal_wp_notification_service.rb
index 0fb8b4103bb..43fab770706 100644
--- a/app/services/notifications/journal_wp_notification_service.rb
+++ b/app/services/notifications/journal_wp_notification_service.rb
@@ -87,6 +87,7 @@ class Notifications::JournalWpNotificationService
add_receiver(receivers, settings_of_commented(journal), :commented)
add_receiver(receivers, settings_of_created(journal), :created)
add_receiver(receivers, settings_of_processed(journal), :processed)
+ add_receiver(receivers, settings_of_prioritized(journal), :prioritized)
remove_self_recipient(receivers, journal)
@@ -147,6 +148,14 @@ class Notifications::JournalWpNotificationService
:work_package_processed)
end
+ def settings_of_prioritized(journal)
+ scope = !journal.initial? && journal.details.has_key?(:priority_id) ? User.all : User.none
+
+ applicable_settings(scope,
+ journal.data.project,
+ :work_package_prioritized)
+ end
+
def applicable_settings(user_scope, project, reason)
NotificationSetting
.applicable(project)
@@ -189,8 +198,7 @@ class Notifications::JournalWpNotificationService
end
def send_notification_setting?(journal)
- notify_for_wp_updated?(journal) ||
- notify_for_priority(journal)
+ notify_for_wp_updated?(journal) || journal.initial?
end
def mention_matches(journal)
@@ -218,11 +226,6 @@ class Notifications::JournalWpNotificationService
notification_enabled?('work_package_updated') && !journal.initial?
end
- def notify_for_priority(journal)
- notification_enabled?('work_package_priority_updated') &&
- journal.details.has_key?(:priority_id)
- end
-
def notification_enabled?(name)
Setting.notified_events.include?(name)
end
diff --git a/app/services/user_preferences/update_service.rb b/app/services/user_preferences/update_service.rb
index 1b0331ac440..526530acdac 100644
--- a/app/services/user_preferences/update_service.rb
+++ b/app/services/user_preferences/update_service.rb
@@ -83,7 +83,14 @@ module UserPreferences
on_duplicate_key_update: {
conflict_target: conflict_target,
index_predicate: index_predicate,
- columns: %i[watched involved mentioned work_package_commented work_package_created work_package_processed all]
+ columns: %i[watched
+ involved
+ mentioned
+ work_package_commented
+ work_package_created
+ work_package_processed
+ work_package_prioritized
+ all]
},
validate: false
).ids
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 74dacd42405..24594ced0cc 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1896,7 +1896,6 @@ en:
label_work_package_new: "New work package"
label_work_package_edit: "Edit work package %{name}"
label_work_package_plural: "Work packages"
- label_work_package_priority_updated: "Work package priority updated"
label_work_package_status: "Work package status"
label_work_package_status_new: "New status"
label_work_package_status_plural: "Work package statuses"
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index 9f0c09d121b..9b12a93ce2a 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -585,6 +585,7 @@ en:
work_package_commented: 'Work package commented'
work_package_created: 'Work package created'
work_package_processed: 'Work package status changed'
+ work_package_prioritized: 'Work package priority changed'
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 b566bba2a3c..95c703bd4b8 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -237,7 +237,6 @@ notified_events:
serialized: true
default:
- work_package_updated
- - work_package_priority_updated
- news_added
- news_comment_added
- file_added
diff --git a/db/migrate/20210802114054_add_notification_setting_options.rb b/db/migrate/20210802114054_add_notification_setting_options.rb
index 4d4bf070325..8cc31263f3b 100644
--- a/db/migrate/20210802114054_add_notification_setting_options.rb
+++ b/db/migrate/20210802114054_add_notification_setting_options.rb
@@ -4,8 +4,10 @@ class AddNotificationSettingOptions < ActiveRecord::Migration[6.1]
t.boolean :work_package_commented, default: false
t.boolean :work_package_created, default: false
t.boolean :work_package_processed, default: false
+ t.boolean :work_package_prioritized, default: false
end
# TODO: remove existing notification setting from settings
+ # TODO: add index to all boolean fields
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 5fa7136f3a1..b5c979719d2 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
@@ -72,6 +72,16 @@
[attr.aria-label]="text.work_package_processed_header"
/>
</td>
+<td>
+ <input
+ type="checkbox"
+ [checked]="setting.workPackagePrioritized || setting.all"
+ [disabled]="setting.all"
+ (change)="update({ workPackagePrioritized: $event.target.checked })"
+ data-qa-notification-type="work_package_prioritized"
+ [attr.aria-label]="text.work_package_prioritized_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 f6fd517da7c..37d3e8ad2a6 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
@@ -31,6 +31,7 @@ export class NotificationSettingRowComponent implements OnInit {
work_package_commented_header: this.I18n.t('js.notifications.settings.work_package_commented'),
work_package_created_header: this.I18n.t('js.notifications.settings.work_package_created'),
work_package_processed_header: this.I18n.t('js.notifications.settings.work_package_processed'),
+ work_package_prioritized_header: this.I18n.t('js.notifications.settings.work_package_prioritized'),
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 1e7d25a1118..a0197c3cd66 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
@@ -63,6 +63,13 @@
</div>
</div>
</th>
+ <th>
+ <div class="generic-table--sort-header-outer">
+ <div class="generic-table--sort-header">
+ <span [textContent]="text.work_package_prioritized_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 8d08843ef24..e826eaf9810 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
@@ -37,6 +37,7 @@ export class NotificationSettingsTableComponent {
work_package_commented_header: this.I18n.t('js.notifications.settings.work_package_commented'),
work_package_created_header: this.I18n.t('js.notifications.settings.work_package_created'),
work_package_processed_header: this.I18n.t('js.notifications.settings.work_package_processed'),
+ work_package_prioritized_header: this.I18n.t('js.notifications.settings.work_package_prioritized'),
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 cd3b6c3f206..17540416485 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
@@ -11,6 +11,7 @@ export interface NotificationSetting {
workPackageCommented:boolean;
workPackageCreated:boolean;
workPackageProcessed:boolean;
+ workPackagePrioritized:boolean;
all:boolean;
}
@@ -28,6 +29,7 @@ export function buildNotificationSetting(project:null|HalSourceLink, params:Part
workPackageCommented: true,
workPackageCreated: true,
workPackageProcessed: true,
+ workPackagePrioritized: 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 5fa4662d2df..e3838af5f63 100644
--- a/lib/api/v3/user_preferences/notification_setting_representer.rb
+++ b/lib/api/v3/user_preferences/notification_setting_representer.rb
@@ -41,6 +41,7 @@ module API
property :work_package_created
property :work_package_commented
property :work_package_processed
+ property :work_package_prioritized
property :all
associated_resource :project,
diff --git a/lib/open_project/notifiable.rb b/lib/open_project/notifiable.rb
index 6d488b21bb8..adbd9bc3aaa 100644
--- a/lib/open_project/notifiable.rb
+++ b/lib/open_project/notifiable.rb
@@ -31,7 +31,6 @@
module OpenProject
NOTIFIABLE = [
%w(work_package_updated),
- %w(work_package_priority_updated work_package_updated),
%w(news_added),
%w(news_comment_added),
%w(file_added),
diff --git a/spec/factories/notification_setting_factory.rb b/spec/factories/notification_setting_factory.rb
index a06fdec8671..adc03499da6 100644
--- a/spec/factories/notification_setting_factory.rb
+++ b/spec/factories/notification_setting_factory.rb
@@ -8,6 +8,7 @@ FactoryBot.define do
work_package_commented { false }
work_package_created { false }
work_package_processed { false }
+ work_package_prioritized { false }
project { nil } # Default settings
user
diff --git a/spec/features/notifications/digest_mail_spec.rb b/spec/features/notifications/digest_mail_spec.rb
index d7ada016f6e..6551e5efdc0 100644
--- a/spec/features/notifications/digest_mail_spec.rb
+++ b/spec/features/notifications/digest_mail_spec.rb
@@ -21,6 +21,7 @@ describe "Digest email", type: :feature, js: true do
work_package_commented: false,
work_package_created: false,
work_package_processed: false,
+ work_package_prioritized: false,
all: false),
FactoryBot.build(:in_app_notification_setting,
involved: false,
@@ -29,6 +30,7 @@ describe "Digest email", type: :feature, js: true do
work_package_commented: false,
work_package_created: false,
work_package_processed: false,
+ work_package_prioritized: false,
all: false),
FactoryBot.build(:mail_digest_notification_setting,
involved: true,
@@ -37,6 +39,7 @@ describe "Digest email", type: :feature, js: true do
work_package_commented: true,
work_package_created: true,
work_package_processed: true,
+ work_package_prioritized: true,
all: false)
]
end
@@ -61,6 +64,7 @@ describe "Digest email", type: :feature, js: true do
work_package_commented: true,
work_package_created: true,
work_package_processed: true,
+ work_package_prioritized: true,
all: false
notification_settings_page.configure_channel :mail_digest,
@@ -71,6 +75,7 @@ describe "Digest email", type: :feature, js: true do
work_package_commented: false,
work_package_created: false,
work_package_processed: false,
+ work_package_prioritized: false,
all: false
notification_settings_page.add_row(mute_project)
@@ -83,6 +88,7 @@ describe "Digest email", type: :feature, js: true do
work_package_commented: false,
work_package_created: false,
work_package_processed: false,
+ work_package_prioritized: false,
all: false
notification_settings_page.save
diff --git a/spec/features/users/notifications/shared_examples.rb b/spec/features/users/notifications/shared_examples.rb
index 68285e6741f..c7596f31bb1 100644
--- a/spec/features/users/notifications/shared_examples.rb
+++ b/spec/features/users/notifications/shared_examples.rb
@@ -20,6 +20,7 @@ shared_examples 'notification settings workflow' do
work_package_commented: true,
work_package_created: true,
work_package_processed: true,
+ work_package_prioritized: true,
all: false
# Set settings for project email
@@ -31,6 +32,7 @@ shared_examples 'notification settings workflow' do
work_package_commented: false,
work_package_created: false,
work_package_processed: false,
+ work_package_prioritized: false,
all: false
# Set settings for project email digest
@@ -42,6 +44,7 @@ shared_examples 'notification settings workflow' do
work_package_commented: true,
work_package_created: true,
work_package_processed: true,
+ work_package_prioritized: true,
all: true
settings_page.save
@@ -59,6 +62,7 @@ shared_examples 'notification settings workflow' do
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
mail = notification_settings.find_by(project: project, channel: :mail)
expect(mail.involved).to be_truthy
@@ -68,6 +72,7 @@ shared_examples 'notification settings workflow' do
expect(mail.work_package_commented).to be_truthy
expect(mail.work_package_created).to be_truthy
expect(mail.work_package_processed).to be_truthy
+ expect(mail.work_package_prioritized).to be_truthy
mail_digest = notification_settings.find_by(project: project, channel: :mail_digest)
expect(mail_digest.involved).to be_falsey
@@ -77,6 +82,7 @@ shared_examples 'notification settings workflow' do
expect(mail_digest.work_package_commented).to be_truthy
expect(mail_digest.work_package_created).to be_truthy
expect(mail_digest.work_package_processed).to be_truthy
+ expect(mail_digest.work_package_prioritized).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
index a874b5426ed..67689431ce8 100644
--- 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
@@ -100,6 +100,10 @@ describe ::API::V3::UserPreferences::NotificationSettingRepresenter, 'rendering'
it_behaves_like 'property', :workPackageProcessed do
let(:value) { notification_setting.work_package_processed }
end
+
+ it_behaves_like 'property', :workPackagePrioritized do
+ let(:value) { notification_setting.work_package_prioritized }
+ end
end
describe '_embedded' do
diff --git a/spec/lib/open_project/notifiable_spec.rb b/spec/lib/open_project/notifiable_spec.rb
index db97125eaba..7de7a6ec8c5 100644
--- a/spec/lib/open_project/notifiable_spec.rb
+++ b/spec/lib/open_project/notifiable_spec.rb
@@ -32,7 +32,7 @@ require 'spec_helper'
describe OpenProject::Notifiable do
describe '#all' do
it 'matches expected list' do
- expected = %w(work_package_updated work_package_priority_updated news_added news_comment_added
+ expected = %w(work_package_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))
diff --git a/spec/services/notifications/journal_wp_notification_service_spec.rb b/spec/services/notifications/journal_wp_notification_service_spec.rb
index f0313a82ea9..24d3d026b7a 100644
--- a/spec/services/notifications/journal_wp_notification_service_spec.rb
+++ b/spec/services/notifications/journal_wp_notification_service_spec.rb
@@ -58,7 +58,8 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
mentioned: false,
work_package_commented: false,
work_package_processed: false,
- work_package_created: false
+ work_package_created: false,
+ work_package_prioritized: false
}
end
let(:recipient_notification_settings) do
@@ -120,7 +121,7 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
end
let(:send_notifications) { true }
let(:notification_setting) do
- %w(work_package_updated work_package_priority_updated)
+ %w(work_package_updated)
end
def call
@@ -807,6 +808,21 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
it_behaves_like 'creates no notification'
end
+ context 'when the user configured to be notified on work package priority changes' do
+ let(:recipient_notification_settings) do
+ [
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false
+ .merge(work_package_prioritized: true)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false
+ .merge(work_package_prioritized: true)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false
+ .merge(work_package_prioritized: true))
+ ]
+ end
+
+ it_behaves_like 'creates no notification'
+ end
+
context 'when the user did not configure to be notified' do
let(:recipient_notification_settings) do
[
@@ -910,7 +926,7 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
end
end
- context 'when the user has commented notifications deactivated' do
+ context 'when the user has processed notifications deactivated' do
let(:recipient_notification_settings) do
[
FactoryBot.build(:mail_notification_setting, **notification_settings_all_false),
@@ -926,7 +942,7 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
context 'when the journal has no status update' do
let(:journal) { journal_2_with_notes }
- context 'with the user having commented notifications activated' do
+ context 'with the user having processed notifications activated' do
let(:recipient_notification_settings) do
[
FactoryBot.build(:mail_notification_setting, **notification_settings_all_false
@@ -944,46 +960,62 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
context 'when the journal has priority' do
let(:journal) { journal_2_with_priority }
- let(:user_property) { :assigned_to }
-
- context 'notification for work_package_updated and work_package_priority_updated disabled' do
- let(:notification_setting) { [] }
- 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 prioritized notifications activated' do
+ let(:recipient_notification_settings) do
+ [
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false
+ .merge(work_package_prioritized: true)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false
+ .merge(work_package_prioritized: true)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false
+ .merge(work_package_prioritized: true))
+ ]
+ end
it_behaves_like 'creates notification' do
let(:notification_channel_reasons) do
{
read_ian: false,
- reason_ian: :involved,
+ reason_ian: :prioritized,
read_mail: false,
- reason_mail: :involved,
+ reason_mail: :prioritized,
read_mail_digest: false,
- reason_mail_digest: :involved
+ reason_mail_digest: :prioritized
}
end
end
end
- context 'notification for work_package_priority_updated enabled' do
- let(:notification_setting) { %w(work_package_priority_updated) }
+ context 'when the user has prioritized 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 no notification'
+ end
+ end
+
+ context 'when the journal has no priority update' do
+ let(:journal) { journal_2_with_status }
- 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
+ context 'with the user having prioritized notifications activated' do
+ let(:recipient_notification_settings) do
+ [
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false
+ .merge(work_package_prioritized: true)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false
+ .merge(work_package_prioritized: true)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false
+ .merge(work_package_prioritized: true))
+ ]
end
+
+ it_behaves_like 'creates no notification'
end
end
diff --git a/spec/services/user_preferences/update_service_integration_spec.rb b/spec/services/user_preferences/update_service_integration_spec.rb
index 34af30d0e55..cb810088004 100644
--- a/spec/services/user_preferences/update_service_integration_spec.rb
+++ b/spec/services/user_preferences/update_service_integration_spec.rb
@@ -59,7 +59,9 @@ describe UserPreferences::UpdateService, 'integration', type: :model do
watched: false,
involved: true,
work_package_commented: false,
- work_package_created: true
+ work_package_created: true,
+ work_package_processed: true,
+ work_package_prioritized: false
}
]
}
@@ -85,6 +87,8 @@ describe UserPreferences::UpdateService, 'integration', type: :model do
expect(subject.first.involved).to eq true
expect(subject.first.work_package_commented).to eq false
expect(subject.first.work_package_created).to eq true
+ expect(subject.first.work_package_processed).to eq true
+ expect(subject.first.work_package_prioritized).to eq false
expect(subject.first).to eq(default_ian.reload)
expect(current_user.notification_settings.count).to eq(1)
@@ -115,6 +119,8 @@ describe UserPreferences::UpdateService, 'integration', type: :model do
expect(subject.first.involved).to eq false
expect(subject.first.work_package_commented).to eq false
expect(subject.first.work_package_created).to eq false
+ expect(subject.first.work_package_processed).to eq false
+ expect(subject.first.work_package_prioritized).to eq false
expect(current_user.notification_settings.count).to eq(1)