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

Remove channel from non-wp PR

Oliver Günther8dec991d0187
diff --git a/app/contracts/notifications/create_contract.rb b/app/contracts/notifications/create_contract.rb
index 3d57260fd00..4a370888222 100644
--- a/app/contracts/notifications/create_contract.rb
+++ b/app/contracts/notifications/create_contract.rb
@@ -41,6 +41,16 @@ module Notifications
validate :validate_recipient_present
validate :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
+ end
def validate_recipient_present
errors.add(:recipient, :blank) if model.recipient.blank?
diff --git a/app/contracts/user_preferences/params_contract.rb b/app/contracts/user_preferences/params_contract.rb
index 61b60eef21b..af1d95a1ff6 100644
--- a/app/contracts/user_preferences/params_contract.rb
+++ b/app/contracts/user_preferences/params_contract.rb
@@ -39,7 +39,7 @@ module UserPreferences
protected
def only_one_global_setting
- if has_more_than_one_global_channel?
+ if global_notifications.count > 1
errors.add :notification_settings, :only_one_global_setting
end
end
@@ -58,12 +58,6 @@ module UserPreferences
end
end
- def has_more_than_one_global_channel?
- global_notifications
- .group_by { |notification| notification[:channel] }
- .any? { |_, items| items.count > 1 }
- end
-
def global_notifications
notifications.select { |notification| notification[:project_id].nil? }
end
diff --git a/app/models/notification_setting.rb b/app/models/notification_setting.rb
index 644fb9f174d..a1e8b515d21 100644
--- a/app/models/notification_setting.rb
+++ b/app/models/notification_setting.rb
@@ -26,7 +26,6 @@ class NotificationSetting < ApplicationRecord
WORK_PACKAGE_PROCESSED,
WORK_PACKAGE_PRIORITIZED,
WORK_PACKAGE_SCHEDULED,
- ALL,
*email_settings
]
end
diff --git a/app/models/notifications/scopes/unread_mail_digest.rb b/app/models/notifications/scopes/unsent_mail.rb
similarity index 98%
rename from app/models/notifications/scopes/unread_mail_digest.rb
rename to app/models/notifications/scopes/unsent_mail.rb
index 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 UnsentMail
extend ActiveSupport::Concern
class_methods do
diff --git a/app/services/notifications/create_from_model_service.rb b/app/services/notifications/create_from_model_service.rb
index 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::CreateFromModelService
return 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::CreateFromModelService
attr_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_receivers
receivers = receivers_hash
@@ -255,7 +250,7 @@ class Notifications::CreateFromModelService
def add_receiver(receivers, collection, reason)
collection.each do |notification|
- receivers[notification.user_id][notification.channel] << reason
+ receivers[notification.user_id] << reason
end
end
@@ -265,9 +260,7 @@ class Notifications::CreateFromModelService
def receivers_hash
Hash.new do |hash, user|
- hash[user] = Hash.new do |channel_hash, channel|
- channel_hash[channel] = []
- end
+ hash[user] = []
end
end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 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.rb
index 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]
end
end
+ # rubocop:disable Metrics/AbcSize
def down
change_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;
SQL
end
+ # rubocop:enable Metrics/AbcSize
end
diff --git a/lib/api/v3/user_preferences/notification_setting_representer.rb b/lib/api/v3/user_preferences/notification_setting_representer.rb
index 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 API
class NotificationSettingRepresenter < ::API::Decorators::Single
include API::Decorators::LinkedResource
- property :channel
NotificationSetting.all_settings.each do |setting|
property setting
end
diff --git a/spec/contracts/notifications/create_contract_spec.rb b/spec/contracts/notifications/create_contract_spec.rb
index 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 do
let(:notification_reason) { nil }
let(:notification_read_ian) { nil }
- it_behaves_like 'contract is valid'
+ it_behaves_like 'contract is invalid', reason: :no_notification_reason
end
context 'without a subject' do
@@ -101,7 +101,7 @@ describe Notifications::CreateContract do
context 'with sent_mail true' do
let(: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_creation
end
end
end
diff --git a/spec/factories/notification_setting_factory.rb b/spec/factories/notification_setting_factory.rb
index 24ea0b9a026..f94a0c237e0 100644
--- a/spec/factories/notification_setting_factory.rb
+++ b/spec/factories/notification_setting_factory.rb
@@ -1,6 +1,5 @@
FactoryBot.define do
factory :notification_setting do
- all { false }
involved { true }
mentioned { true }
watched { true }
@@ -9,6 +8,14 @@ FactoryBot.define do
work_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 settings
user
end
diff --git a/spec/factories/user_factory.rb b/spec/factories/user_factory.rb
index 2017eb7f734..f477c0613e2 100644
--- a/spec/factories/user_factory.rb
+++ b/spec/factories/user_factory.rb
@@ -58,9 +58,9 @@ FactoryBot.define do
user.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)
]
end
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 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) do
let(: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.rb
index 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_settings
expect(in_project[:project_id]).to eq "1"
- expect(in_project[:channel]).to eq 'in_app'
expect(in_project[:all]).to be_truthy
expect(global[:project_id]).to eq nil
- expect(global[:channel]).to eq 'email'
expect(global[:all]).to eq false
expect(global[:mentioned]).to eq true
end
diff --git a/spec/services/notifications/create_from_journal_job_shared.rb b/spec/services/notifications/create_from_journal_job_shared.rb
index 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' do
end
let(:notification_settings_all_false) do
NotificationSetting
- .all_reasons
+ .all_settings
.index_with(false)
end
let(:notification_settings_all_true) do
NotificationSetting
- .all_reasons
+ .all_settings
.index_with(true)
end
diff --git a/spec/services/notifications/create_from_model_service_comment_spec.rb b/spec/services/notifications/create_from_model_service_comment_spec.rb
index 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
}
end
end
@@ -111,7 +111,7 @@ describe Notifications::CreateFromModelService, 'comment', with_settings: { jour
read_ian: nil,
reason: false,
read_mail: false,
- sent_mail: nil,
+ sent_mail: nil
}
end
end