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
Revert timezone setting back to string, validate using canonical (#11607)
Oliver Günther49b1cd32e5cd
diff --git a/app/models/setting.rb b/app/models/setting.rbindex 6cd59e0ac10..ab6b64a12d0 100644--- a/app/models/setting.rb+++ b/app/models/setting.rb@@ -356,8 +356,6 @@ class Setting < ApplicationRecordDate.parse valuewhen :datetimeDateTime.parse value- when :timezone- ActiveSupport::TimeZone.lookup_timezone(value) || valueelsevalueenddiff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rbindex d34ba4df7f5..e0bb19bfe9f 100644--- a/config/constants/settings/definition.rb+++ b/config/constants/settings/definition.rb@@ -400,8 +400,6 @@ module SettingsAR_BOOLEAN_TYPE.cast(value)when :symbolvalue.to_sym- when :timezone- ActiveSupport::TimeZone.lookup_timezone(value) || valueelsevalueenddiff --git a/config/constants/settings/definitions.rb b/config/constants/settings/definitions.rbindex cd53ac531ed..7d71c4d27f1 100644--- a/config/constants/settings/definitions.rb+++ b/config/constants/settings/definitions.rb@@ -922,8 +922,8 @@ Settings::Definition.define doadd :user_default_timezone,default: nil,- format: :timezone,- allowed: ActiveSupport::TimeZone.all + [nil]+ format: :string,+ allowed: ActiveSupport::TimeZone.all.map { |tz| tz.tzinfo.canonical_identifier }.sort.uniq + [nil]add :users_deletable_by_admins,default: falsediff --git a/lib/core_extensions.rb b/lib/core_extensions.rbindex c44175d0d69..4da78f71a15 100644--- a/lib/core_extensions.rb+++ b/lib/core_extensions.rb@@ -28,7 +28,6 @@require 'core_extensions/string'require 'core_extensions/time_with_zone'-require 'core_extensions/time_zone'::String.prepend CoreExtensions::String::ActiveSupport::TimeWithZone.include CoreExtensions::TimeWithZonediff --git a/lib/core_extensions/time_zone.rb b/lib/core_extensions/time_zone.rbdeleted file mode 100644index 673d9363236..00000000000--- a/lib/core_extensions/time_zone.rb+++ /dev/null@@ -1,37 +0,0 @@-#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2022 the OpenProject GmbH-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License version 3.-#-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:-# Copyright (C) 2006-2013 Jean-Philippe Lang-# Copyright (C) 2010-2013 the ChiliProject Team-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License-# as published by the Free Software Foundation; either version 2-# of the License, or (at your option) any later version.-#-# This program is distributed in the hope that it will be useful,-# but WITHOUT ANY WARRANTY; without even the implied warranty of-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-# GNU General Public License for more details.-#-# You should have received a copy of the GNU General Public License-# along with this program; if not, write to the Free Software-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.-#-# See COPYRIGHT and LICENSE files for more details.-#++--module CoreExtensions- module TimeZone # :nodoc:- def lookup_timezone(value)- all.detect { |tz| tz.name == value || tz.to_s == value || tz.tzinfo.canonical_identifier == value }- end- end-end--::ActiveSupport::TimeZone.extend ::CoreExtensions::TimeZonediff --git a/spec/constants/settings/definition_spec.rb b/spec/constants/settings/definition_spec.rbindex 55bda139ad8..0c93aa4208e 100644--- a/spec/constants/settings/definition_spec.rb+++ b/spec/constants/settings/definition_spec.rb@@ -166,9 +166,13 @@ describe Settings::Definition doit 'overriding timezone configuration from ENV will cast the value' dostub_const('ENV', { 'OPENPROJECT_USER__DEFAULT__TIMEZONE' => 'Europe/Berlin' })- value = all.detect { |d| d.name == 'user_default_timezone' }.value- expect(value).to be_a ::ActiveSupport::TimeZone- expect(value.name).to eq 'Berlin'+ expect(value_for('user_default_timezone')).to eq 'Europe/Berlin'+ end++ it 'overriding timezone configuration from ENV with a bogus value' do+ stub_const('ENV', { 'OPENPROJECT_USER__DEFAULT__TIMEZONE' => 'foobar' })++ expect { value_for('user_default_timezone') }.to raise_error(ArgumentError)endit 'overriding configuration from ENV will set it to non writable' do@@ -983,30 +987,6 @@ describe Settings::Definition do.to be falseendend-- context 'with a timezone' do- let(:instance) do- described_class.new 'timezone',- format: :timezone,- default: nil,- allowed: ActiveSupport::TimeZone.all + [nil]- end-- it 'accepts a TZ name' do- instance.value = 'Europe/Berlin'- expect(instance).to be_valid- end-- it 'accepts a TZ full identifier' do- instance.value = '(GMT+01:00) Berlin'- expect(instance).to be_valid- end-- it 'rejects a bogus value' do- instance.value = 'foobar'- expect(instance).not_to be_valid- end- endenddescribe '#on_change' dodiff --git a/spec/features/users/my_spec.rb b/spec/features/users/my_spec.rbindex b4f1bbedd43..7139e0952c2 100644--- a/spec/features/users/my_spec.rb+++ b/spec/features/users/my_spec.rb@@ -111,6 +111,22 @@ describe 'my',endend+ describe 'settings' do+ context 'with a default time zone', with_settings: { user_default_timezone: 'Asia/Tokyo' } do+ it 'can override a time zone' do+ expect(user.pref.time_zone).to eq 'Asia/Tokyo'+ visit my_settings_path++ expect(page).to have_select 'pref_time_zone', selected: '(GMT+09:00) Tokyo'+ select '(GMT+01:00) Paris', from: 'pref_time_zone'+ click_on 'Save'++ expect(page).to have_select 'pref_time_zone', selected: '(GMT+01:00) Paris'+ expect(user.pref.time_zone).to eq 'Europe/Paris'+ end+ end+ end+it 'in Access Tokens they can generate their API key' dovisit my_access_token_pathexpect(page).to have_content 'Missing API access key'