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

resilient notification selection upon empty time zone setting

ulferts9252beb770e7
diff --git a/app/models/users/scopes/having_reminder_mail_to_send.rb b/app/models/users/scopes/having_reminder_mail_to_send.rb
index 0a2e5428ad3..f4c36864803 100644
--- a/app/models/users/scopes/having_reminder_mail_to_send.rb
+++ b/app/models/users/scopes/having_reminder_mail_to_send.rb
@@ -69,9 +69,9 @@ module Users::Scopes
# * reminders are enabled
# * any of the configured reminder time is the local time
# * the local workday is enabled to receive a reminder on
- # If no time zone is present, utc is assumed.
+ # If no time zone is present or if it is blank, the configured default time zone or UTC is assumed.
# If no reminder settings are present, sending a reminder at 08:00 local time is assumed.
- # If no workdays are specified, 1 - 5 is assumed which is represents Monday to Friday.
+ # If no workdays are specified, 1 - 5 is assumed which represents Monday to Friday.
times_sql = arel_table
.grouping(Arel::Nodes::ValuesList.new(local_times))
.as('t(today_local, hours, zone, workday)')
@@ -80,7 +80,7 @@ module Users::Scopes
<<~SQL.squish
JOIN (SELECT * FROM #{times_sql.to_sql}) AS local_times
- ON COALESCE(user_preferences.settings->>'time_zone', #{default_timezone}, 'Etc/UTC') = local_times.zone
+ ON COALESCE(NULLIF(user_preferences.settings->>'time_zone',''), #{default_timezone}, 'Etc/UTC') = local_times.zone
AND (
user_preferences.settings->'workdays' @> to_jsonb(local_times.workday)
OR (
diff --git a/spec/models/users/scopes/having_reminder_mail_to_send_spec.rb b/spec/models/users/scopes/having_reminder_mail_to_send_spec.rb
index 32080623616..d2638ecf050 100644
--- a/spec/models/users/scopes/having_reminder_mail_to_send_spec.rb
+++ b/spec/models/users/scopes/having_reminder_mail_to_send_spec.rb
@@ -575,6 +575,27 @@ describe User, '.having_reminder_mail_to_send', type: :model do
end
end
+ context 'for a user without a blank time zone' do
+ let(:paris_user) do
+ FactoryBot.create(
+ :user,
+ firstname: 'Europe/Paris',
+ preferences: {
+ time_zone: '',
+ daily_reminders: {
+ enabled: true,
+ times: [hitting_reminder_slot_for("Etc/UTC", current_time)]
+ }
+ }
+ )
+ end
+
+ it 'is including the user as Etc/UTC is assumed' do
+ expect(scope)
+ .to match_array([paris_user])
+ end
+ end
+
context 'for a user without a time zone and daily_reminders at 08:00' do
let(:paris_user) do
FactoryBot.create(