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

[#43676] Move all notification settings defaults to the database layer

Dombi Attila6cfe2463ab3c
diff --git a/app/services/users/set_attributes_service.rb b/app/services/users/set_attributes_service.rb
index 9c2dc80bbae..a1fd00cd42f 100644
--- a/app/services/users/set_attributes_service.rb
+++ b/app/services/users/set_attributes_service.rb
@@ -52,7 +52,7 @@ module Users
assign_invited_attributes!(params)
end
- initialize_notification_settings unless model.notification_settings.any?
+ model.notification_settings.build unless model.notification_settings.any?
end
def set_preferences
@@ -61,10 +61,6 @@ module Users
.call(pref)
end
- def initialize_notification_settings
- model.notification_settings.build(assignee: true, responsible: true, mentioned: true, watched: true)
- end
-
# rubocop:disable Metrics/AbcSize
def assign_invited_attributes!(params)
placeholder = placeholder_name(params[:mail])
diff --git a/db/migrate/20221017184204_change_defaults_for_notification_settings.rb b/db/migrate/20221017184204_change_defaults_for_notification_settings.rb
new file mode 100644
index 00000000000..b93e2e020ac
--- /dev/null
+++ b/db/migrate/20221017184204_change_defaults_for_notification_settings.rb
@@ -0,0 +1,10 @@
+class ChangeDefaultsForNotificationSettings < ActiveRecord::Migration[7.0]
+ def change
+ change_table :notification_settings, bulk: true do |t|
+ t.change_default :assignee, from: false, to: true
+ t.change_default :responsible, from: false, to: true
+ t.change_default :mentioned, from: false, to: true
+ t.change_default :watched, from: false, to: true
+ end
+ end
+end
diff --git a/spec/services/user_preferences/update_service_integration_spec.rb b/spec/services/user_preferences/update_service_integration_spec.rb
index 1cd668ac8d6..51d111a7801 100644
--- a/spec/services/user_preferences/update_service_integration_spec.rb
+++ b/spec/services/user_preferences/update_service_integration_spec.rb
@@ -87,7 +87,7 @@ describe UserPreferences::UpdateService, 'integration', type: :model do
expect(subject.count).to eq 1
expect(subject.first.project_id).to be_nil
- expect(subject.first.mentioned).to be false
+ expect(subject.first.mentioned).to be true
expect(subject.first.watched).to be false
expect(default_ian.assignee).to be true
expect(default_ian.responsible).to be true
@@ -108,7 +108,7 @@ describe UserPreferences::UpdateService, 'integration', type: :model do
let(:attributes) do
{
notification_settings: [
- { project_id: project.id, mentioned: true }
+ { project_id: project.id, mentioned: false }
]
}
end
@@ -120,15 +120,23 @@ describe UserPreferences::UpdateService, 'integration', type: :model do
expect(subject.count).to eq 1
expect(subject.first.project_id).to eq project.id
+ default_settings = {
+ NotificationSetting::START_DATE => 24,
+ NotificationSetting::DUE_DATE => 24,
+ NotificationSetting::OVERDUE => nil,
+ NotificationSetting::ASSIGNEE => true,
+ NotificationSetting::RESPONSIBLE => true,
+ NotificationSetting::WATCHED => true
+ }
+
NotificationSetting.all_settings.each do |key|
val = subject.first.send key
- if [NotificationSetting::START_DATE, NotificationSetting::DUE_DATE].include?(key)
- expect(val).to eq(24)
- elsif key == NotificationSetting::OVERDUE
- expect(val).to be_nil
+ if key.in?(default_settings)
+ expect(val).to eq(default_settings[key])
else
- expect(val).to eq(key == :mentioned)
+ # Settings with default value false
+ expect(val).to be(false)
end
end