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
Allow settings defaults to be lambdas even if format present
Oliver Günther2b05d50b980f
diff --git a/app/helpers/static_links_helper.rb b/app/helpers/static_links_helper.rbindex e0c7bac89df..facf52b9d52 100644--- a/app/helpers/static_links_helper.rb+++ b/app/helpers/static_links_helper.rb@@ -32,7 +32,7 @@ module StaticLinksHelperdef static_link_to(key, label: nil)item = OpenProject::Static::Links.links.fetch key- link_to label || t(item[:label], default: item[:label]),+ link_to label || t(item[:label]),item[:href],class: 'openproject--static-link',target: '_blank', rel: 'noopener'diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rbindex 7775830faec..c3bd545e28f 100644--- a/config/constants/settings/definition.rb+++ b/config/constants/settings/definition.rb@@ -381,6 +381,8 @@ module Settingsdef cast(value)return nil if value.nil?+ value = value.call if value.respond_to?(:call)+case formatwhen :integervalue.to_i@@ -391,11 +393,7 @@ module Settingswhen :symbolvalue.to_symelse- if value.respond_to?(:call)- value.call- else- value- end+ valueendenddiff --git a/config/constants/settings/definitions.rb b/config/constants/settings/definitions.rbindex fab20d6e42d..ca4ee22f88c 100644--- a/config/constants/settings/definitions.rb+++ b/config/constants/settings/definitions.rb@@ -668,14 +668,14 @@ Settings::Definition.define do# Assume we're running in an TLS terminated connection.add :https,format: :boolean,- default: Rails.env.production?,+ default: -> { Rails.env.production? },writable: false# Allow disabling of HSTS headers and http -> https redirects# for non-localhost hostsadd :hsts,format: :boolean,- default: -> { https? },+ default: true,writable: falseadd :registration_footer,diff --git a/config/environments/production.rb b/config/environments/production.rbindex e8313eeea64..390bbf383c2 100644--- a/config/environments/production.rb+++ b/config/environments/production.rb@@ -80,10 +80,10 @@ OpenProject::Application.configure doconfig.ssl_options = {# Disable redirect on the internal SYS APIredirect: {- hsts: OpenProject::Configuration.hsts?,+ hsts: OpenProject::Configuration.hsts_enabled?,exclude: ->(request) do# Disable redirects when hsts is disabled- return true unless OpenProject::Configuration.hsts?+ return true unless OpenProject::Configuration.hsts_enabled?# Respect the relative URLrelative_url = Regexp.escape(OpenProject::Configuration['rails_relative_url_root'])diff --git a/lib_static/open_project/configuration/helpers.rb b/lib_static/open_project/configuration/helpers.rbindex 7a061f7f1ec..d3cfd6344e1 100644--- a/lib_static/open_project/configuration/helpers.rb+++ b/lib_static/open_project/configuration/helpers.rb@@ -38,6 +38,13 @@ module OpenProjectself['direct_uploads']end+ ##+ # Is hsts really enabled? We only return true+ # if the setting is true AND HTTPS mode is on.+ def hsts_enabled?+ https? && hsts?+ end+### We only allow direct uploads to S3 as we are using the carrierwave_direct# gem which only supports S3 for the time being.diff --git a/spec/constants/settings/definition_spec.rb b/spec/constants/settings/definition_spec.rbindex 69751691b2c..613c071ef72 100644--- a/spec/constants/settings/definition_spec.rb+++ b/spec/constants/settings/definition_spec.rb@@ -956,5 +956,18 @@ describe Settings::Definition do.to eq 0.5endend++ context 'with a boolean provided with a proc default' do+ let(:instance) do+ described_class.new 'bogus',+ format: :boolean,+ default: -> { false }+ end++ it 'calls the proc as a default' do+ expect(instance.default)+ .to be false+ end+ endendend