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
make nested hash env names work with env_alias for Setting
Christophe Bliard73a8421c42e2
diff --git a/app/helpers/user_consent_helper.rb b/app/helpers/user_consent_helper.rbindex f529eebc882..dd9ec1ef4e4 100644--- a/app/helpers/user_consent_helper.rb+++ b/app/helpers/user_consent_helper.rb@@ -47,7 +47,7 @@ module ::UserConsentHelperdef user_consent_instructions(_user, locale: I18n.locale)all = Setting.consent_info- all.fetch(locale) { all.values.first }+ all.fetch(locale.to_s) { all.values.first }enddef consent_checkbox_label(locale: I18n.locale)diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rbindex 505350dd25f..b21da1d496f 100644--- a/config/constants/settings/definition.rb+++ b/config/constants/settings/definition.rb@@ -317,7 +317,12 @@ module Settingsenddef each_env_var_hash_override(definition)- hash_override_matcher = /^(?:#{env_name(definition)}|#{env_name_legacy(definition)})_(.+)/i+ hash_override_matcher =+ if definition.env_alias+ /^(?:#{env_name(definition)}|#{env_name_legacy(definition)}|#{env_name_alias(definition)})_(.+)/i+ else+ /^(?:#{env_name(definition)}|#{env_name_legacy(definition)})_(.+)/i+ endENV.each do |env_var_name, env_var_value|env_var_name.match(hash_override_matcher) do |m|yield env_var_name, env_var_value, m[1]diff --git a/modules/recaptcha/app/controllers/recaptcha/request_controller.rb b/modules/recaptcha/app/controllers/recaptcha/request_controller.rbindex db5628a7fe2..4cc878e7a79 100644--- a/modules/recaptcha/app/controllers/recaptcha/request_controller.rb+++ b/modules/recaptcha/app/controllers/recaptcha/request_controller.rb@@ -28,7 +28,7 @@ module ::Recaptchadef verifyif valid_recaptcha?- save_recpatcha_verification_success!+ save_recaptcha_verification_success!complete_stage_redirectelsefail_recaptcha I18n.t('recaptcha.error_captcha')@@ -39,7 +39,7 @@ module ::Recaptcha### Insert that the account was verified- def save_recpatcha_verification_success!+ def save_recaptcha_verification_success!# Remove all previous::Recaptcha::Entry.where(user_id: @authenticated_user.id).delete_all::Recaptcha::Entry.create!(user_id: @authenticated_user.id, version: recaptcha_version)diff --git a/modules/recaptcha/spec/controllers/request_controller_spec.rb b/modules/recaptcha/spec/controllers/request_controller_spec.rbindex c6de6e3ff3a..bb403328418 100644--- a/modules/recaptcha/spec/controllers/request_controller_spec.rb+++ b/modules/recaptcha/spec/controllers/request_controller_spec.rb@@ -2,11 +2,21 @@ require 'spec_helper'describe ::Recaptcha::RequestController, type: :controller dolet(:user) { create :user }++ include_context 'with settings' do+ let(:settings) do+ {+ plugin_openproject_recaptcha: {+ 'recaptcha_type' => 'v2',+ 'website_key' => 'A',+ 'secret_key' => 'B'+ }+ }+ end+ end+before dologin_as user- allow(Setting)- .to receive(:plugin_openproject_recaptcha)- .and_return(recaptcha_type: 'v2', website_key: 'A', secret_key: 'B')session[:authenticated_user_id] = user.idsession[:stage_secrets] = { recaptcha: 'asdf' }@@ -21,7 +31,7 @@ describe ::Recaptcha::RequestController, type: :controller doit 'skips if user is verified' doallow(::Recaptcha::Entry)- .to receive_message_chain(:where, :exists?)+ .to receive(:exists?).with(user_id: user.id).and_return trueget :perform@@ -32,25 +42,27 @@ describe ::Recaptcha::RequestController, type: :controller dolet(:user) { create :admin }it 'skips the verification' do- expect(controller).not_to receive(:perform)+ allow(controller).to receive(:perform)get :performexpect(response).to redirect_to stage_success_path(stage: :recaptcha, secret: 'asdf')+ expect(controller).not_to have_received(:perform)endendenddescribe 'verify' doit 'succeeds assuming verification works' do- allow(@controller).to receive(:valid_recaptcha?).and_return true- expect(@controller).to receive(:save_recpatcha_verification_success!)+ allow(controller).to receive(:valid_recaptcha?).and_return true+ allow(controller).to receive(:save_recaptcha_verification_success!)post :verifyexpect(flash[:error]).to be_nilexpect(response).to redirect_to stage_success_path(stage: :recaptcha, secret: 'asdf')+ expect(controller).to have_received(:save_recaptcha_verification_success!)endit 'fails assuming verification fails' do- allow(@controller).to receive(:valid_recaptcha?).and_return false+ allow(controller).to receive(:valid_recaptcha?).and_return falsepost :verifyexpect(flash[:error]).to be_presentexpect(response).to redirect_to stage_failure_path(stage: :recaptcha)diff --git a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy_manager.rb b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy_manager.rbindex 461406cf6d5..e910bd9067b 100644--- a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy_manager.rb+++ b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy_manager.rb@@ -93,7 +93,7 @@ module OpenProject::TwoFactorAuthenticationtypes << s.device_typeend- classes = types.to_h { |type| [type, ::TwoFactorAuthentication::Device.const_get(type.to_s.camelize)] }+ types.index_with { |type| ::TwoFactorAuthentication::Device.const_get(type.to_s.camelize) }end##diff --git a/modules/two_factor_authentication/spec/models/devices/totp_spec.rb b/modules/two_factor_authentication/spec/models/devices/totp_spec.rbindex 89edc5f2605..7caa0e9e44d 100644--- a/modules/two_factor_authentication/spec/models/devices/totp_spec.rb+++ b/modules/two_factor_authentication/spec/models/devices/totp_spec.rb@@ -83,7 +83,7 @@ describe ::TwoFactorAuthentication::Device::Totp, with_2fa_ee: true, type: :modeexpect(subject.verify_token(valid)).to be false- future = Time.current + 1.minute+ future = 1.minute.from_nowTimecop.freeze(future) dovalid = totp.nowexpect(subject.verify_token(valid)).to be truediff --git a/modules/two_factor_authentication/spec/services/token_delivery/totp_spec.rb b/modules/two_factor_authentication/spec/services/token_delivery/totp_spec.rbindex 3763db73db2..196af3ab178 100644--- a/modules/two_factor_authentication/spec/services/token_delivery/totp_spec.rb+++ b/modules/two_factor_authentication/spec/services/token_delivery/totp_spec.rb@@ -5,17 +5,12 @@ describe ::OpenProject::TwoFactorAuthentication::TokenStrategy::Totp, with_2fa_elet!(:user) { create :user }let!(:device) { create :two_factor_authentication_device_totp, user: user, default: true }- before do- allow(OpenProject::Configuration)- .to receive(:[]).with('2fa')- .and_return(active_strategies: [:totp])- end-describe '#verify' dosubject { ::TwoFactorAuthentication::TokenService.new user: user }+let(:result) { subject.verify token }- context '#valid current token' do+ context 'with valid current token' dolet(:token) { device.totp.now }it 'is validated' do@@ -30,7 +25,7 @@ describe ::OpenProject::TwoFactorAuthentication::TokenStrategy::Totp, with_2fa_eendend- context 'invalid token' do+ context 'with invalid token' dolet(:token) { 'definitely invalid' }it 'is not validated' do@@ -39,7 +34,7 @@ describe ::OpenProject::TwoFactorAuthentication::TokenStrategy::Totp, with_2fa_eendend- context 'assuming internal error' do+ context 'with internal error' dolet(:token) { 1234 }before dodiff --git a/spec/constants/settings/definition_spec.rb b/spec/constants/settings/definition_spec.rbindex 638a3419f95..a1251e044f0 100644--- a/spec/constants/settings/definition_spec.rb+++ b/spec/constants/settings/definition_spec.rb@@ -322,29 +322,30 @@ describe Settings::Definition dodescribed_class.all << definition_2faend- # it 'allows overriding settings from ENV with aliased env name' do- # require Rails.root.join('modules/two_factor_authentication/lib/open_project/two_factor_authentication/engine')- # stub_const(- # 'ENV',- # {- # 'OPENPROJECT_2FA' => '{"enforced": true, "allow_remember_for_days": 15}'- # }- # )-- # expect(value_for('plugin_openproject_two_factor_authentication'))- # .to eq(active_strategies: [], enforced: true, allow_remember_for_days: 15)- # end-it 'allows overriding settings hash partially from ENV with aliased env name' do+ stub_const(+ 'ENV',+ {+ 'OPENPROJECT_2FA_ENFORCED' => 'true',+ 'OPENPROJECT_2FA_ALLOW__REMEMBER__FOR__DAYS' => '15'+ }+ )++ described_class.send(:override_value, definition_2fa) # override from env manually after changing ENV+ expect(value_for('plugin_openproject_two_factor_authentication'))+ .to eq('active_strategies' => [:totp], 'enforced' => true, 'allow_remember_for_days' => 15)+ end++ it 'allows overriding settings hash from ENV with aliased env name' dostub_const('ENV',{'OPENPROJECT_2FA' => '{"enforced": true, "allow_remember_for_days": 15}'})- Settings::Definition.send(:override_value, definition_2fa) # override from env manually after changing ENV+ described_class.send(:override_value, definition_2fa) # override from env manually after changing ENVexpect(value_for('plugin_openproject_two_factor_authentication'))- .to eq({ 'active_strategies' => [], 'enforced' => true, 'allow_remember_for_days' => 15 })+ .to eq({ 'active_strategies' => [:totp], 'enforced' => true, 'allow_remember_for_days' => 15 })endenddiff --git a/spec/support/shared/with_settings.rb b/spec/support/shared/with_settings.rbindex 9b131391d82..6206cd03bb3 100644--- a/spec/support/shared/with_settings.rb+++ b/spec/support/shared/with_settings.rb@@ -67,7 +67,7 @@ module WithSettingsMixinraise "#{k} is not a valid setting" unless Setting.respond_to?(name)expect(name).not_to start_with("localized_"), -> do- base = name[10..-1]+ base = name[10..]"Don't use `#{name}` in `with_settings`. Do this: `with_settings: { #{base}: { \"en\" => \"#{v}\" } }`"enddiff --git a/spec/views/account/register.html.erb_spec.rb b/spec/views/account/register.html.erb_spec.rbindex 7469e03e530..dbe3f6fbb8e 100644--- a/spec/views/account/register.html.erb_spec.rb+++ b/spec/views/account/register.html.erb_spec.rb@@ -43,13 +43,13 @@ describe 'account/register', type: :view dolet(:auth_source) { create :auth_source }let(:user) { build :user, auth_source: auth_source }- it 'should not show a login field' do+ it 'does not show a login field' doexpect(rendered).not_to include('user[login]')endendcontext 'without auth source' do- it 'should show a login field' do+ it 'shows a login field' doexpect(rendered).to include('user[login]')endend@@ -67,21 +67,21 @@ describe 'account/register', type: :view dolet(:auth_source) { create :auth_source }let(:user) { build :user, auth_source: auth_source }- it 'should not show a login field' do+ it 'does not show a login field' doexpect(rendered).not_to include('user[login]')end- it 'should show an email field' do+ it 'shows an email field' doexpect(rendered).to include('user[mail]')endendcontext 'without auth source' do- it 'should not show a login field' do+ it 'does not show a login field' doexpect(rendered).not_to include('user[login]')end- it 'should show an email field' do+ it 'shows an email field' doexpect(rendered).to include('user[mail]')endend@@ -96,7 +96,7 @@ describe 'account/register', type: :view doassign(:user, user)end- it 'should render the registration footer from the settings' do+ it 'renders the registration footer from the settings' dorenderexpect(rendered).to include(footer)@@ -106,8 +106,8 @@ describe 'account/register', type: :view docontext "with consent required", with_settings: {consent_required: true,consent_info: {- en: "You must consent!",- de: "Du musst zustimmen!"+ 'en' => "You must consent!",+ 'de' => "Du musst zustimmen!"}} dolet(:locale) { raise "you have to define the locale" }diff --git a/spec_legacy/support/legacy_assertions.rb b/spec_legacy/support/legacy_assertions.rbindex 312b702a038..311afe5a340 100644--- a/spec_legacy/support/legacy_assertions.rb+++ b/spec_legacy/support/legacy_assertions.rb@@ -82,7 +82,7 @@ module LegacyAssertionsAndHelpersfileend- def with_settings(options, &_block)+ def with_legacy_settings(options, &_block)saved_settings = options.keys.inject({}) { |h, k| h[k] = Setting[k].dup; h }options.each { |k, v| Setting[k] = v }yielddiff --git a/spec_legacy/unit/mail_handler_spec.rb b/spec_legacy/unit/mail_handler_spec.rbindex 980d2bfca31..a445b5cff38 100644--- a/spec_legacy/unit/mail_handler_spec.rb+++ b/spec_legacy/unit/mail_handler_spec.rb@@ -175,7 +175,7 @@ describe MailHandler, type: :model doassert_equal false, submit_email('ticket_without_from_header.eml')end- context 'without default start_date', with_settings: { work_package_startdate_is_adddate: false } do+ context 'without default start_date', with_legacy_settings: { work_package_startdate_is_adddate: false } doit 'should add work package with invalid attributes' doissue = submit_email('ticket_with_invalid_attributes.eml', allow_override: 'type,category,priority')assert issue.is_a?(WorkPackage)@@ -309,7 +309,7 @@ describe MailHandler, type: :model doendcontext 'with min password length',- with_settings: { password_min_length: 15 } do+ with_legacy_settings: { password_min_length: 15 } doit 'should new user from attributes should respect minimum password length' douser = MailHandler.new_user_from_attributes('[email protected]')assert user.valid?diff --git a/spec_legacy/unit/project_spec.rb b/spec_legacy/unit/project_spec.rbindex e42b0a3e5cf..73d090770a8 100644--- a/spec_legacy/unit/project_spec.rb+++ b/spec_legacy/unit/project_spec.rb@@ -140,7 +140,7 @@ describe Project, type: :model doendcontext 'with modules',- with_settings: { default_projects_modules: ['work_package_tracking', 'repository'] } do+ with_legacy_settings: { default_projects_modules: ['work_package_tracking', 'repository'] } doit 'should enabled module names' doproject = Project.new