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

ulferts2a6ab1510130
diff --git a/app/models/notification.rb b/app/models/notification.rb
index c809f8f18bd..e4de893c4a3 100644
--- a/app/models/notification.rb
+++ b/app/models/notification.rb
@@ -7,7 +7,8 @@ class Notification < ApplicationRecord
commented: 4,
created: 5,
processed: 6,
- prioritized: 7
+ prioritized: 7,
+ scheduled: 8
}.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 37690bb5ba2..895e1414bd4 100644
--- a/app/services/notifications/journal_wp_notification_service.rb
+++ b/app/services/notifications/journal_wp_notification_service.rb
@@ -80,7 +80,7 @@ class Notifications::JournalWpNotificationService
def notification_receivers(journal)
receivers = receivers_hash
- %i(mentioned involved watched subscribed commented created processed prioritized).each do |reason|
+ %i(mentioned involved watched subscribed commented created processed prioritized scheduled).each do |reason|
add_receivers_by_reason(receivers, journal, reason)
end
@@ -126,37 +126,47 @@ class Notifications::JournalWpNotificationService
end
def settings_of_commented(journal)
- scope = journal.notes? ? User.all : User.none
+ return NotificationSetting.none unless journal.notes?
- applicable_settings(scope,
+ applicable_settings(User.all,
journal.data.project,
:work_package_commented)
end
def settings_of_created(journal)
- scope = journal.initial? ? User.all : User.none
+ return NotificationSetting.none unless journal.initial?
- applicable_settings(scope,
+ applicable_settings(User.all,
journal.data.project,
:work_package_created)
end
def settings_of_processed(journal)
- scope = !journal.initial? && journal.details.has_key?(:status_id) ? User.all : User.none
+ return NotificationSetting.none unless !journal.initial? && journal.details.has_key?(:status_id)
- applicable_settings(scope,
+ applicable_settings(User.all,
journal.data.project,
:work_package_processed)
end
def settings_of_prioritized(journal)
- scope = !journal.initial? && journal.details.has_key?(:priority_id) ? User.all : User.none
+ return NotificationSetting.none unless !journal.initial? && journal.details.has_key?(:priority_id)
- applicable_settings(scope,
+ applicable_settings(User.all,
journal.data.project,
:work_package_prioritized)
end
+ def settings_of_scheduled(journal)
+ if journal.initial? || !(journal.details.has_key?(:start_date) || journal.details.has_key?(:due_date))
+ return NotificationSetting.none
+ end
+
+ applicable_settings(User.all,
+ journal.data.project,
+ :work_package_scheduled)
+ end
+
def applicable_settings(user_scope, project, reason)
NotificationSetting
.applicable(project)
diff --git a/app/services/user_preferences/update_service.rb b/app/services/user_preferences/update_service.rb
index 526530acdac..e127776e371 100644
--- a/app/services/user_preferences/update_service.rb
+++ b/app/services/user_preferences/update_service.rb
@@ -90,6 +90,7 @@ module UserPreferences
work_package_created
work_package_processed
work_package_prioritized
+ work_package_scheduled
all]
},
validate: false
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index 9b12a93ce2a..14526b0ff16 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -586,6 +586,7 @@ en:
work_package_created: 'Work package created'
work_package_processed: 'Work package status changed'
work_package_prioritized: 'Work package priority changed'
+ work_package_scheduled: 'Work package scheduled'
all: 'All events'
add: 'Add setting for project'
already_selected: 'This project is already selected'
diff --git a/db/migrate/20210802114054_add_notification_setting_options.rb b/db/migrate/20210802114054_add_notification_setting_options.rb
index fe7e05ee21b..128c8640d1c 100644
--- a/db/migrate/20210802114054_add_notification_setting_options.rb
+++ b/db/migrate/20210802114054_add_notification_setting_options.rb
@@ -14,6 +14,7 @@ class AddNotificationSettingOptions < ActiveRecord::Migration[6.1]
t.boolean :work_package_created, default: false, index: true
t.boolean :work_package_processed, default: false, index: true
t.boolean :work_package_prioritized, default: false, index: true
+ t.boolean :work_package_scheduled, default: false, index: true
t.index :all
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 b5c979719d2..961d638e0f4 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
@@ -82,6 +82,16 @@
[attr.aria-label]="text.work_package_prioritized_header"
/>
</td>
+<td>
+ <input
+ type="checkbox"
+ [checked]="setting.workPackageScheduled || setting.all"
+ [disabled]="setting.all"
+ (change)="update({ workPackageScheduled: $event.target.checked })"
+ data-qa-notification-type="work_package_scheduled"
+ [attr.aria-label]="text.work_package_scheduled_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 37d3e8ad2a6..735c25c919e 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
@@ -32,6 +32,7 @@ export class NotificationSettingRowComponent implements OnInit {
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'),
+ work_package_scheduled_header: this.I18n.t('js.notifications.settings.work_package_scheduled'),
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 a0197c3cd66..42c2feb753e 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
@@ -8,6 +8,11 @@
<col highlight-col>
<col highlight-col>
<col highlight-col>
+ <col highlight-col>
+ <col highlight-col>
+ <col highlight-col>
+ <col highlight-col>
+ <col highlight-col>
</colgroup>
<thead>
<tr>
@@ -70,6 +75,13 @@
</div>
</div>
</th>
+ <th>
+ <div class="generic-table--sort-header-outer">
+ <div class="generic-table--sort-header">
+ <span [textContent]="text.work_package_scheduled_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 e826eaf9810..be0c27bcdaa 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
@@ -38,6 +38,7 @@ export class NotificationSettingsTableComponent {
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'),
+ work_package_scheduled_header: this.I18n.t('js.notifications.settings.work_package_scheduled'),
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 17540416485..6d5b6cb4981 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
@@ -12,6 +12,7 @@ export interface NotificationSetting {
workPackageCreated:boolean;
workPackageProcessed:boolean;
workPackagePrioritized:boolean;
+ workPackageScheduled:boolean;
all:boolean;
}
@@ -30,6 +31,7 @@ export function buildNotificationSetting(project:null|HalSourceLink, params:Part
workPackageCreated: true,
workPackageProcessed: true,
workPackagePrioritized: true,
+ workPackageScheduled: 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 e3838af5f63..d4e64691a20 100644
--- a/lib/api/v3/user_preferences/notification_setting_representer.rb
+++ b/lib/api/v3/user_preferences/notification_setting_representer.rb
@@ -42,6 +42,7 @@ module API
property :work_package_commented
property :work_package_processed
property :work_package_prioritized
+ property :work_package_scheduled
property :all
associated_resource :project,
diff --git a/spec/factories/notification_setting_factory.rb b/spec/factories/notification_setting_factory.rb
index adc03499da6..635b6135721 100644
--- a/spec/factories/notification_setting_factory.rb
+++ b/spec/factories/notification_setting_factory.rb
@@ -9,6 +9,7 @@ FactoryBot.define do
work_package_created { false }
work_package_processed { false }
work_package_prioritized { false }
+ work_package_scheduled { 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 6551e5efdc0..107985f10cf 100644
--- a/spec/features/notifications/digest_mail_spec.rb
+++ b/spec/features/notifications/digest_mail_spec.rb
@@ -22,6 +22,7 @@ describe "Digest email", type: :feature, js: true do
work_package_created: false,
work_package_processed: false,
work_package_prioritized: false,
+ work_package_scheduled: false,
all: false),
FactoryBot.build(:in_app_notification_setting,
involved: false,
@@ -31,6 +32,7 @@ describe "Digest email", type: :feature, js: true do
work_package_created: false,
work_package_processed: false,
work_package_prioritized: false,
+ work_package_scheduled: false,
all: false),
FactoryBot.build(:mail_digest_notification_setting,
involved: true,
@@ -40,6 +42,7 @@ describe "Digest email", type: :feature, js: true do
work_package_created: true,
work_package_processed: true,
work_package_prioritized: true,
+ work_package_scheduled: true,
all: false)
]
end
@@ -65,6 +68,7 @@ describe "Digest email", type: :feature, js: true do
work_package_created: true,
work_package_processed: true,
work_package_prioritized: true,
+ work_package_scheduled: true,
all: false
notification_settings_page.configure_channel :mail_digest,
@@ -76,6 +80,7 @@ describe "Digest email", type: :feature, js: true do
work_package_created: false,
work_package_processed: false,
work_package_prioritized: false,
+ work_package_scheduled: false,
all: false
notification_settings_page.add_row(mute_project)
@@ -89,6 +94,7 @@ describe "Digest email", type: :feature, js: true do
work_package_created: false,
work_package_processed: false,
work_package_prioritized: false,
+ work_package_scheduled: 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 c7596f31bb1..3048462fde6 100644
--- a/spec/features/users/notifications/shared_examples.rb
+++ b/spec/features/users/notifications/shared_examples.rb
@@ -21,6 +21,7 @@ shared_examples 'notification settings workflow' do
work_package_created: true,
work_package_processed: true,
work_package_prioritized: true,
+ work_package_scheduled: true,
all: false
# Set settings for project email
@@ -33,6 +34,7 @@ shared_examples 'notification settings workflow' do
work_package_created: false,
work_package_processed: false,
work_package_prioritized: false,
+ work_package_scheduled: false,
all: false
# Set settings for project email digest
@@ -45,6 +47,7 @@ shared_examples 'notification settings workflow' do
work_package_created: true,
work_package_processed: true,
work_package_prioritized: true,
+ work_package_scheduled: true,
all: true
settings_page.save
@@ -63,6 +66,7 @@ shared_examples 'notification settings workflow' do
expect(in_app.work_package_created).to be_falsey
expect(in_app.work_package_processed).to be_falsey
expect(in_app.work_package_prioritized).to be_falsey
+ expect(in_app.work_package_scheduled).to be_falsey
mail = notification_settings.find_by(project: project, channel: :mail)
expect(mail.involved).to be_truthy
@@ -73,6 +77,7 @@ shared_examples 'notification settings workflow' do
expect(mail.work_package_created).to be_truthy
expect(mail.work_package_processed).to be_truthy
expect(mail.work_package_prioritized).to be_truthy
+ expect(mail.work_package_scheduled).to be_truthy
mail_digest = notification_settings.find_by(project: project, channel: :mail_digest)
expect(mail_digest.involved).to be_falsey
@@ -83,6 +88,7 @@ shared_examples 'notification settings workflow' do
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
+ expect(mail_digest.work_package_scheduled).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 67689431ce8..2bf08b85797 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
@@ -104,6 +104,10 @@ describe ::API::V3::UserPreferences::NotificationSettingRepresenter, 'rendering'
it_behaves_like 'property', :workPackagePrioritized do
let(:value) { notification_setting.work_package_prioritized }
end
+
+ it_behaves_like 'property', :workPackageScheduled do
+ let(:value) { notification_setting.work_package_scheduled }
+ end
end
describe '_embedded' do
diff --git a/spec/services/notifications/journal_wp_notification_service_spec.rb b/spec/services/notifications/journal_wp_notification_service_spec.rb
index ceffcc9b1a9..79bb1d6c4a8 100644
--- a/spec/services/notifications/journal_wp_notification_service_spec.rb
+++ b/spec/services/notifications/journal_wp_notification_service_spec.rb
@@ -59,6 +59,7 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
work_package_commented: false,
work_package_processed: false,
work_package_created: false,
+ work_package_scheduled: false,
work_package_prioritized: false
}
end
@@ -119,6 +120,16 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
work_package.save(validate: false)
work_package.journals.last
end
+ let(:journal_2_with_start_date) do
+ work_package.start_date = Time.zone.today
+ work_package.save(validate: false)
+ work_package.journals.last
+ end
+ let(:journal_2_with_due_date) do
+ work_package.due_date = Time.zone.today
+ work_package.save(validate: false)
+ work_package.journals.last
+ end
let(:send_notifications) { true }
def call
@@ -1015,6 +1026,109 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_a
end
end
+ context 'when the journal has a start date update' do
+ let(:journal) { journal_2_with_start_date }
+
+ context 'when the user has scheduled notifications activated' do
+ let(:recipient_notification_settings) do
+ [
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false
+ .merge(work_package_scheduled: true)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false
+ .merge(work_package_scheduled: true)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false
+ .merge(work_package_scheduled: true))
+ ]
+ end
+
+ it_behaves_like 'creates notification' do
+ let(:notification_channel_reasons) do
+ {
+ read_ian: false,
+ reason_ian: :scheduled,
+ read_mail: false,
+ reason_mail: :scheduled,
+ read_mail_digest: false,
+ reason_mail_digest: :scheduled
+ }
+ end
+ end
+ end
+
+ context 'when the user has scheduled 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 start or due date update' do
+ let(:journal) { journal_2_with_notes }
+
+ context 'with the user having scheduled notifications activated' do
+ let(:recipient_notification_settings) do
+ [
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false
+ .merge(work_package_scheduled: true)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false
+ .merge(work_package_scheduled: true)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false
+ .merge(work_package_processed: true))
+ ]
+ end
+
+ it_behaves_like 'creates no notification'
+ end
+ end
+
+ context 'when the journal has a due date update' do
+ let(:journal) { journal_2_with_due_date }
+
+ context 'when the user has scheduled notifications activated' do
+ let(:recipient_notification_settings) do
+ [
+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false
+ .merge(work_package_scheduled: true)),
+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false
+ .merge(work_package_scheduled: true)),
+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false
+ .merge(work_package_scheduled: true))
+ ]
+ end
+
+ it_behaves_like 'creates notification' do
+ let(:notification_channel_reasons) do
+ {
+ read_ian: false,
+ reason_ian: :scheduled,
+ read_mail: false,
+ reason_mail: :scheduled,
+ read_mail_digest: false,
+ reason_mail_digest: :scheduled
+ }
+ end
+ end
+ end
+
+ context 'when the user has scheduled 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 author has been deleted' do
let!(:deleted_user) { DeletedUser.first }
let(:user_property) { :assigned_to }
diff --git a/spec/services/user_preferences/update_service_integration_spec.rb b/spec/services/user_preferences/update_service_integration_spec.rb
index cb810088004..ddef7cb505a 100644
--- a/spec/services/user_preferences/update_service_integration_spec.rb
+++ b/spec/services/user_preferences/update_service_integration_spec.rb
@@ -61,7 +61,8 @@ describe UserPreferences::UpdateService, 'integration', type: :model do
work_package_commented: false,
work_package_created: true,
work_package_processed: true,
- work_package_prioritized: false
+ work_package_prioritized: false,
+ work_package_scheduled: false
}
]
}
@@ -77,6 +78,9 @@ describe UserPreferences::UpdateService, 'integration', type: :model do
expect(default_ian.involved).to eq true
expect(default_ian.work_package_commented).to eq false
expect(default_ian.work_package_created).to eq false
+ expect(default_ian.work_package_processed).to eq false
+ expect(default_ian.work_package_prioritized).to eq false
+ expect(default_ian.work_package_scheduled).to eq false
expect(subject.count).to eq 1
expect(subject.first.project_id).to eq nil
@@ -89,6 +93,7 @@ describe UserPreferences::UpdateService, 'integration', type: :model do
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.work_package_scheduled).to eq false
expect(subject.first).to eq(default_ian.reload)
expect(current_user.notification_settings.count).to eq(1)
@@ -121,6 +126,7 @@ describe UserPreferences::UpdateService, 'integration', type: :model do
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(subject.first.work_package_scheduled).to eq false
expect(current_user.notification_settings.count).to eq(1)