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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
user_default_timezone setting is first fallback for reminder mail
ulfertsa33fcbac9448
diff --git a/app/models/users/scopes/having_reminder_mail_to_send.rb b/app/models/users/scopes/having_reminder_mail_to_send.rbindex 3bfa2f349b3..b57bbc4ec74 100644--- a/app/models/users/scopes/having_reminder_mail_to_send.rb+++ b/app/models/users/scopes/having_reminder_mail_to_send.rb@@ -75,9 +75,12 @@ module Users::Scopestimes_sql = arel_table.grouping(Arel::Nodes::ValuesList.new(local_times)).as('t(time, zone, workday)')++ default_timezone = Setting.user_default_timezone.present? ? "'#{Setting.user_default_timezone}'" : 'NULL'+<<~SQL.squishJOIN (SELECT * FROM #{times_sql.to_sql}) AS local_times- ON COALESCE(user_preferences.settings->>'time_zone', 'Etc/UTC') = local_times.zone+ ON COALESCE(user_preferences.settings->>'time_zone', #{default_timezone}, 'Etc/UTC') = local_times.zoneAND (user_preferences.settings->'workdays' @> to_jsonb(local_times.workday)OR (diff --git a/db/migrate/20211005080304_tzinfo_time_zones.rb b/db/migrate/20211005080304_tzinfo_time_zones.rbindex d3ed20f0f0e..b0e3b46d089 100644--- a/db/migrate/20211005080304_tzinfo_time_zones.rb+++ b/db/migrate/20211005080304_tzinfo_time_zones.rb@@ -41,7 +41,8 @@ class TzinfoTimeZones < ActiveRecord::Migration[6.1]end.flatten(1)- migrate_time_zone(zone_mappings)+ migrate_user_time_zone(zone_mappings)+ migrate_default_time_zone(zone_mappings)enddef down@@ -51,18 +52,19 @@ class TzinfoTimeZones < ActiveRecord::Migration[6.1][tz.tzinfo.canonical_zone.name, tz.name]end- migrate_time_zone(zone_mappings)+ migrate_user_time_zone(zone_mappings)+ migrate_default_time_zone(zone_mappings)endprotected- def migrate_time_zone(mappings)+ def migrate_user_time_zone(mappings)execute <<~SQL.squishWITH source AS (SELECT id, settings || jsonb_build_object('time_zone', to_zone) settings- FROM user_preferences- LEFT JOIN (SELECT * FROM (#{Arel::Nodes::ValuesList.new(mappings).to_sql}) as t(from_zone, to_zone)) zones- ON zones.from_zone = user_preferences.settings->>'time_zone'+ FROM user_preferences+ LEFT JOIN (SELECT * FROM (#{Arel::Nodes::ValuesList.new(mappings).to_sql}) as t(from_zone, to_zone)) zones+ ON zones.from_zone = user_preferences.settings->>'time_zone')UPDATE user_preferences sink@@ -72,4 +74,18 @@ class TzinfoTimeZones < ActiveRecord::Migration[6.1]AND sink.settings->'time_zone' IS NOT NULLSQLend++ def migrate_default_time_zone(mappings)+ execute <<~SQL.squish+ WITH zones AS (+ SELECT * FROM (#{Arel::Nodes::ValuesList.new(mappings).to_sql}) as t(from_zone, to_zone)+ )++ UPDATE settings+ SET value = zones.to_zone+ FROM zones+ WHERE settings.name = 'user_default_timezone'+ AND settings.value = zones.from_zone+ SQL+ endenddiff --git a/spec/models/users/default_timezone_spec.rb b/spec/models/users/default_timezone_spec.rbindex a2b9eeaf078..ddeb2997eb2 100644--- a/spec/models/users/default_timezone_spec.rb+++ b/spec/models/users/default_timezone_spec.rb@@ -37,9 +37,9 @@ describe User, "default time zone" doendend- context "with a system default set", with_settings: { user_default_timezone: "Edinburgh" } do+ context "with a system default set", with_settings: { user_default_timezone: "Europe/London" } doit "is set to the default" do- expect(user.pref.time_zone).to eq "Edinburgh"+ expect(user.pref.time_zone).to eq "Europe/London"endendenddiff --git a/spec/models/users/scopes/having_reminder_mail_to_send_spec.rb b/spec/models/users/scopes/having_reminder_mail_to_send_spec.rbindex f9227026920..d5aafc6a2f4 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@@ -521,6 +521,31 @@ describe User, '.having_reminder_mail_to_send', type: :model doendend+ context 'for a user without a time zone and a default time zone configured',+ with_settings: { user_default_timezone: 'Europe/Moscow' } do+ let(:moscow_user) do+ FactoryBot.create(+ :user,+ firstname: 'Europe/Moscow',+ preferences: {+ daily_reminders: {+ enabled: true,+ times: [hitting_reminder_slot_for("Europe/Moscow", current_time)]+ }+ }+ )+ end+ let(:notifications) do+ FactoryBot.create(:notification, recipient: moscow_user, created_at: 5.minutes.ago)+ end+ let(:users) { [moscow_user] }++ it 'is including the configured default timezone is assumed' do+ expect(scope)+ .to match_array([moscow_user])+ end+ end+context 'when the provided scope_time is after the current time' dolet(:scope_time) { Time.current + 1.minute }