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

Allow setting only one date, assumed to be first=last date

Oliver Günther42b314bb970d
diff --git a/lib/api/v3/user_preferences/user_preference_representer.rb b/lib/api/v3/user_preferences/user_preference_representer.rb
index 5c968f03825..ba9d5305d9b 100644
--- a/lib/api/v3/user_preferences/user_preference_representer.rb
+++ b/lib/api/v3/user_preferences/user_preference_representer.rb
@@ -86,6 +86,10 @@ module API
end,
setter: ->(fragment:, **) do
self.pause_reminders = fragment.transform_keys(&:underscore)
+
+ if pause_reminders['last_day'].blank? && pause_reminders['first_day']
+ pause_reminders['last_day'] = pause_reminders['first_day']
+ end
end
property :workdays
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 62723c2164f..6c26e7d746f 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
@@ -96,4 +96,58 @@ describe ::API::V3::UserPreferences::UserPreferenceRepresenter,
})
end
end
+
+ describe 'pause_reminders' do
+ let(:request_body) do
+ {
+ "pauseReminders" => {
+ "enabled" => true,
+ "firstDay" => first_day,
+ "lastDay" => last_day
+ }
+ }
+ end
+
+ context 'with all set' do
+ let(:first_day) { '2021-10-10' }
+ let(:last_day) { '2021-10-20' }
+
+ it 'sets both dates' do
+ expect(parsed.pause_reminders)
+ .to eql({
+ "enabled" => true,
+ "first_day" => first_day,
+ "last_day" => last_day
+ })
+ end
+ end
+
+ context 'with first only set' do
+ let(:first_day) { '2021-10-10' }
+ let(:last_day) { nil }
+
+ it 'uses the first day for the last day' do
+ expect(parsed.pause_reminders)
+ .to eql({
+ "enabled" => true,
+ "first_day" => first_day,
+ "last_day" => first_day
+ })
+ end
+ end
+
+ context 'with last only set' do
+ let(:first_day) { nil }
+ let(:last_day) { '2021-10-10' }
+
+ it 'uses the first day for the last day' do
+ expect(parsed.pause_reminders)
+ .to eql({
+ "enabled" => true,
+ "first_day" => nil,
+ "last_day" => last_day
+ })
+ end
+ end
+ end
end