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

Oliver Günther99f767681315
diff --git a/app/models/users/scopes/notified_on_all.rb b/app/models/users/scopes/notified_on_all.rb
deleted file mode 100644
index 1c0d7e4f9a8..00000000000
--- a/app/models/users/scopes/notified_on_all.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-#-- encoding: UTF-8
-
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2021 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-# Return all users who want to be notified on every activity within a project.
-# If there is only the global notification setting in place, that one is authoritative.
-# If there is a project specific setting in place, it is the project specific setting instead.
-module Users::Scopes
- module NotifiedOnAll
- extend ActiveSupport::Concern
-
- class_methods do
- def notified_on_all(project)
- global_settings = NotificationSetting
- .where(all: true, project: nil)
- project_settings_not_all = NotificationSetting
- .where(project: project)
- .group(:user_id)
- .having('NOT bool_or("all")')
- project_settings = NotificationSetting
- .where(all: true, project: project)
-
- where(id: global_settings.select(:user_id))
- .where.not(id: project_settings_not_all.select(:user_id))
- .or(User.where(id: project_settings.select(:user_id)))
- end
- end
- end
-end
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index 136adc9b5a5..4ca3f5147b9 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -594,7 +594,7 @@ en:
work_package_commented: 'All new comments'
work_package_created: 'New work packages'
work_package_processed: 'All status changes'
- work_package_prioritized: 'all priority changes'
+ work_package_prioritized: 'All priority changes'
work_package_scheduled: 'All date changes'
global:
immediately:
diff --git a/spec/factories/notification_setting_factory.rb b/spec/factories/notification_setting_factory.rb
index 635b6135721..24ea0b9a026 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
- channel { :mail }
all { false }
involved { true }
mentioned { true }
@@ -12,17 +11,5 @@ FactoryBot.define do
work_package_scheduled { false }
project { nil } # Default settings
user
-
- factory :mail_notification_setting do
- channel { :mail }
- end
-
- factory :mail_digest_notification_setting do
- channel { :mail_digest }
- end
-
- factory :in_app_notification_setting do
- channel { :in_app }
- end
end
end
diff --git a/spec/factories/user_factory.rb b/spec/factories/user_factory.rb
index d522f2f823d..659953fdbd8 100644
--- a/spec/factories/user_factory.rb
+++ b/spec/factories/user_factory.rb
@@ -55,14 +55,12 @@ FactoryBot.define do
end
callback(:after_create) do |user, factory|
- user.pref.save unless factory.preferences&.empty?
+ user.pref.save if factory.preferences.present?
if user.notification_settings.empty?
all_true = NotificationSetting.all_settings.index_with(true)
user.notification_settings = [
- FactoryBot.create(:mail_notification_setting, user: user, **all_true),
- FactoryBot.create(:in_app_notification_setting, user: user, **all_true),
- FactoryBot.create(:mail_digest_notification_setting, user: user)
+ FactoryBot.create(:notification_setting, user: user, **all_true),
]
end
diff --git a/spec/models/mail_handler_spec.rb b/spec/models/mail_handler_spec.rb
index fe885dfb9d6..76b345b325a 100644
--- a/spec/models/mail_handler_spec.rb
+++ b/spec/models/mail_handler_spec.rb
@@ -453,9 +453,7 @@ describe MailHandler, type: :model do
assignee = FactoryBot.create(:user,
member_in_project: project,
member_with_permissions: %i(view_work_packages),
- notification_settings: [FactoryBot.build(:mail_notification_setting,
- all: false,
- involved: true)])
+ notification_settings: [FactoryBot.build(:notification_setting, involved: true)])
work_package.update_column(:assigned_to_id, assignee.id)
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 107f3caa30f..36c4d605802 100644
--- a/spec/services/notifications/create_from_model_service_comment_spec.rb
+++ b/spec/services/notifications/create_from_model_service_comment_spec.rb
@@ -77,9 +77,7 @@ describe Notifications::CreateFromModelService, 'comment', with_settings: { jour
context 'with the user having registered for involved notifications' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(involved: true)),
- FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(involved: true)),
- FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(involved: true))
+ FactoryBot.build(:notification_setting, **notification_settings_all_false.merge(involved: true))
]
end
@@ -89,9 +87,7 @@ describe Notifications::CreateFromModelService, 'comment', with_settings: { jour
context 'with the user having registered for no notifications' 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)
+ FactoryBot.build(:notification_setting, **notification_settings_all_false)
]
end
@@ -101,9 +97,7 @@ describe Notifications::CreateFromModelService, 'comment', with_settings: { jour
context 'with the user having registered for watcher notifications and watching the news' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(watched: true)),
- FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(watched: true)),
- FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(watched: true))
+ FactoryBot.build(:notification_setting, **notification_settings_all_false.merge(watched: true))
]
end
@@ -126,9 +120,7 @@ describe Notifications::CreateFromModelService, 'comment', with_settings: { jour
context 'with the user not having registered for watcher notifications and watching the news' 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)
+ FactoryBot.build(:notification_setting, **notification_settings_all_false)
]
end
@@ -142,9 +134,7 @@ describe Notifications::CreateFromModelService, 'comment', with_settings: { jour
context 'with the user having registered for watcher notifications and not watching the news' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(watched: true)),
- FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(watched: true)),
- FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(watched: true))
+ FactoryBot.build(:notification_setting, **notification_settings_all_false.merge(watched: true))
]
end
diff --git a/spec/services/notifications/create_from_model_service_message_spec.rb b/spec/services/notifications/create_from_model_service_message_spec.rb
index 8ffe66d718f..e9582c83e07 100644
--- a/spec/services/notifications/create_from_model_service_message_spec.rb
+++ b/spec/services/notifications/create_from_model_service_message_spec.rb
@@ -78,9 +78,7 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jour
context 'with the user having registered for involved notifications' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(involved: true)),
- FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(involved: true)),
- FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(involved: true))
+ FactoryBot.build(:notification_setting, **notification_settings_all_false.merge(involved: true))
]
end
@@ -90,9 +88,7 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jour
context 'with the user having registered for no notifications' 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)
+ FactoryBot.build(:notification_setting, **notification_settings_all_false)
]
end
@@ -102,9 +98,7 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jour
context 'with the user having registered for watcher notifications and watching the forum' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(watched: true)),
- FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(watched: true)),
- FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(watched: true))
+ FactoryBot.build(:notification_setting, **notification_settings_all_false.merge(watched: true))
]
end
@@ -126,9 +120,7 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jour
context 'with the user not having registered for watcher notifications and watching the forum' 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)
+ FactoryBot.build(:notification_setting, **notification_settings_all_false)
]
end
@@ -142,9 +134,7 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jour
context 'with the user having registered for watcher notifications and not watching the forum nor root message' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(watched: true)),
- FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(watched: true)),
- FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(watched: true))
+ FactoryBot.build(:notification_setting, **notification_settings_all_false.merge(watched: true))
]
end
@@ -154,9 +144,7 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jour
context 'with the user having registered for watcher notifications and watching the root' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(watched: true)),
- FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(watched: true)),
- FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(watched: true))
+ FactoryBot.build(:notification_setting, **notification_settings_all_false.merge(watched: true))
]
end
@@ -178,9 +166,7 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jour
context 'with the user not having registered for watcher notifications and watching the root' 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)
+ FactoryBot.build(:notification_setting, **notification_settings_all_false)
]
end
@@ -221,9 +207,7 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jour
context 'with the user having registered for involved notifications' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(involved: true)),
- FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(involved: true)),
- FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(involved: true))
+ FactoryBot.build(:notification_setting, **notification_settings_all_false.merge(involved: true))
]
end
@@ -233,9 +217,7 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jour
context 'with the user having registered for no notifications' 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)
+ FactoryBot.build(:notification_setting, **notification_settings_all_false)
]
end
@@ -245,9 +227,7 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jour
context 'with the user having registered for watcher notifications and watching the forum' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(watched: true)),
- FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(watched: true)),
- FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(watched: true))
+ FactoryBot.build(:notification_setting, **notification_settings_all_false.merge(watched: true))
]
end
@@ -269,9 +249,7 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jour
context 'with the user not having registered for watcher notifications and watching the forum' 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)
+ FactoryBot.build(:notification_setting, **notification_settings_all_false)
]
end
@@ -285,9 +263,7 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jour
context 'with the user having registered for watcher notifications and not watching the forum nor root message' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(watched: true)),
- FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(watched: true)),
- FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(watched: true))
+ FactoryBot.build(:notification_setting, **notification_settings_all_false.merge(watched: true))
]
end
@@ -297,9 +273,7 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jour
context 'with the user having registered for watcher notifications and watching the root' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(watched: true)),
- FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(watched: true)),
- FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(watched: true))
+ FactoryBot.build(:notification_setting, **notification_settings_all_false.merge(watched: true))
]
end
@@ -321,9 +295,7 @@ describe Notifications::CreateFromModelService, 'message', with_settings: { jour
context 'with the user not having registered for watcher notifications and watching the root' 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)
+ FactoryBot.build(:notification_setting, **notification_settings_all_false)
]
end
diff --git a/spec/services/notifications/create_from_model_service_news_spec.rb b/spec/services/notifications/create_from_model_service_news_spec.rb
index 57b9bed8b01..2321d2a0517 100644
--- a/spec/services/notifications/create_from_model_service_news_spec.rb
+++ b/spec/services/notifications/create_from_model_service_news_spec.rb
@@ -70,9 +70,7 @@ describe Notifications::CreateFromModelService, 'news', with_settings: { journal
context 'with the user having registered for involved notifications' do
let(:recipient_notification_settings) do
[
- FactoryBot.build(:mail_notification_setting, **notification_settings_all_false.merge(involved: true)),
- FactoryBot.build(:in_app_notification_setting, **notification_settings_all_false.merge(involved: true)),
- FactoryBot.build(:mail_digest_notification_setting, **notification_settings_all_false.merge(involved: true))
+ FactoryBot.build(:notification_setting, **notification_settings_all_false.merge(involved: true))
]
end
@@ -82,9 +80,7 @@ describe Notifications::CreateFromModelService, 'news', with_settings: { journal
context 'with the user having registered for no notifications' 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)
+ FactoryBot.build(:notification_setting, **notification_settings_all_false)
]
end