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

[#43673] fixes after comments

Dmitrii00a0d42ed10d
diff --git a/app/contracts/user_preferences/params_contract.rb b/app/contracts/user_preferences/params_contract.rb
index 1dfaf438b3c..018d3b0b549 100644
--- a/app/contracts/user_preferences/params_contract.rb
+++ b/app/contracts/user_preferences/params_contract.rb
@@ -28,15 +28,16 @@
module UserPreferences
class ParamsContract < ::ParamsContract
- AVAILABLE_DATE = [nil, 12, 24, 78, 168].freeze
+ AVAILABLE_DATE = [nil, 0, 24, 72, 168].freeze
+ AVAILABLE_OVERDUE_DATE = [nil, 0, 72, 168].freeze
validate :only_one_global_setting,
if: -> { notifications.present? }
validate :global_email_alerts,
if: -> { notifications.present? }
- validate :global_setting_start_date_due_date_overdue,
+ validate :global_date_alerts,
if: -> { notifications.present? }
- validate :project_notifications_start_date_due_date_overdue,
+ validate :project_date_alerts,
if: -> { notifications.present? }
protected
@@ -53,31 +54,23 @@ module UserPreferences
end
end
- def global_setting_start_date_due_date_overdue
- return unless stores_all_date_fields?(global_notifications)
-
+ def global_date_alerts
if any_of_date_fields_fail_validation?(global_notifications)
errors.add :notification_settings, :wrong_date
end
end
- def project_notifications_start_date_due_date_overdue
- return unless stores_all_date_fields?(project_notifications)
-
+ def project_date_alerts
if any_of_date_fields_fail_validation?(project_notifications)
errors.add :notification_settings, :wrong_date
end
end
- def stores_all_date_fields?(notifications_type)
- notifications_type.all? { |setting| setting.key?(:start_date) && setting.key?(:due_date) && setting.key?(:overdue) }
- end
-
def any_of_date_fields_fail_validation?(notifications_type)
notifications_type.any? do |setting|
- setting.slice(:start_date, :due_date, :overdue).detect do |_, date|
+ setting.slice(:start_date, :due_date).detect do |_, date|
AVAILABLE_DATE.exclude?(date)
- end
+ end || AVAILABLE_OVERDUE_DATE.exclude?(setting[:overdue])
end
end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index bb315092aaa..e42fa55671d 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -746,6 +746,7 @@ en:
only_one_global_setting: 'There must only be one global notification setting.'
email_alerts_global: 'The email notification settings can only be set globally.'
format: "%{message}"
+ wrong_date: 'Wrong value for Start date, Due date, or Overdue.'
parse_schema_filter_params_service:
attributes:
base:
diff --git a/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.ts b/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.ts
index 480e581ae47..9a79f81da75 100644
--- a/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.ts
+++ b/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.ts
@@ -170,6 +170,9 @@ export class NotificationsSettingsPageComponent extends UntilDestroyedMixin impl
workPackageScheduled: notificationSettings.workPackageScheduled,
workPackagePrioritized: notificationSettings.workPackagePrioritized,
workPackageCommented: notificationSettings.workPackageCommented,
+ startDate: 24,
+ dueDate: 24,
+ overdue: null,
};
const projectPrefs:INotificationSetting[] = notificationSettings.projectSettings.map((settings) => ({
@@ -191,6 +194,9 @@ export class NotificationsSettingsPageComponent extends UntilDestroyedMixin impl
wikiPageUpdated: false,
membershipAdded: false,
membershipUpdated: false,
+ startDate: 24,
+ dueDate: 24,
+ overdue: null,
}));
this.storeService.update(this.userId, {
diff --git a/frontend/src/app/features/user-preferences/state/notification-setting.model.ts b/frontend/src/app/features/user-preferences/state/notification-setting.model.ts
index 05f521205ad..3fad0c5ea2f 100644
--- a/frontend/src/app/features/user-preferences/state/notification-setting.model.ts
+++ b/frontend/src/app/features/user-preferences/state/notification-setting.model.ts
@@ -19,6 +19,9 @@ export interface INotificationSetting {
wikiPageUpdated:boolean;
membershipAdded:boolean;
membershipUpdated:boolean;
+ startDate:number|null;
+ dueDate:number|null;
+ overdue:number|null;
}
export function buildNotificationSetting(project:null|HalSourceLink, params:Partial<INotificationSetting>):INotificationSetting {
@@ -46,6 +49,9 @@ export function buildNotificationSetting(project:null|HalSourceLink, params:Part
wikiPageUpdated: true,
membershipAdded: true,
membershipUpdated: true,
+ startDate: 24,
+ dueDate: 24,
+ overdue: null,
...params,
};
}
diff --git a/spec/contracts/user_preferences/params_contract_spec.rb b/spec/contracts/user_preferences/params_contract_spec.rb
index ddccbed4b1a..7b42809a3b4 100644
--- a/spec/contracts/user_preferences/params_contract_spec.rb
+++ b/spec/contracts/user_preferences/params_contract_spec.rb
@@ -89,14 +89,24 @@ describe UserPreferences::ParamsContract do
context 'when project setting with start_date, due_date and overdue set' do
let(:notification_settings) do
[
- { start_date: 24, due_date: 24, overdue: 24 }
+ { start_date: 24, due_date: 24, overdue: 0 }
]
end
it_behaves_like 'contract is valid'
end
- context 'when project setting with start_date, due_date and overdue is invalid' do
+ context 'when global setting with start_date, due_date and overdue set' do
+ let(:notification_settings) do
+ [
+ { project_id: 1234, start_date: 24, due_date: 24, overdue: 0 }
+ ]
+ end
+
+ it_behaves_like 'contract is valid'
+ end
+
+ context 'when project setting with due_date and start_date with overdue are invalid' do
let(:notification_settings) do
[
{ start_date: 22, due_date: 24, overdue: 24 }
@@ -106,6 +116,56 @@ describe UserPreferences::ParamsContract do
it_behaves_like 'contract is invalid', notification_settings: :wrong_date
end
+ context 'when global setting with due_date and start_date with overdue are invalid' do
+ let(:notification_settings) do
+ [
+ { project_id: 1234, start_date: 22, due_date: 24, overdue: 24 }
+ ]
+ end
+
+ it_behaves_like 'contract is invalid', notification_settings: :wrong_date
+ end
+
+ context 'when project setting with start_date, due_date and overdue missing' do
+ let(:notification_settings) do
+ [
+ { start_date: 24, due_date: 24 }
+ ]
+ end
+
+ it_behaves_like 'contract is valid'
+ end
+
+ context 'when global setting with start_date, due_date and overdue missing' do
+ let(:notification_settings) do
+ [
+ { project_id: 1234, start_date: 24, due_date: 24 }
+ ]
+ end
+
+ it_behaves_like 'contract is valid'
+ end
+
+ context 'when project setting with start_date, due_date invalid and overdue missing' do
+ let(:notification_settings) do
+ [
+ { start_date: 24, due_date: 22 }
+ ]
+ end
+
+ it_behaves_like 'contract is invalid', notification_settings: :wrong_date
+ end
+
+ context 'when global setting with start_date, due_date invalid and overdue missing' do
+ let(:notification_settings) do
+ [
+ { project_id: 1234, start_date: 24, due_date: 22 }
+ ]
+ end
+
+ it_behaves_like 'contract is invalid', notification_settings: :wrong_date
+ end
+
context 'when notification_settings empty' do
let(:params) do
{
diff --git a/spec/factories/user_factory.rb b/spec/factories/user_factory.rb
index 29d279f3fd1..7a34d65b098 100644
--- a/spec/factories/user_factory.rb
+++ b/spec/factories/user_factory.rb
@@ -58,10 +58,11 @@ FactoryBot.define do
user.pref.save if factory.preferences.present?
if user.notification_settings.empty?
- date_settings = [NotificationSetting::START_DATE, NotificationSetting::DUE_DATE, NotificationSetting::OVERDUE]
+ date_settings = [NotificationSetting::START_DATE, NotificationSetting::DUE_DATE,
+ NotificationSetting::OVERDUE].index_with(0)
all_true = NotificationSetting.all_settings.reject { |setting| date_settings.include?(setting) }.index_with(true)
user.notification_settings = [
- create(:notification_setting, user:, **all_true.merge(date_settings.index_with(24)))
+ create(:notification_setting, user:, **all_true.merge(date_settings))
]
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 64a8cd037bc..876737709e0 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
@@ -34,7 +34,7 @@ describe ::API::V3::UserPreferences::NotificationSettingRepresenter, 'rendering'
subject(:generated) { representer.to_json }
let(:project) { build_stubbed :project }
- let(:notification_setting) { build_stubbed(:notification_setting, overdue: 24, project:) }
+ let(:notification_setting) { build_stubbed(:notification_setting, overdue: 0, project:) }
let(:representer) do
described_class.create notification_setting,
diff --git a/spec/lib/api/v3/user_preferences/user_preference_representer_rendering_spec.rb b/spec/lib/api/v3/user_preferences/user_preference_representer_rendering_spec.rb
index b845cbdddf5..ba80bfdaaae 100644
--- a/spec/lib/api/v3/user_preferences/user_preference_representer_rendering_spec.rb
+++ b/spec/lib/api/v3/user_preferences/user_preference_representer_rendering_spec.rb
@@ -41,7 +41,7 @@ describe ::API::V3::UserPreferences::UserPreferenceRepresenter,
}
})
end
- let(:notification_setting) { build(:notification_setting, overdue: 24) }
+ let(:notification_setting) { build(:notification_setting, overdue: 0) }
let(:user) { build_stubbed(:user, preference:) }
let(:representer) { described_class.new(preference, current_user: user) }