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
remove work_package_updated from notified_events
ulferts8cfb94be7db5
diff --git a/app/services/notifications/journal_wp_notification_service.rb b/app/services/notifications/journal_wp_notification_service.rbindex 43fab770706..37690bb5ba2 100644--- a/app/services/notifications/journal_wp_notification_service.rb+++ b/app/services/notifications/journal_wp_notification_service.rb@@ -43,7 +43,7 @@ class Notifications::JournalWpNotificationServicedef call(journal, send_notifications)return nil if abort_sending?(journal, send_notifications)- notification_receivers(journal.journable, journal).each do |recipient_id, channel_reasons|+ notification_receivers(journal).each do |recipient_id, channel_reasons|create_notification(journal,recipient_id,channel_reasons)@@ -77,23 +77,22 @@ class Notifications::JournalWpNotificationService}end- def notification_receivers(work_package, journal)+ def notification_receivers(journal)receivers = receivers_hash- add_receiver(receivers, settings_of_mentioned(journal), :mentioned)- 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)- add_receiver(receivers, settings_of_created(journal), :created)- add_receiver(receivers, settings_of_processed(journal), :processed)- add_receiver(receivers, settings_of_prioritized(journal), :prioritized)+ %i(mentioned involved watched subscribed commented created processed prioritized).each do |reason|+ add_receivers_by_reason(receivers, journal, reason)+ endremove_self_recipient(receivers, journal)receiversend+ def add_receivers_by_reason(receivers, journal, reason)+ add_receiver(receivers, send(:"settings_of_#{reason}", journal), reason)+ end+def settings_of_mentioned(journal)applicable_settings(mentioned_ids(journal),journal.data.project,@@ -118,7 +117,9 @@ class Notifications::JournalWpNotificationService:all)end- def settings_of_watched(work_package)+ def settings_of_watched(journal)+ work_package = journal.journable+applicable_settings(work_package.watcher_users,work_package.project,:watched)@@ -194,11 +195,7 @@ class Notifications::JournalWpNotificationServiceenddef send_notification?(journal, send_notifications)- send_notifications && ::UserMailer.perform_deliveries && send_notification_setting?(journal)- end-- def send_notification_setting?(journal)- notify_for_wp_updated?(journal) || journal.initial?+ send_notifications && ::UserMailer.perform_deliveriesenddef mention_matches(journal)@@ -222,14 +219,6 @@ class Notifications::JournalWpNotificationService}end- def notify_for_wp_updated?(journal)- notification_enabled?('work_package_updated') && !journal.initial?- end-- def notification_enabled?(name)- Setting.notified_events.include?(name)- end-def abort_sending?(journal, send_notifications)!send_notification?(journal, send_notifications) || journal.noop?enddiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 24594ced0cc..1d0508b4ddd 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1900,7 +1900,6 @@ en:label_work_package_status_new: "New status"label_work_package_status_plural: "Work package statuses"label_work_package_types: "Work package types"- label_work_package_updated: "Work package updated"label_work_package_tracking: "Work package tracking"label_work_package_view_all: "View all work packages"label_workflow: "Workflow"diff --git a/config/settings.yml b/config/settings.ymlindex 95c703bd4b8..647f98ea154 100644--- a/config/settings.yml+++ b/config/settings.yml@@ -236,7 +236,6 @@ cross_project_work_package_relations:notified_events:serialized: truedefault:- - work_package_updated- news_added- news_comment_added- file_addeddiff --git a/db/migrate/20210802114054_add_notification_setting_options.rb b/db/migrate/20210802114054_add_notification_setting_options.rbindex 8cc31263f3b..84ae52751da 100644--- a/db/migrate/20210802114054_add_notification_setting_options.rb+++ b/db/migrate/20210802114054_add_notification_setting_options.rb@@ -1,13 +1,34 @@class AddNotificationSettingOptions < ActiveRecord::Migration[6.1]def change+ add_notification_settings_options+ update_notified_events++ # TODO: add index to all boolean fields+ end++ def add_notification_settings_optionschange_table :notification_settings, bulk: true do |t|t.boolean :work_package_commented, default: falset.boolean :work_package_created, default: falset.boolean :work_package_processed, default: falset.boolean :work_package_prioritized, default: falseend+ end- # TODO: remove existing notification setting from settings- # TODO: add index to all boolean fields+ def update_notified_events+ event_types = %w(work_package_added work_package_updated work_package_note_added status_updated work_package_priority_updated)++ # rubocop:disable Rails/WhereExists+ # The Setting.exists? method is overwritten+ reversible do |dir|+ dir.up do+ Setting.notified_events = Setting.notified_events - event_types if Setting.where(name: 'notified_events').exists?+ end++ dir.down do+ Setting.notified_events = Setting.notified_events + event_types if Setting.where(name: 'notified_events').exists?+ end+ end+ # rubocop:enable Rails/WhereExistsendenddiff --git a/lib/open_project/notifiable.rb b/lib/open_project/notifiable.rbindex adbd9bc3aaa..e78a9254d42 100644--- a/lib/open_project/notifiable.rb+++ b/lib/open_project/notifiable.rb@@ -30,7 +30,6 @@module OpenProjectNOTIFIABLE = [- %w(work_package_updated),%w(news_added),%w(news_comment_added),%w(file_added),diff --git a/spec/lib/open_project/notifiable_spec.rb b/spec/lib/open_project/notifiable_spec.rbindex 7de7a6ec8c5..f76aa6aa616 100644--- a/spec/lib/open_project/notifiable_spec.rb+++ b/spec/lib/open_project/notifiable_spec.rb@@ -32,8 +32,8 @@ require 'spec_helper'describe OpenProject::Notifiable dodescribe '#all' doit 'matches expected list' do- expected = %w(work_package_updated news_added news_comment_added- file_added message_posted wiki_content_added wiki_content_updated membership_added membership_updated)+ expected = %w(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.rbindex 24d3d026b7a..ceffcc9b1a9 100644--- a/spec/services/notifications/journal_wp_notification_service_spec.rb+++ b/spec/services/notifications/journal_wp_notification_service_spec.rb@@ -120,9 +120,6 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_awork_package.journals.lastendlet(:send_notifications) { true }- let(:notification_setting) do- %w(work_package_updated)- enddef calldescribed_class.call(journal, send_notifications)@@ -133,7 +130,6 @@ describe Notifications::JournalWpNotificationService, with_settings: { journal_aallow(OpenProject::Notifications).to receive(:send) # ... and do nothinglogin_as(author)- allow(Setting).to receive(:notified_events).and_return(notification_setting)endshared_examples_for 'creates notification' dodiff --git a/spec/workers/notifications/journal_completed_job_integration_spec.rb b/spec/workers/notifications/journal_completed_job_integration_spec.rbindex 5868e8b040f..83d1140e1c1 100644--- a/spec/workers/notifications/journal_completed_job_integration_spec.rb+++ b/spec/workers/notifications/journal_completed_job_integration_spec.rb@@ -53,9 +53,9 @@ describe Notifications::JournalCompletedJob, type: :model doauthor: author,assigned_to: recipient)end- let(:journal) { journal_1 }- let(:journal_1) { work_package.journals.first }- let(:journal_2) do+ let(:journal) { journal1 }+ let(:journal1) { work_package.journals.first }+ let(:journal2) dowork_package.add_journal author, 'something I have to say'work_package.save(validate: false)work_package.journals.last@@ -93,7 +93,7 @@ describe Notifications::JournalCompletedJob, type: :model doenddescribe 'journal creation' do- context 'work_package_created' do+ context 'with the work package being created' dobefore doFactoryBot.create(:work_package, project: project)end@@ -101,7 +101,7 @@ describe Notifications::JournalCompletedJob, type: :model doit_behaves_like 'sends notification'end- context 'work_package_updated' do+ context 'with the work package being updated' dobefore dowork_package.add_journal(author)work_package.subject = 'A change to the issue'@@ -111,7 +111,7 @@ describe Notifications::JournalCompletedJob, type: :model doit_behaves_like 'sends notification'end- context 'work_package_note_added' do+ context 'with the journal being updated with a note' dobefore dowork_package.add_journal(author, 'This update has a note')work_package.save!(validate: false)@@ -122,7 +122,7 @@ describe Notifications::JournalCompletedJob, type: :model doendend- context 'for wiki page content' do+ context 'with wiki page content' dolet(:wiki_page_content) dowiki = FactoryBot.create(:wiki,project: project)@@ -130,9 +130,9 @@ describe Notifications::JournalCompletedJob, type: :model doFactoryBot.create(:wiki_page_with_content, wiki: wiki).contentend- let(:journal) { journal_1 }- let(:journal_1) { wiki_page_content.journals.first }- let(:journal_2) do+ let(:journal) { journal1 }+ let(:journal1) { wiki_page_content.journals.first }+ let(:journal2) dowiki_page_content.add_journal author, 'something I have to say'wiki_page_content.save(validate: false)wiki_page_content.journals.last