OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
add work package created notification setting
ulfertsa1074bcb93b5
diff --git a/app/models/notification.rb b/app/models/notification.rbindex cfd2645d546..bfb23667c0b 100644--- a/app/models/notification.rb+++ b/app/models/notification.rb@@ -1,7 +1,28 @@class Notification < ApplicationRecord- 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+ enum reason_ian: {+ mentioned: 0,+ involved: 1,+ watched: 2,+ subscribed: 3,+ commented: 4,+ created: 5+ }, _prefix: :ian+ enum reason_mail: {+ mentioned: 0,+ involved: 1,+ watched: 2,+ subscribed: 3,+ commented: 4,+ created: 5+ }, _prefix: :mail+ enum reason_mail_digest: {+ mentioned: 0,+ involved: 1,+ watched: 2,+ subscribed: 3,+ commented: 4,+ created: 5+ }, _prefix: :mail_digestbelongs_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.rbindex 1f3702d39a3..c0654f0e7a5 100644--- a/app/services/notifications/journal_wp_notification_service.rb+++ b/app/services/notifications/journal_wp_notification_service.rb@@ -85,6 +85,7 @@ class Notifications::JournalWpNotificationServiceadd_receiver(receivers, settings_of_watched(work_package), :watched)add_receiver(receivers, settings_of_subscribed(journal), :subscribed)add_receiver(receivers, settings_of_commented(journal), :commented)+ add_receiver(receivers, settings_of_created(journal), :created)remove_self_recipient(receivers, journal)@@ -129,6 +130,14 @@ class Notifications::JournalWpNotificationService:work_package_commented)end+ def settings_of_created(journal)+ scope = journal.initial? ? User.all : User.none++ applicable_settings(scope,+ journal.data.project,+ :work_package_created)+ end+def applicable_settings(user_scope, project, reason)NotificationSetting.applicable(project)@@ -171,8 +180,7 @@ class Notifications::JournalWpNotificationServiceenddef send_notification_setting?(journal)- notify_for_wp_added?(journal) ||- notify_for_wp_updated?(journal) ||+ notify_for_wp_updated?(journal) ||notify_for_status?(journal) ||notify_for_priority(journal)end@@ -198,10 +206,6 @@ class Notifications::JournalWpNotificationService}end- def notify_for_wp_added?(journal)- notification_enabled?('work_package_added') && journal.initial?- end-def notify_for_wp_updated?(journal)notification_enabled?('work_package_updated') && !journal.initial?enddiff --git a/app/services/user_preferences/update_service.rb b/app/services/user_preferences/update_service.rbindex 1555ae6cf2c..62c1086686e 100644--- a/app/services/user_preferences/update_service.rb+++ b/app/services/user_preferences/update_service.rb@@ -83,7 +83,7 @@ module UserPreferenceson_duplicate_key_update: {conflict_target: conflict_target,index_predicate: index_predicate,- columns: %i[watched involved mentioned work_package_commented all]+ columns: %i[watched involved mentioned work_package_commented work_package_created all]},validate: false).idsdiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 597dcce7ed8..8ef125f5f75 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1890,7 +1890,6 @@ en:label_wiki_show_submenu_item: "Show as submenu item of "label_wiki_start: "Start page"label_work_package: "Work package"- label_work_package_added: "Work package added"label_work_package_attachments: "Work package attachments"label_work_package_category_new: "New category"label_work_package_category_plural: "Work package categories"diff --git a/config/locales/js-en.yml b/config/locales/js-en.ymlindex e46f659d127..507fca1a8ed 100644--- a/config/locales/js-en.yml+++ b/config/locales/js-en.yml@@ -582,7 +582,8 @@ en:involved: 'I am involved'mentioned: 'I was mentioned'watched: 'I am watching'- work_package_commented: 'Comment on work package'+ work_package_commented: 'Work package commented'+ work_package_created: 'Work package created'all: 'All events'add: 'Add setting for project'already_selected: 'This project is already selected'diff --git a/config/settings.yml b/config/settings.ymlindex ec686262f49..6e00b10c71c 100644--- a/config/settings.yml+++ b/config/settings.yml@@ -236,7 +236,6 @@ cross_project_work_package_relations:notified_events:serialized: truedefault:- - work_package_added- work_package_updated- status_updated- work_package_priority_updateddiff --git a/db/migrate/20210802114054_add_notification_setting_options.rb b/db/migrate/20210802114054_add_notification_setting_options.rbindex 5c3adb64c2d..a8a5cc2e281 100644--- a/db/migrate/20210802114054_add_notification_setting_options.rb+++ b/db/migrate/20210802114054_add_notification_setting_options.rb@@ -1,6 +1,9 @@class AddNotificationSettingOptions < ActiveRecord::Migration[6.1]def change- add_column :notification_settings, :work_package_commented, :boolean, default: false+ change_table :notification_settings, bulk: true do |t|+ t.boolean :work_package_commented, default: false+ t.boolean :work_package_created, default: false+ end# TODO: remove existing notification setting from settingsenddiff --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.htmlindex 6f54de5aef8..ab81926b5aa 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.workPackageCreated || setting.all"+ [disabled]="setting.all"+ (change)="update({ workPackageCreated: $event.target.checked })"+ data-qa-notification-type="work_package_created"+ [attr.aria-label]="text.work_package_created_header"+ />+</td><td><inputtype="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.tsindex 6e524ac00f0..e3d2a83b636 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@@ -29,6 +29,7 @@ export class NotificationSettingRowComponent implements OnInit {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'),+ work_package_created_header: this.I18n.t('js.notifications.settings.work_package_created'),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.htmlindex ffe678b02b9..d075b3f589c 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_created_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.tsindex 179e0898360..47fc4e8ac0f 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@@ -35,6 +35,7 @@ export class NotificationSettingsTableComponent {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'),+ work_package_created_header: this.I18n.t('js.notifications.settings.work_package_created'),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.tsindex 9b7faf091ee..03f428a336d 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@@ -9,6 +9,7 @@ export interface NotificationSetting {involved:boolean;mentioned:boolean;workPackageCommented:boolean;+ workPackageCreated:boolean;all:boolean;}@@ -24,6 +25,7 @@ export function buildNotificationSetting(project:null|HalSourceLink, params:Partmentioned: true,watched: true,workPackageCommented: true,+ workPackageCreated: 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.rbindex 5590201c4de..d01bc72c2d8 100644--- a/lib/api/v3/user_preferences/notification_setting_representer.rb+++ b/lib/api/v3/user_preferences/notification_setting_representer.rb@@ -40,6 +40,7 @@ module APIproperty :mentionedproperty :allproperty :work_package_commented+ property :work_package_createdassociated_resource :project,skip_render: ->(*) { true },diff --git a/lib/open_project/notifiable.rb b/lib/open_project/notifiable.rbindex bd949dd3a67..2c03c5d6bc0 100644--- a/lib/open_project/notifiable.rb+++ b/lib/open_project/notifiable.rb@@ -30,7 +30,6 @@module OpenProjectNOTIFIABLE = [- %w(work_package_added),%w(work_package_updated),%w(status_updated work_package_updated),%w(work_package_priority_updated work_package_updated),diff --git a/spec/factories/notification_setting_factory.rb b/spec/factories/notification_setting_factory.rbindex 21a4510195e..25c390361bb 100644--- a/spec/factories/notification_setting_factory.rb+++ b/spec/factories/notification_setting_factory.rb@@ -5,7 +5,8 @@ FactoryBot.define doinvolved { true }mentioned { true }watched { true }- work_package_commented { true }+ work_package_commented { false }+ work_package_created { false }project { nil } # Default settingsuserdiff --git a/spec/features/notifications/digest_mail_spec.rb b/spec/features/notifications/digest_mail_spec.rbindex 59b9cf96f4c..311ebcefc63 100644--- a/spec/features/notifications/digest_mail_spec.rb+++ b/spec/features/notifications/digest_mail_spec.rb@@ -19,18 +19,21 @@ describe "Digest email", type: :feature, js: true dowatched: false,mentioned: false,work_package_commented: false,+ work_package_created: false,all: false),FactoryBot.build(:in_app_notification_setting,involved: false,watched: false,mentioned: false,work_package_commented: false,+ work_package_created: false,all: false),FactoryBot.build(:mail_digest_notification_setting,involved: true,watched: true,mentioned: true,work_package_commented: true,+ work_package_created: true,all: false)]end@@ -53,6 +56,7 @@ describe "Digest email", type: :feature, js: true domentioned: true,watched: true,work_package_commented: true,+ work_package_created: true,all: falsenotification_settings_page.configure_channel :mail_digest,@@ -61,6 +65,7 @@ describe "Digest email", type: :feature, js: true domentioned: true,watched: true,work_package_commented: false,+ work_package_created: false,all: falsenotification_settings_page.add_row(mute_project)@@ -71,6 +76,7 @@ describe "Digest email", type: :feature, js: true domentioned: false,watched: false,work_package_commented: false,+ work_package_created: false,all: falsenotification_settings_page.savediff --git a/spec/features/users/notifications/shared_examples.rb b/spec/features/users/notifications/shared_examples.rbindex 80c679343a7..15f385b7672 100644--- a/spec/features/users/notifications/shared_examples.rb+++ b/spec/features/users/notifications/shared_examples.rb@@ -18,6 +18,7 @@ shared_examples 'notification settings workflow' domentioned: true,watched: true,work_package_commented: true,+ work_package_created: true,all: false# Set settings for project email@@ -27,6 +28,7 @@ shared_examples 'notification settings workflow' domentioned: true,watched: false,work_package_commented: false,+ work_package_created: false,all: false# Set settings for project email digest@@ -36,6 +38,7 @@ shared_examples 'notification settings workflow' domentioned: true,watched: false,work_package_commented: true,+ work_package_created: true,all: truesettings_page.save@@ -51,6 +54,7 @@ shared_examples 'notification settings workflow' doexpect(in_app.watched).to be_falseyexpect(in_app.all).to be_falseyexpect(in_app.work_package_commented).to be_falsey+ expect(in_app.work_package_created).to be_falseymail = notification_settings.find_by(project: project, channel: :mail)expect(mail.involved).to be_truthy@@ -58,6 +62,7 @@ shared_examples 'notification settings workflow' doexpect(mail.watched).to be_truthyexpect(mail.all).to be_falseyexpect(mail.work_package_commented).to be_truthy+ expect(mail.work_package_created).to be_truthymail_digest = notification_settings.find_by(project: project, channel: :mail_digest)expect(mail_digest.involved).to be_falsey@@ -65,6 +70,7 @@ shared_examples 'notification settings workflow' doexpect(mail_digest.watched).to be_falseyexpect(mail_digest.all).to be_truthyexpect(mail_digest.work_package_commented).to be_truthy+ expect(mail_digest.work_package_created).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.rbindex b330ede57cd..51b87d5f8e1 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@@ -92,6 +92,10 @@ describe ::API::V3::UserPreferences::NotificationSettingRepresenter, 'rendering'it_behaves_like 'property', :workPackageCommented dolet(:value) { notification_setting.work_package_commented }end++ it_behaves_like 'property', :workPackageCreated do+ let(:value) { notification_setting.work_package_created }+ endenddescribe '_embedded' dodiff --git a/spec/lib/open_project/notifiable_spec.rb b/spec/lib/open_project/notifiable_spec.rbindex d9c65f57759..d6c8888a44c 100644--- a/spec/lib/open_project/notifiable_spec.rb+++ b/spec/lib/open_project/notifiable_spec.rb@@ -32,8 +32,7 @@ require 'spec_helper'describe OpenProject::Notifiable dodescribe '#all' doit 'matches expected list' do- expected = %w(work_package_added work_package_updated- status_updated work_package_priority_updated news_added news_comment_added+ expected = %w(work_package_updated status_updated work_package_priority_updated news_added news_comment_addedfile_added message_posted wiki_content_added wiki_content_updated membership_added membership_updated)expect(described_class.all.map(&:name))diff --git a/spec/models/work_package/work_package_action_mailer_spec.rb b/spec/models/work_package/work_package_action_mailer_spec.rbindex beac7fb2c99..9bc05db0b0a 100644--- a/spec/models/work_package/work_package_action_mailer_spec.rb+++ b/spec/models/work_package/work_package_action_mailer_spec.rb@@ -32,13 +32,13 @@ describe WorkPackage, type: :model dodescribe ActionMailer::Base dolet(:user_1) doFactoryBot.create(:user,- mail: '[email protected]',- member_in_project: project)+ mail: '[email protected]',+ member_in_project: project)endlet(:user_2) doFactoryBot.create(:user,- mail: '[email protected]',- member_in_project: project)+ mail: '[email protected]',+ member_in_project: project)endlet(:project) { FactoryBot.create(:project) }let(:work_package) { FactoryBot.build(:work_package, project: project) }diff --git a/spec/services/notifications/journal_wp_notification_service_spec.rb b/spec/services/notifications/journal_wp_notification_service_spec.rbindex e81cfceb875..425d8ae53a4 100644--- a/spec/services/notifications/journal_wp_notification_service_spec.rb+++ b/spec/services/notifications/journal_wp_notification_service_spec.rb@@ -56,7 +56,8 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_ainvolved: false,watched: false,mentioned: false,- work_package_commented: false+ work_package_commented: false,+ work_package_created: false}endlet(:recipient_notification_settings) do@@ -118,7 +119,7 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_aendlet(:send_notifications) { true }let(:notification_setting) do- %w(work_package_added work_package_updated status_updated work_package_priority_updated)+ %w(work_package_updated status_updated work_package_priority_updated)enddef call@@ -763,11 +764,44 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_aendend- context 'when notification for work_package_added disabled' do- let(:notification_setting) { %w(work_package_updated) }- let(:user_property) { :assigned_to }+ context 'when a work package is created' do+ context 'when the user configured to be notified' do+ let(:recipient_notification_settings) do+ [+ FactoryBot.build(:mail_notification_setting, **notification_settings_all_false+ .merge(work_package_created: true)),+ FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false+ .merge(work_package_created: true)),+ FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false+ .merge(work_package_created: true))+ ]+ end- it_behaves_like 'creates no notification'+ it_behaves_like 'creates notification' do+ let(:notification_channel_reasons) do+ {+ read_ian: false,+ reason_ian: :created,+ read_mail: false,+ reason_mail: :created,+ read_mail_digest: false,+ reason_mail_digest: :created+ }+ end+ end+ end++ context 'when the user did not configure to be notified' do+ let(:recipient_notification_settings) do+ [+ 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++ it_behaves_like 'creates no notification'+ endendcontext 'when the journal has a note' do@@ -836,7 +870,7 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_alet(:user_property) { :assigned_to }context 'notification for work_package_updated and status_updated disabled' do- let(:notification_setting) { %w(work_package_added work_package_priority_updated) }+ let(:notification_setting) { %w(work_package_priority_updated) }it_behaves_like 'creates no notification'end@@ -881,7 +915,7 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_alet(:user_property) { :assigned_to }context 'notification for work_package_updated and work_package_priority_updated disabled' do- let(:notification_setting) { %w(work_package_added status_updated) }+ let(:notification_setting) { %w(status_updated) }it_behaves_like 'creates no notification'enddiff --git a/spec/services/user_preferences/update_service_integration_spec.rb b/spec/services/user_preferences/update_service_integration_spec.rbindex 963fbc5a089..34af30d0e55 100644--- a/spec/services/user_preferences/update_service_integration_spec.rb+++ b/spec/services/user_preferences/update_service_integration_spec.rb@@ -58,7 +58,8 @@ describe UserPreferences::UpdateService, 'integration', type: :model doall: false,watched: false,involved: true,- work_package_commented: false+ work_package_commented: false,+ work_package_created: true}]}@@ -72,7 +73,8 @@ describe UserPreferences::UpdateService, 'integration', type: :model doexpect(default_ian.watched).to eq trueexpect(default_ian.mentioned).to eq trueexpect(default_ian.involved).to eq true- expect(default_ian.work_package_commented).to eq true+ expect(default_ian.work_package_commented).to eq false+ expect(default_ian.work_package_created).to eq falseexpect(subject.count).to eq 1expect(subject.first.project_id).to eq nil@@ -82,6 +84,7 @@ describe UserPreferences::UpdateService, 'integration', type: :model doexpect(subject.first.watched).to eq falseexpect(subject.first.involved).to eq trueexpect(subject.first.work_package_commented).to eq false+ expect(subject.first.work_package_created).to eq trueexpect(subject.first).to eq(default_ian.reload)expect(current_user.notification_settings.count).to eq(1)@@ -111,6 +114,7 @@ describe UserPreferences::UpdateService, 'integration', type: :model doexpect(subject.first.watched).to eq falseexpect(subject.first.involved).to eq falseexpect(subject.first.work_package_commented).to eq false+ expect(subject.first.work_package_created).to eq falseexpect(current_user.notification_settings.count).to eq(1)diff --git a/spec_legacy/unit/mail_handler_spec.rb b/spec_legacy/unit/mail_handler_spec.rbindex 15e119fb202..d41255edbcf 100644--- a/spec_legacy/unit/mail_handler_spec.rb+++ b/spec_legacy/unit/mail_handler_spec.rb@@ -272,8 +272,6 @@ describe MailHandler, type: :model doendit 'should add work package should send email notification' do- Setting.notified_events = ['work_package_added']-User.find(2).notification_settings.create(channel: :mail, all: true)# This email contains: 'Project: onlinestore'