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 channel from non-wp PR
Oliver Günther8dec991d0187
diff --git a/app/contracts/notifications/create_contract.rb b/app/contracts/notifications/create_contract.rbindex 3d57260fd00..4a370888222 100644--- a/app/contracts/notifications/create_contract.rb+++ b/app/contracts/notifications/create_contract.rb@@ -41,6 +41,16 @@ module Notificationsvalidate :validate_recipient_presentvalidate :validate_reason_present+ validate :validate_read+ validate :validate_sent++ def validate_read+ errors.add(:read_ian, :read_on_creation) if model.read_ian+ end++ def validate_sent+ errors.add(:sent_mail, :set_on_creation) if model.sent_mail+ enddef validate_recipient_presenterrors.add(:recipient, :blank) if model.recipient.blank?diff --git a/app/contracts/user_preferences/params_contract.rb b/app/contracts/user_preferences/params_contract.rbindex 61b60eef21b..af1d95a1ff6 100644--- a/app/contracts/user_preferences/params_contract.rb+++ b/app/contracts/user_preferences/params_contract.rb@@ -39,7 +39,7 @@ module UserPreferencesprotecteddef only_one_global_setting- if has_more_than_one_global_channel?+ if global_notifications.count > 1errors.add :notification_settings, :only_one_global_settingendend@@ -58,12 +58,6 @@ module UserPreferencesendend- def has_more_than_one_global_channel?- global_notifications- .group_by { |notification| notification[:channel] }- .any? { |_, items| items.count > 1 }- end-def global_notificationsnotifications.select { |notification| notification[:project_id].nil? }enddiff --git a/app/models/notification_setting.rb b/app/models/notification_setting.rbindex 644fb9f174d..a1e8b515d21 100644--- a/app/models/notification_setting.rb+++ b/app/models/notification_setting.rb@@ -26,7 +26,6 @@ class NotificationSetting < ApplicationRecordWORK_PACKAGE_PROCESSED,WORK_PACKAGE_PRIORITIZED,WORK_PACKAGE_SCHEDULED,- ALL,*email_settings]enddiff --git a/app/models/notifications/scopes/unread_mail_digest.rb b/app/models/notifications/scopes/unsent_mail.rbsimilarity index 98%rename from app/models/notifications/scopes/unread_mail_digest.rbrename to app/models/notifications/scopes/unsent_mail.rbindex 6f61be2f085..a1d422938cf 100644--- a/app/models/notifications/scopes/unread_mail_digest.rb+++ b/app/models/notifications/scopes/unsent_mail.rb@@ -30,7 +30,7 @@# Return digest mail notifications that are unread (have read_digest_mail: false)module Notifications::Scopes- module UnreadMailDigest+ module UnsentMailextend ActiveSupport::Concernclass_methods dodiff --git a/app/services/notifications/create_from_model_service.rb b/app/services/notifications/create_from_model_service.rbindex dc88413ab81..344b3e74364 100644--- a/app/services/notifications/create_from_model_service.rb+++ b/app/services/notifications/create_from_model_service.rb@@ -48,8 +48,8 @@ class Notifications::CreateFromModelServicereturn result if result.failure?- notification_receivers.each do |recipient_id, channel_reasons|- call = create_notification(recipient_id, channel_reasons)+ notification_receivers.each do |recipient_id, reasons|+ call = create_notification(recipient_id, reasons)result.add_dependent!(call)end@@ -60,28 +60,23 @@ class Notifications::CreateFromModelServiceattr_accessor :model- def create_notification(recipient_id, channel_reasons)+ def create_notification(recipient_id, reasons)notification_attributes = {recipient_id: recipient_id,project: project,resource: resource,journal: journal,- actor: user_with_fallback- }.merge(channel_attributes(channel_reasons))+ actor: user_with_fallback,+ reason: reasons.first,+ read_ian: false,+ sent_mail: false+ }Notifications::CreateService.new(user: user_with_fallback).call(notification_attributes)end- def channel_attributes(channel_reasons)- {- reason: strategy.supports_ian? && channel_reasons['in_app']&.first,- read_ian: strategy.supports_ian? && channel_reasons.keys.include?('in_app') ? false : nil,- sent_mail: strategy.supports_mail_digest? && channel_reasons.keys.include?('mail_digest') ? false : nil- }- end-def notification_receiversreceivers = receivers_hash@@ -255,7 +250,7 @@ class Notifications::CreateFromModelServicedef add_receiver(receivers, collection, reason)collection.each do |notification|- receivers[notification.user_id][notification.channel] << reason+ receivers[notification.user_id] << reasonendend@@ -265,9 +260,7 @@ class Notifications::CreateFromModelServicedef receivers_hashHash.new do |hash, user|- hash[user] = Hash.new do |channel_hash, channel|- channel_hash[channel] = []- end+ hash[user] = []endenddiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 62411929788..dfd43eb43bb 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -687,7 +687,7 @@ en:read_ian:read_on_creation: 'cannot be set to true on notification creation.'sent_mail:- read_on_creation: 'cannot be set to true on notification creation.'+ set_on_creation: 'cannot be set to true on notification creation.'reason:no_notification_reason: 'cannot be blank as IAN is chosen as a channel.'reason_mail_digest:diff --git a/db/migrate/20210914065555_cleanup_notifications.rb b/db/migrate/20210914065555_cleanup_notifications.rbindex 80385d60239..f1db1151997 100644--- a/db/migrate/20210914065555_cleanup_notifications.rb+++ b/db/migrate/20210914065555_cleanup_notifications.rb@@ -27,6 +27,7 @@ class CleanupNotifications < ActiveRecord::Migration[6.1]endend+ # rubocop:disable Metrics/AbcSizedef downchange_table :notifications, bulk: true do |t|t.boolean :read_mail, default: false, index: true@@ -73,4 +74,5 @@ class CleanupNotifications < ActiveRecord::Migration[6.1]FROM notification_settings;SQLend+ # rubocop:enable Metrics/AbcSizeenddiff --git a/lib/api/v3/user_preferences/notification_setting_representer.rb b/lib/api/v3/user_preferences/notification_setting_representer.rbindex 4c49e010696..cd04226810e 100644--- a/lib/api/v3/user_preferences/notification_setting_representer.rb+++ b/lib/api/v3/user_preferences/notification_setting_representer.rb@@ -34,7 +34,6 @@ module APIclass NotificationSettingRepresenter < ::API::Decorators::Singleinclude API::Decorators::LinkedResource- property :channelNotificationSetting.all_settings.each do |setting|property settingenddiff --git a/spec/contracts/notifications/create_contract_spec.rb b/spec/contracts/notifications/create_contract_spec.rbindex 20aa4f6d69a..afb0ec4f062 100644--- a/spec/contracts/notifications/create_contract_spec.rb+++ b/spec/contracts/notifications/create_contract_spec.rb@@ -77,7 +77,7 @@ describe Notifications::CreateContract dolet(:notification_reason) { nil }let(:notification_read_ian) { nil }- it_behaves_like 'contract is valid'+ it_behaves_like 'contract is invalid', reason: :no_notification_reasonendcontext 'without a subject' do@@ -101,7 +101,7 @@ describe Notifications::CreateContract docontext 'with sent_mail true' dolet(:notification_sent_mail) { true }- it_behaves_like 'contract is invalid', sent_mail: :read_on_creation+ it_behaves_like 'contract is invalid', sent_mail: :set_on_creationendendenddiff --git a/spec/factories/notification_setting_factory.rb b/spec/factories/notification_setting_factory.rbindex 24ea0b9a026..f94a0c237e0 100644--- a/spec/factories/notification_setting_factory.rb+++ b/spec/factories/notification_setting_factory.rb@@ -1,6 +1,5 @@FactoryBot.define dofactory :notification_setting do- all { false }involved { true }mentioned { true }watched { true }@@ -9,6 +8,14 @@ FactoryBot.define dowork_package_processed { false }work_package_prioritized { false }work_package_scheduled { false }+ news_added { false }+ news_commented { false }+ document_added { false }+ forum_messages { false }+ wiki_page_added { false }+ wiki_page_updated { false }+ membership_added { false }+ membership_updated { false }project { nil } # Default settingsuserenddiff --git a/spec/factories/user_factory.rb b/spec/factories/user_factory.rbindex 2017eb7f734..f477c0613e2 100644--- a/spec/factories/user_factory.rb+++ b/spec/factories/user_factory.rb@@ -58,9 +58,9 @@ FactoryBot.define douser.pref.save if factory.preferences.present?if user.notification_settings.empty?- all_true = NotificationSetting.all_reasons.index_with(true)+ all_true = NotificationSetting.all_settings.index_with(true)user.notification_settings = [- FactoryBot.create(:notification_setting, user: user, **all_true),+ FactoryBot.create(:notification_setting, user: user, **all_true)]enddiff --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 ae77c86e04d..95717ce7269 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@@ -69,10 +69,6 @@ describe ::API::V3::UserPreferences::NotificationSettingRepresenter, 'rendering'.not_to have_json_path('_type')end- it_behaves_like 'property', :channel do- let(:value) { notification_setting.channel }- end-NotificationSetting.all_settings.each do |property|it_behaves_like 'property', property.to_s.camelize(:lower) dolet(:value) { notification_setting.send property }diff --git a/spec/lib/api/v3/user_preferences/user_preference_representer_parsing_spec.rb b/spec/lib/api/v3/user_preferences/user_preference_representer_parsing_spec.rbindex 4c3b01b557f..0ae8f7210df 100644--- a/spec/lib/api/v3/user_preferences/user_preference_representer_parsing_spec.rb+++ b/spec/lib/api/v3/user_preferences/user_preference_representer_parsing_spec.rb@@ -43,7 +43,6 @@ describe ::API::V3::UserPreferences::UserPreferenceRepresenter,{'notifications' => [{- 'channel' => 'in_app','all' => true,'_links' => {'project' => {@@ -52,7 +51,6 @@ describe ::API::V3::UserPreferences::UserPreferenceRepresenter,}},{- 'channel' => 'email','all' => false,'mentioned' => true,'_links' => {@@ -71,11 +69,9 @@ describe ::API::V3::UserPreferences::UserPreferenceRepresenter,in_project, global = subject.notification_settingsexpect(in_project[:project_id]).to eq "1"- expect(in_project[:channel]).to eq 'in_app'expect(in_project[:all]).to be_truthyexpect(global[:project_id]).to eq nil- expect(global[:channel]).to eq 'email'expect(global[:all]).to eq falseexpect(global[:mentioned]).to eq trueenddiff --git a/spec/services/notifications/create_from_journal_job_shared.rb b/spec/services/notifications/create_from_journal_job_shared.rbindex 7772d25cf4f..0bf41e1a640 100644--- a/spec/services/notifications/create_from_journal_job_shared.rb+++ b/spec/services/notifications/create_from_journal_job_shared.rb@@ -52,13 +52,13 @@ shared_context 'with CreateFromJournalJob context' doendlet(:notification_settings_all_false) doNotificationSetting- .all_reasons+ .all_settings.index_with(false)endlet(:notification_settings_all_true) doNotificationSetting- .all_reasons+ .all_settings.index_with(true)enddiff --git a/spec/services/notifications/create_from_model_service_comment_spec.rb b/spec/services/notifications/create_from_model_service_comment_spec.rbindex f8760a01247..67c5f23c43a 100644--- a/spec/services/notifications/create_from_model_service_comment_spec.rb+++ b/spec/services/notifications/create_from_model_service_comment_spec.rb@@ -68,7 +68,7 @@ describe Notifications::CreateFromModelService, 'comment', with_settings: { jour{read_ian: nil,reason: false,- sent_mail: nil,+ sent_mail: nil}endend@@ -111,7 +111,7 @@ describe Notifications::CreateFromModelService, 'comment', with_settings: { jourread_ian: nil,reason: false,read_mail: false,- sent_mail: nil,+ sent_mail: nil}endend