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
[#45965] Setting definitions validations access nonloaded constants
Pavel Balashovc5d75459dd40
diff --git a/app/models/permitted_params/allowed_settings.rb b/app/models/permitted_params/allowed_settings.rbindex d3e27409e90..45c04d8ac38 100644--- a/app/models/permitted_params/allowed_settings.rb+++ b/app/models/permitted_params/allowed_settings.rb@@ -20,7 +20,7 @@ class PermittedParamsmodule_functiondef all- keys = Setting.definitions.map(&:name)+ keys = Setting.definitions.keysrestrictions.select(&:applicable?).each do |restriction|restricted_keys = restriction.restricted_keys@@ -40,7 +40,7 @@ class PermittedParamsenddef init!- password_keys = %w(+ password_keys = %i(password_min_lengthpassword_active_rulespassword_min_adhered_rules@@ -55,7 +55,7 @@ class PermittedParams)add_restriction!(- keys: %w(registration_footer),+ keys: %i(registration_footer),condition: -> { OpenProject::Configuration.registration_footer.present? })enddiff --git a/app/models/setting.rb b/app/models/setting.rbindex 303a2750164..99248c188f6 100644--- a/app/models/setting.rb+++ b/app/models/setting.rb@@ -144,7 +144,7 @@ class Setting < ApplicationRecordvalidates :name,uniqueness: true,inclusion: {- in: ->(*) { Settings::Definition.all.map(&:name) } # @available_settings change at runtime+ in: ->(*) { Settings::Definition.all.keys.map(&:to_s) } # @available_settings change at runtime}validates :value,numericality: {diff --git a/app/seeders/basic_data/setting_seeder.rb b/app/seeders/basic_data/setting_seeder.rbindex f7dc7ac827f..8ee3efbdddf 100644--- a/app/seeders/basic_data/setting_seeder.rb+++ b/app/seeders/basic_data/setting_seeder.rb@@ -67,6 +67,7 @@ module BasicDatadef seedable_setting_definitionsSetting.definitions+ .values.select(&:writable?).reject { |definition| definition.value.nil? }enddiff --git a/config/application.rb b/config/application.rbindex d2635a094cc..8845cacc622 100644--- a/config/application.rb+++ b/config/application.rb@@ -36,7 +36,7 @@ require 'core_extensions'# Silence deprecations early on for testing on CI and productionActiveSupport::Deprecation.silenced =(Rails.env.production? && !ENV['OPENPROJECT_SHOW_DEPRECATIONS']) ||- (Rails.env.test? && ENV['CI'])+ (Rails.env.test? && ENV.fetch('CI', nil))if defined?(Bundler)# Require the gems listed in Gemfile, including any gems@@ -83,7 +83,7 @@ module OpenProject# Set up STDOUT logging if requestedif ENV["RAILS_LOG_TO_STDOUT"].present?- logger = ActiveSupport::Logger.new(STDOUT)+ logger = ActiveSupport::Logger.new($stdout)logger.formatter = config.log_formatterconfig.logger = ActiveSupport::TaggedLogging.new(logger)end@@ -214,8 +214,14 @@ module OpenProject# Enable the Rails 7 cache formatconfig.active_support.cache_format_version = 7.0+ config.after_initialize do+ Settings::Definition::DEFINITIONS.each do |setting_name, setting_options|+ Settings::Definition.add(setting_name, **setting_options)+ end+ end+def self.root_url- Setting.protocol + "://" + Setting.host_name+ "#{Setting.protocol}://#{Setting.host_name}"end##diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rbindex 5749125176d..9cb01956db7 100644--- a/config/constants/settings/definition.rb+++ b/config/constants/settings/definition.rb@@ -30,6 +30,996 @@ module Settingsclass DefinitionENV_PREFIX = 'OPENPROJECT_'.freezeAR_BOOLEAN_TYPE = ActiveRecord::Type::Boolean.new+ DEFINITIONS = {+ activity_days_default: {+ default: 30+ },+ after_first_login_redirect_url: {+ format: :string,+ description: 'URL users logging in for the first time will be redirected to (e.g., a help screen)',+ default: nil,+ writable: false+ },+ after_login_default_redirect_url: {+ description: 'Override URL to which logged in users are redirected instead of the My page',+ format: :string,+ default: nil,+ writable: false+ },+ apiv3_cors_enabled: {+ description: 'Enable CORS headers for APIv3 server responses',+ default: false+ },+ apiv3_cors_origins: {+ default: []+ },+ apiv3_docs_enabled: {+ description: 'Enable interactive APIv3 documentation as part of the application',+ default: true+ },+ apiv3_enable_basic_auth: {+ description: 'Enable API token or global basic authentication for APIv3 requests',+ default: true,+ writable: false+ },+ apiv3_max_page_size: {+ default: 1000+ },+ app_title: {+ default: 'OpenProject'+ },+ attachment_max_size: {+ default: 5120+ },+ # Existing setting+ attachment_whitelist: {+ default: []+ },+ ##+ # Carrierwave storage type. Possible values are, among others, :file and :fog.+ # The latter requires further configuration.+ attachments_storage: {+ description: 'File storage configuration',+ default: :file,+ format: :symbol,+ allowed: %i[file fog],+ writable: false+ },+ attachments_storage_path: {+ description: 'File storage disk location (only applicable for local file storage)',+ format: :string,+ default: nil,+ writable: false+ },+ attachments_grace_period: {+ description: 'Time to wait before uploaded files not attached to any container are removed',+ default: 180,+ writable: false+ },+ auth_source_sso: {+ description: 'Configuration for Header-based Single Sign-On',+ format: :hash,+ default: nil,+ writable: false+ },+ # Configures the authentication capabilities supported by the instance.+ # Currently this is focused on the configuration for basic auth.+ # e.g.+ # authentication:+ # global_basic_auth:+ # user: admin+ # password: 123456+ authentication: {+ description: 'Configuration options for global basic auth',+ format: :hash,+ default: nil,+ writable: false+ },+ autofetch_changesets: {+ default: true+ },+ # autologin duration in days+ # 0 means autologin is disabled+ autologin: {+ default: 0+ },+ autologin_cookie_name: {+ description: 'Cookie name for autologin cookie',+ default: 'autologin',+ writable: false+ },+ autologin_cookie_path: {+ description: 'Cookie path for autologin cookie',+ default: '/',+ writable: false+ },+ autologin_cookie_secure: {+ description: 'Cookie secure mode for autologin cookie',+ default: false,+ writable: false+ },+ available_languages: {+ format: :array,+ default: %w[en de fr es pt pt-BR it zh-CN ko ru].freeze,+ allowed: -> { Redmine::I18n.all_languages }+ },+ avatar_link_expiry_seconds: {+ description: 'Cache duration for avatar image API responses',+ default: 24.hours.to_i,+ writable: false+ },+ # Allow users with the required permissions to create backups via the web interface or API.+ backup_enabled: {+ description: 'Enable application backups through the UI',+ default: true,+ writable: false+ },+ backup_daily_limit: {+ description: 'Maximum number of application backups allowed per day',+ default: 3,+ writable: false+ },+ backup_initial_waiting_period: {+ description: 'Wait time before newly created backup tokens are usable',+ default: 24.hours,+ format: :integer,+ writable: false+ },+ backup_include_attachments: {+ description: 'Allow inclusion of attachments in application backups',+ default: true,+ writable: false+ },+ backup_attachment_size_max_sum_mb: {+ description: 'Maximum limit of attachment size to include into application backups',+ default: 1024,+ writable: false+ },+ blacklisted_routes: {+ description: 'Blocked routes to prevent access to certain modules or pages',+ default: [],+ writable: false+ },+ bcc_recipients: {+ default: true+ },+ boards_demo_data_available: {+ description: 'Internal setting determining availability of demo seed data',+ default: false+ },+ brute_force_block_minutes: {+ description: 'Number of minutes to block users after presumed brute force attack',+ default: 30+ },+ brute_force_block_after_failed_logins: {+ description: 'Number of login attempts per user before assuming brute force attack',+ default: 20+ },+ cache_expires_in_seconds: {+ description: 'Expiration time for memcache entries, empty for no expiry be default',+ format: :integer,+ default: nil,+ writable: false+ },+ cache_formatted_text: {+ default: true+ },+ # use dalli defaults for memcache+ cache_memcache_server: {+ description: 'The memcache server host and IP',+ format: :string,+ default: nil,+ writable: false+ },+ cache_namespace: {+ format: :string,+ description: 'Namespace for cache keys, useful when multiple applications use a single memcache server',+ default: nil,+ writable: false+ },+ commit_fix_done_ratio: {+ description: 'Progress to apply when commit fixes work package',+ default: 100+ },+ commit_fix_keywords: {+ description: 'Keywords to look for in commit for fixing work packages',+ default: 'fixes,closes'+ },+ commit_fix_status_id: {+ description: 'Assigned status when fixing keyword is found',+ format: :integer,+ default: nil,+ allowed: -> { Status.pluck(:id) + [nil] }+ },+ commit_logs_encoding: {+ description: "Encoding used to convert commit logs to UTF-8",+ default: 'UTF-8'+ },+ commit_logtime_activity_id: {+ description: :setting_commit_logtime_activity_id,+ format: :integer,+ default: nil,+ allowed: -> { TimeEntryActivity.pluck(:id) + [nil] }+ },+ commit_logtime_enabled: {+ description: "Allow logging time through commit message",+ default: false+ },+ commit_ref_keywords: {+ description: "Keywords used in commits for referencing work packages",+ default: 'refs,references,IssueID'+ },+ consent_decline_mail: {+ format: :string,+ default: nil+ },+ # Time after which users have to have consented to what ever they need to consent+ # to (depending on other settings) such as a privacy policy.+ consent_time: {+ default: nil,+ format: :datetime+ },+ # Additional info about what the user is consenting to (optional).+ consent_info: {+ default: {+ en: "## Consent\n\nYou need to agree to the [privacy and security policy]" ++ "(https://www.openproject.org/data-privacy-and-security/) of this OpenProject instance."+ }+ },+ # Indicates whether or not users need to consent to something such as privacy policy.+ consent_required: {+ default: false+ },+ cross_project_work_package_relations: {+ default: true+ },+ # Allow in-context translations to be loaded with CSP+ crowdin_in_context_translations: {+ description: 'Add crowdin in-context translations helper',+ default: true,+ writable: false+ },+ database_cipher_key: {+ description: 'Encryption key for repository credentials',+ format: :string,+ default: nil,+ writable: false+ },+ date_format: {+ format: :string,+ default: nil,+ allowed: [+ '%Y-%m-%d',+ '%d/%m/%Y',+ '%d.%m.%Y',+ '%d-%m-%Y',+ '%m/%d/%Y',+ '%d %b %Y',+ '%d %B %Y',+ '%b %d, %Y',+ '%B %d, %Y'+ ].freeze+ },+ default_auto_hide_popups: {+ description: 'Whether to automatically hide success notifications by default',+ default: true+ },+ # user configuration+ default_comment_sort_order: {+ description: 'Default sort order for activities',+ default: 'asc',+ writable: false+ },+ default_language: {+ default: 'en'+ },+ default_projects_modules: {+ default: %w[calendar board_view work_package_tracking news costs wiki],+ allowed: -> { OpenProject::AccessControl.available_project_modules.map(&:to_s) }+ },+ default_projects_public: {+ default: false+ },+ demo_projects_available: {+ default: false+ },+ demo_view_of_type_work_packages_table_seeded: {+ default: false+ },+ demo_view_of_type_team_planner_seeded: {+ default: false+ },+ diff_max_lines_displayed: {+ default: 1500+ },+ direct_uploads: {+ description: 'Enable direct uploads to AWS S3. Only applicable with enabled Fog / AWS S3 configuration',+ default: true,+ writable: false+ },+ disable_browser_cache: {+ description: 'Prevent browser from caching any logged-in responses for security reasons',+ default: true,+ writable: false+ },+ # allow to disable default modules+ disabled_modules: {+ description: 'A list of module names to prevent access to in the application',+ default: [],+ allowed: -> { OpenProject::AccessControl.available_project_modules.map(&:to_s) },+ writable: false+ },+ disable_password_choice: {+ description: "If enabled a user's password cannot be set to an arbitrary value, but can only be randomized.",+ default: false,+ writable: false+ },+ disable_password_login: {+ description: 'Disable internal logins and instead only allow SSO through OmniAuth.',+ default: false,+ writable: false+ },+ display_subprojects_work_packages: {+ default: true+ },+ drop_old_sessions_on_logout: {+ description: 'Destroy all sessions for current_user on logout',+ default: true,+ writable: false+ },+ drop_old_sessions_on_login: {+ description: 'Destroy all sessions for current_user on login',+ default: false,+ writable: false+ },+ edition: {+ format: :string,+ default: 'standard',+ description: 'OpenProject edition mode',+ writable: false,+ allowed: %w[standard bim]+ },+ ee_manager_visible: {+ description: 'Show or hide the Enterprise configuration page and enterprise banners',+ default: true,+ writable: false+ },+ enable_internal_assets_server: {+ description: 'Serve assets through the Rails internal asset server',+ default: false,+ writable: false+ },+ # email configuration+ email_delivery_configuration: {+ default: 'inapp',+ allowed: %w[inapp legacy],+ writable: false,+ env_alias: 'EMAIL_DELIVERY_CONFIGURATION'+ },+ email_delivery_method: {+ format: :symbol,+ default: nil,+ env_alias: 'EMAIL_DELIVERY_METHOD'+ },+ emails_footer: {+ default: {+ 'en' => ''+ }+ },+ emails_header: {+ default: {+ 'en' => ''+ }+ },+ # use email address as login, hide login in registration form+ email_login: {+ default: false+ },+ enabled_projects_columns: {+ default: %w[project_status public created_at latest_activity_at required_disk_space],+ allowed: -> { Projects::TableCell.new(nil, current_user: User.admin.first).all_columns.map(&:first).map(&:to_s) }+ },+ enabled_scm: {+ default: %w[subversion git]+ },+ # Allow connections for trial creation and booking+ enterprise_trial_creation_host: {+ description: 'Host for EE trial service',+ default: 'https://augur.openproject.com',+ writable: false+ },+ enterprise_chargebee_site: {+ description: 'Site name for EE trial service',+ default: 'openproject-enterprise',+ writable: false+ },+ enterprise_plan: {+ description: 'Default EE selected plan',+ default: 'enterprise-on-premises---euro---1-year',+ writable: false+ },+ feeds_enabled: {+ default: true+ },+ feeds_limit: {+ default: 15+ },+ # Maximum size of files that can be displayed+ # inline through the file viewer (in KB)+ file_max_size_displayed: {+ default: 512+ },+ first_week_of_year: {+ default: nil,+ format: :integer,+ allowed: [1, 4]+ },+ fog: {+ description: 'Configure fog, e.g. when using an S3 uploader',+ default: {}+ },+ fog_download_url_expires_in: {+ description: 'Expiration time in seconds of created shared presigned URLs',+ default: 21600, # 6h by default as 6 hours is max in S3 when using IAM roles+ writable: false+ },+ # Additional / overridden help links+ force_help_link: {+ description: 'You can set a custom URL for the help button in application header menu.',+ format: :string,+ default: nil,+ writable: false+ },+ force_formatting_help_link: {+ description: 'You can set a custom URL for the help button in the WYSIWYG editor.',+ format: :string,+ default: nil,+ writable: false+ },+ forced_single_page_size: {+ description: 'Forced page size for manually sorted work package views',+ default: 250+ },+ host_name: {+ default: "localhost:3000"+ },+ # Health check configuration+ health_checks_authentication_password: {+ description: 'Add an authentication challenge for the /health_check endpoint',+ format: :string,+ default: nil,+ writable: false+ },+ # Maximum number of backed up jobs (that are not yet executed)+ # before health check fails+ health_checks_jobs_queue_count_threshold: {+ description: 'Set threshold of backed up background jobs to fail health check',+ format: :integer,+ default: 50,+ writable: false+ },+ ## Maximum number of minutes that jobs have not yet run after their designated 'run_at' time+ health_checks_jobs_never_ran_minutes_ago: {+ description: 'Set threshold of outstanding background jobs to fail health check',+ format: :integer,+ default: 5,+ writable: false+ },+ ## Maximum number of unprocessed requests in puma's backlog.+ health_checks_backlog_threshold: {+ description: 'Set threshold of outstanding HTTP requests to fail health check',+ format: :integer,+ default: 20,+ writable: false+ },+ # Default gravatar image, set to something other than 404+ # to ensure a default is returned+ gravatar_fallback_image: {+ description: 'Set default gravatar image fallback',+ default: '404',+ writable: false+ },+ hidden_menu_items: {+ description: 'Hide menu items in the menu sidebar for each main menu (such as Administration and Projects).',+ default: {},+ writable: false+ },+ impressum_link: {+ description: 'Impressum link to be set, hidden by default',+ format: :string,+ default: nil,+ writable: false+ },+ installation_type: {+ default: 'manual',+ writable: false+ },+ installation_uuid: {+ format: :string,+ default: nil+ },+ internal_password_confirmation: {+ description: 'Require password confirmations for certain administrative actions',+ default: true,+ writable: false+ },+ invitation_expiration_days: {+ default: 7+ },+ journal_aggregation_time_minutes: {+ default: 5+ },+ ldap_force_no_page: {+ description: 'Force LDAP to respond as a single page, in case paged responses do not work with your server.',+ format: :string,+ default: nil,+ writable: false+ },+ ldap_groups_disable_sync_job: {+ description: 'Deactivate regular synchronization job for groups in case scheduled as a separate cronjob',+ default: false,+ writable: false+ },+ ldap_users_disable_sync_job: {+ description: 'Deactive user attributes synchronization from LDAP',+ default: false,+ writable: false+ },+ ldap_users_sync_status: {+ description: 'Enable user status (locked/unlocked) synchronization from LDAP',+ format: :boolean,+ default: false,+ writable: false+ },+ ldap_tls_options: {+ format: :hash,+ default: {},+ writable: true+ },+ log_level: {+ description: 'Set the OpenProject logger level',+ default: Rails.env.development? ? 'debug' : 'info',+ allowed: %w[debug info warn error fatal],+ writable: false+ },+ log_requesting_user: {+ default: false+ },+ # Use lograge to format logs, off by default+ lograge_formatter: {+ description: 'Use lograge formatter for outputting logs',+ default: nil,+ format: :string,+ writable: false+ },+ login_required: {+ default: false+ },+ lost_password: {+ description: 'Activate or deactivate lost password form',+ default: true+ },+ mail_from: {+ default: '[email protected]'+ },+ mail_handler_api_key: {+ format: :string,+ default: nil+ },+ mail_handler_body_delimiters: {+ default: ''+ },+ mail_handler_body_delimiter_regex: {+ default: ''+ },+ mail_handler_ignore_filenames: {+ default: 'signature.asc'+ },+ mail_suffix_separators: {+ default: '+'+ },+ main_content_language: {+ default: 'english',+ description: 'Main content language for PostgreSQL full text features',+ writable: false,+ allowed: %w[danish dutch english finnish french german hungarian+ italian norwegian portuguese romanian russian simple spanish swedish turkish]+ },+ migration_check_on_exceptions: {+ description: 'Check for missing migrations in internal errors',+ default: true,+ writable: false+ },+ # Role given to a non-admin user who creates a project+ new_project_user_role_id: {+ format: :integer,+ default: nil,+ allowed: -> { Role.pluck(:id) }+ },+ oauth_allow_remapping_of_existing_users: {+ description: 'When set to false, prevent users from other identity providers to take over accounts connected ' \+ 'to another identity provider.',+ default: true+ },+ omniauth_direct_login_provider: {+ description: 'Clicking on login sends a login request to the specified OmniAuth provider.',+ format: :string,+ default: nil,+ writable: false+ },+ override_bcrypt_cost_factor: {+ description: "Set a custom BCrypt cost factor for deriving a user's bcrypt hash.",+ format: :string,+ default: nil,+ writable: false+ },+ onboarding_video_url: {+ description: 'Onboarding guide instructional video URL',+ default: 'https://player.vimeo.com/video/163426858?autoplay=1',+ writable: false+ },+ onboarding_enabled: {+ description: 'Enable or disable onboarding guided tour for new users',+ default: true,+ writable: false+ },+ password_active_rules: {+ default: %w[lowercase uppercase numeric special],+ allowed: %w[lowercase uppercase numeric special]+ },+ password_count_former_banned: {+ default: 0+ },+ password_days_valid: {+ default: 0+ },+ password_min_length: {+ default: 10+ },+ password_min_adhered_rules: {+ default: 0+ },+ # TODO: turn into array of ints+ # Requires a migration to be written+ # replace Setting#per_page_options_array+ per_page_options: {+ default: '20, 100'+ },+ plain_text_mail: {+ default: false+ },+ project_gantt_query: {+ default: nil,+ format: :string+ },+ rails_asset_host: {+ description: 'Custom asset hostname for serving assets (e.g., Cloudfront)',+ format: :string,+ default: nil,+ writable: false+ },+ rails_cache_store: {+ description: 'Set cache store implemenation to use with OpenProject',+ format: :symbol,+ default: :file_store,+ writable: false,+ allowed: %i[file_store memcache]+ },+ rails_relative_url_root: {+ description: 'Set a URL prefix / base path to run OpenProject under, e.g., host.tld/openproject',+ default: '',+ writable: false+ },+ https: {+ description: 'Set assumed connection security for the Rails processes',+ format: :boolean,+ default: -> { Rails.env.production? },+ writable: false+ },+ hsts: {+ description: 'Allow disabling of HSTS headers and http -> https redirects',+ format: :boolean,+ default: true,+ writable: false+ },+ registration_footer: {+ default: {+ 'en' => ''+ },+ writable: false+ },+ report_incoming_email_errors: {+ description: 'Respond to incoming mails with error details',+ default: true+ },+ repositories_automatic_managed_vendor: {+ default: nil,+ format: :string,+ allowed: -> { OpenProject::SCM::Manager.registered.keys.map(&:to_s) }+ },+ # encodings used to convert repository files content to UTF-8+ # multiple values accepted, comma separated+ repositories_encodings: {+ default: nil,+ format: :string+ },+ repository_authentication_caching_enabled: {+ default: true+ },+ repository_checkout_data: {+ default: {+ "git" => { "enabled" => 0 },+ "subversion" => { "enabled" => 0 }+ }+ },+ repository_log_display_limit: {+ default: 100+ },+ repository_storage_cache_minutes: {+ default: 720+ },+ repository_truncate_at: {+ default: 500+ },+ rest_api_enabled: {+ default: true+ },+ scm: {+ format: :hash,+ default: {},+ writable: false+ },+ scm_git_command: {+ format: :string,+ default: nil,+ writable: false+ },+ scm_local_checkout_path: {+ default: 'repositories', # relative to OpenProject directory+ writable: false+ },+ scm_subversion_command: {+ format: :string,+ default: nil,+ writable: false+ },+ # Display update / security badge, enabled by default+ security_badge_displayed: {+ default: true+ },+ security_badge_url: {+ description: 'URL of the update check badge',+ default: "https://releases.openproject.com/v1/check.svg",+ writable: false+ },+ self_registration: {+ default: 2+ },+ sendmail_arguments: {+ description: 'Arguments to call sendmail with in case it is configured as outgoing email setup',+ format: :string,+ default: "-i",+ writable: false+ },+ sendmail_location: {+ description: 'Location of sendmail to call if it is configured as outgoing email setup',+ format: :string,+ default: "/usr/sbin/sendmail"+ },+ # Allow separate error reporting for frontend errors+ appsignal_frontend_key: {+ format: :string,+ default: nil,+ description: 'Appsignal API key for JavaScript error reporting',+ writable: false+ },+ session_cookie_name: {+ description: 'Set session cookie name',+ default: '_open_project_session',+ writable: false+ },+ session_store: {+ description: 'Where to store session data',+ default: :active_record_store,+ writable: false+ },+ session_ttl_enabled: {+ default: false+ },+ session_ttl: {+ default: 120+ },+ show_community_links: {+ description: 'Enable or disable links to OpenProject community instances',+ default: true,+ writable: false+ },+ show_pending_migrations_warning: {+ description: 'Enable or disable warning bar in case of pending migrations',+ default: true,+ writable: false+ },+ show_setting_mismatch_warning: {+ description: 'Show mismatched protocol/hostname warning. In cases where they must differ this can be disabled',+ default: true,+ writable: false+ },+ # Render storage information+ show_storage_information: {+ description: 'Show available and taken storage information under administration / info',+ default: true,+ writable: false+ },+ show_warning_bars: {+ description: 'Render warning bars (pending migrations, deprecation, unsupported browsers)',+ default: true,+ writable: false+ },+ smtp_authentication: {+ format: :string,+ default: 'plain',+ env_alias: 'SMTP_AUTHENTICATION'+ },+ smtp_enable_starttls_auto: {+ format: :boolean,+ default: false,+ env_alias: 'SMTP_ENABLE_STARTTLS_AUTO'+ },+ smtp_openssl_verify_mode: {+ description: 'Globally set verify mode for OpenSSL. Careful: Setting to none will disable any SSL verification!',+ format: :string,+ default: "peer",+ allowed: %w[none peer client_once fail_if_no_peer_cert],+ writable: false+ },+ smtp_ssl: {+ format: :boolean,+ default: false,+ env_alias: 'SMTP_SSL'+ },+ smtp_address: {+ format: :string,+ default: '',+ env_alias: 'SMTP_ADDRESS'+ },+ smtp_domain: {+ format: :string,+ default: 'your.domain.com',+ env_alias: 'SMTP_DOMAIN'+ },+ smtp_user_name: {+ format: :string,+ default: '',+ env_alias: 'SMTP_USER_NAME'+ },+ smtp_port: {+ format: :integer,+ default: 587,+ env_alias: 'SMTP_PORT'+ },+ smtp_password: {+ format: :string,+ default: '',+ env_alias: 'SMTP_PASSWORD'+ },+ software_name: {+ description: 'Override software application name',+ default: 'OpenProject'+ },+ software_url: {+ description: 'Override software application URL',+ default: 'https://www.openproject.org/'+ },+ sql_slow_query_threshold: {+ description: 'Time limit in ms after which queries will be logged as slow queries',+ default: 2000,+ writable: false+ },+ start_of_week: {+ default: nil,+ format: :integer,+ allowed: [1, 6, 7]+ },+ statsd: {+ description: 'enable statsd metrics (currently puma only) by configuring host',+ default: {+ 'host' => nil,+ 'port' => 8125+ },+ writable: false+ },+ sys_api_enabled: {+ description: 'Enable internal system API for setting up managed repositories',+ default: false+ },+ sys_api_key: {+ description: 'Internal system API key for setting up managed repositories',+ default: nil,+ format: :string+ },+ time_format: {+ format: :string,+ default: nil,+ allowed: [+ '%H:%M',+ '%I:%M %p'+ ].freeze+ },+ user_default_timezone: {+ default: nil,+ format: :string,+ allowed: ActiveSupport::TimeZone.all.map { |tz| tz.tzinfo.canonical_identifier }.sort.uniq + [nil]+ },+ users_deletable_by_admins: {+ default: false+ },+ users_deletable_by_self: {+ default: false+ },+ user_format: {+ default: :firstname_lastname,+ allowed: -> { User::USER_FORMATS_STRUCTURE.keys }+ },+ web: {+ description: 'Web worker count and threads configuration',+ default: {+ 'workers' => 2,+ 'timeout' => 120,+ 'wait_timeout' => 10,+ 'min_threads' => 4,+ 'max_threads' => 16+ },+ writable: false+ },+ welcome_text: {+ format: :string,+ default: nil+ },+ welcome_title: {+ format: :string,+ default: nil+ },+ welcome_on_homescreen: {+ default: false+ },+ work_package_done_ratio: {+ default: 'field',+ allowed: %w[field status disabled]+ },+ work_packages_projects_export_limit: {+ default: 500+ },+ work_package_list_default_highlighted_attributes: {+ default: [],+ allowed: -> {+ Query.available_columns(nil).select(&:highlightable).map(&:name).map(&:to_s)+ }+ },+ work_package_list_default_highlighting_mode: {+ format: :string,+ default: -> { EnterpriseToken.allows_to?(:conditional_highlighting) ? 'inline' : 'none' },+ allowed: -> { Query::QUERY_HIGHLIGHTING_MODES },+ writable: -> { EnterpriseToken.allows_to?(:conditional_highlighting) }+ },+ work_package_list_default_columns: {+ default: %w[id subject type status assigned_to priority],+ allowed: -> { Query.new.displayable_columns.map(&:name).map(&:to_s) }+ },+ work_package_startdate_is_adddate: {+ default: false+ },+ working_days: {+ description: 'Set working days of the week (Array of 1 to 7, where 1=Monday, 7=Sunday)',+ format: :array,+ allowed: Array(1..7),+ default: Array(1..5) # Sat, Sun being non-working days,+ },+ youtube_channel: {+ description: 'Link to YouTube channel in help menu',+ default: 'https://www.youtube.com/c/OpenProjectCommunity',+ writable: false+ }+ }.freezeattr_accessor :name,:format,@@ -152,9 +1142,10 @@ module Settingswritable: true,allowed: nil,env_alias: nil)- return if @by_name.present? && @by_name[name.to_s].present?+ name = name.to_sym+ return if @all.present? && @all[name].present?- @by_name = nil+ @all = {} if @all.nil?definition = new(name,format:,@@ -163,10 +1154,8 @@ module Settingswritable:,allowed:,env_alias:)-override_value(definition)-- all << definition+ @all[name] = definitionenddef define(&)@@ -174,45 +1163,25 @@ module Settingsenddef [](name)- by_name[name.to_s]+ name = name.to_sym+ if @all.present? && @all.key?(name)+ @all[name]+ else+ h = DEFINITIONS[name]+ add(name, **h) if h.present?+ endenddef exists?(name)- by_name.keys.include?(name.to_s)- end-- def all_of_prefix(prefix)- all.select { |definition| definition.name.start_with?(prefix) }+ @all.keys.include?(name.to_sym)enddef all- @all ||= []-- unless loaded- self.loaded = true- load './config/constants/settings/definitions.rb'- end-@allendprivate- # Currently only required for testing.- #- # Tag your test with :settings_reset to start test with fresh settings- # definitions and restore them after test.- def reset- @all = nil- @loaded = false- @by_name = nil- @file_config = nil- end-- def by_name- @by_name ||= all.index_by(&:name)- end-def file_config@file_config ||= beginfilename = Rails.root.join('config/configuration.yml')@@ -391,8 +1360,6 @@ module Settingsdef load_yaml(source)YAML::safe_load(source, permitted_classes: [Symbol, Date])end-- attr_accessor :loadedendprivatediff --git a/config/constants/settings/definitions.rb b/config/constants/settings/definitions.rbdeleted file mode 100644index 601e52a23ea..00000000000--- a/config/constants/settings/definitions.rb+++ /dev/null@@ -1,1023 +0,0 @@-#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2023 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 docs/COPYRIGHT.rdoc for more details.-#++--# The list of all defined settings that however might get extended e.g. in modules/plugins-# Contains what was formerly defined in both the settings.yml as well as in configuration.rb.-# Values from the later can typically be identified by having-# writable: false-# set. That would not be strictly necessary since they currently don't have a UI anyway and-# that is where the value is actually used.--Settings::Definition.define do- add :activity_days_default,- default: 30-- add :after_first_login_redirect_url,- format: :string,- description: 'URL users logging in for the first time will be redirected to (e.g., a help screen)',- default: nil,- writable: false-- add :after_login_default_redirect_url,- description: 'Override URL to which logged in users are redirected instead of the My page',- format: :string,- default: nil,- writable: false-- add :apiv3_cors_enabled,- description: 'Enable CORS headers for APIv3 server responses',- default: false-- add :apiv3_cors_origins,- default: []-- add :apiv3_docs_enabled,- description: 'Enable interactive APIv3 documentation as part of the application',- default: true-- add :apiv3_enable_basic_auth,- description: 'Enable API token or global basic authentication for APIv3 requests',- default: true,- writable: false-- add :apiv3_max_page_size,- default: 1000-- add :app_title,- default: 'OpenProject'-- add :attachment_max_size,- default: 5120-- # Existing setting- add :attachment_whitelist,- default: []-- ##- # Carrierwave storage type. Possible values are, among others, :file and :fog.- # The latter requires further configuration.- add :attachments_storage,- description: 'File storage configuration',- default: :file,- format: :symbol,- allowed: %i[file fog],- writable: false-- add :attachments_storage_path,- description: 'File storage disk location (only applicable for local file storage)',- format: :string,- default: nil,- writable: false-- add :attachments_grace_period,- description: 'Time to wait before uploaded files not attached to any container are removed',- default: 180,- writable: false-- add :auth_source_sso,- description: 'Configuration for Header-based Single Sign-On',- format: :hash,- default: nil,- writable: false-- # Configures the authentication capabilities supported by the instance.- # Currently this is focused on the configuration for basic auth.- # e.g.- # authentication:- # global_basic_auth:- # user: admin- # password: 123456- add :authentication,- description: 'Configuration options for global basic auth',- format: :hash,- default: nil,- writable: false-- add :autofetch_changesets,- default: true-- # autologin duration in days- # 0 means autologin is disabled- add :autologin,- default: 0-- add :autologin_cookie_name,- description: 'Cookie name for autologin cookie',- default: 'autologin',- writable: false-- add :autologin_cookie_path,- description: 'Cookie path for autologin cookie',- default: '/',- writable: false-- add :autologin_cookie_secure,- description: 'Cookie secure mode for autologin cookie',- default: false,- writable: false-- add :available_languages,- format: :array,- default: %w[en de fr es pt pt-BR it zh-CN ko ru].freeze,- allowed: -> { Redmine::I18n.all_languages }-- add :avatar_link_expiry_seconds,- description: 'Cache duration for avatar image API responses',- default: 24.hours.to_i,- writable: false-- # Allow users with the required permissions to create backups via the web interface or API.- add :backup_enabled,- description: 'Enable application backups through the UI',- default: true,- writable: false-- add :backup_daily_limit,- description: 'Maximum number of application backups allowed per day',- default: 3,- writable: false-- add :backup_initial_waiting_period,- description: 'Wait time before newly created backup tokens are usable',- default: 24.hours,- format: :integer,- writable: false-- add :backup_include_attachments,- description: 'Allow inclusion of attachments in application backups',- default: true,- writable: false-- add :backup_attachment_size_max_sum_mb,- description: 'Maximum limit of attachment size to include into application backups',- default: 1024,- writable: false-- add :blacklisted_routes,- description: 'Blocked routes to prevent access to certain modules or pages',- default: [],- writable: false-- add :bcc_recipients,- default: true-- add :boards_demo_data_available,- description: 'Internal setting determining availability of demo seed data',- default: false-- add :brute_force_block_minutes,- description: 'Number of minutes to block users after presumed brute force attack',- default: 30-- add :brute_force_block_after_failed_logins,- description: 'Number of login attempts per user before assuming brute force attack',- default: 20-- add :cache_expires_in_seconds,- description: 'Expiration time for memcache entries, empty for no expiry be default',- format: :integer,- default: nil,- writable: false-- add :cache_formatted_text,- default: true-- # use dalli defaults for memcache- add :cache_memcache_server,- description: 'The memcache server host and IP',- format: :string,- default: nil,- writable: false-- add :cache_namespace,- format: :string,- description: 'Namespace for cache keys, useful when multiple applications use a single memcache server',- default: nil,- writable: false-- add :commit_fix_done_ratio,- description: 'Progress to apply when commit fixes work package',- default: 100-- add :commit_fix_keywords,- description: 'Keywords to look for in commit for fixing work packages',- default: 'fixes,closes'-- add :commit_fix_status_id,- description: 'Assigned status when fixing keyword is found',- format: :integer,- default: nil,- allowed: -> { Status.pluck(:id) + [nil] }-- add :commit_logs_encoding,- description: "Encoding used to convert commit logs to UTF-8",- default: 'UTF-8'-- add :commit_logtime_activity_id,- description: :setting_commit_logtime_activity_id,- format: :integer,- default: nil,- allowed: -> { TimeEntryActivity.pluck(:id) + [nil] }-- add :commit_logtime_enabled,- description: "Allow logging time through commit message",- default: false-- add :commit_ref_keywords,- description: "Keywords used in commits for referencing work packages",- default: 'refs,references,IssueID'-- add :consent_decline_mail,- format: :string,- default: nil-- # Time after which users have to have consented to what ever they need to consent- # to (depending on other settings) such as a privacy policy.- add :consent_time,- default: nil,- format: :datetime-- # Additional info about what the user is consenting to (optional).- add :consent_info,- default: {- en: "## Consent\n\nYou need to agree to the [privacy and security policy]" +- "(https://www.openproject.org/data-privacy-and-security/) of this OpenProject instance."- }-- # Indicates whether or not users need to consent to something such as privacy policy.- add :consent_required,- default: false-- add :cross_project_work_package_relations,- default: true-- # Allow in-context translations to be loaded with CSP- add :crowdin_in_context_translations,- description: 'Add crowdin in-context translations helper',- default: true,- writable: false-- add :database_cipher_key,- description: 'Encryption key for repository credentials',- format: :string,- default: nil,- writable: false-- add :date_format,- format: :string,- default: nil,- allowed: [- '%Y-%m-%d',- '%d/%m/%Y',- '%d.%m.%Y',- '%d-%m-%Y',- '%m/%d/%Y',- '%d %b %Y',- '%d %B %Y',- '%b %d, %Y',- '%B %d, %Y'- ].freeze-- add :default_auto_hide_popups,- description: 'Whether to automatically hide success notifications by default',- default: true-- # user configuration- add :default_comment_sort_order,- description: 'Default sort order for activities',- default: 'asc',- writable: false-- add :default_language,- default: 'en'-- add :default_projects_modules,- default: %w[calendar board_view work_package_tracking news costs wiki],- allowed: -> { OpenProject::AccessControl.available_project_modules.map(&:to_s) }-- add :default_projects_public,- default: false-- add :demo_projects_available,- default: false-- add :demo_view_of_type_work_packages_table_seeded,- default: false-- add :demo_view_of_type_team_planner_seeded,- default: false-- add :diff_max_lines_displayed,- default: 1500-- add :direct_uploads,- description: 'Enable direct uploads to AWS S3. Only applicable with enabled Fog / AWS S3 configuration',- default: true,- writable: false-- add :disable_browser_cache,- description: 'Prevent browser from caching any logged-in responses for security reasons',- default: true,- writable: false-- # allow to disable default modules- add :disabled_modules,- description: 'A list of module names to prevent access to in the application',- default: [],- writable: false-- add :disable_password_choice,- description: "If enabled a user's password cannot be set to an arbitrary value, but can only be randomized.",- default: false,- writable: false-- add :disable_password_login,- description: 'Disable internal logins and instead only allow SSO through OmniAuth.',- default: false,- writable: false-- add :display_subprojects_work_packages,- default: true-- add :drop_old_sessions_on_logout,- description: 'Destroy all sessions for current_user on logout',- default: true,- writable: false-- add :drop_old_sessions_on_login,- description: 'Destroy all sessions for current_user on login',- default: false,- writable: false-- add :edition,- format: :string,- default: 'standard',- description: 'OpenProject edition mode',- writable: false,- allowed: %w[standard bim]-- add :ee_manager_visible,- description: 'Show or hide the Enterprise configuration page and enterprise banners',- default: true,- writable: false-- add :enable_internal_assets_server,- description: 'Serve assets through the Rails internal asset server',- default: false,- writable: false-- # email configuration- add :email_delivery_configuration,- default: 'inapp',- allowed: %w[inapp legacy],- writable: false,- env_alias: 'EMAIL_DELIVERY_CONFIGURATION'-- add :email_delivery_method,- format: :symbol,- default: nil,- env_alias: 'EMAIL_DELIVERY_METHOD'-- add :emails_footer,- default: {- 'en' => ''- }-- add :emails_header,- default: {- 'en' => ''- }-- # use email address as login, hide login in registration form- add :email_login,- default: false-- add :enabled_projects_columns,- default: %w[project_status public created_at latest_activity_at required_disk_space],- allowed: -> { Projects::TableCell.new(nil, current_user: User.admin.first).all_columns.map(&:first).map(&:to_s) }-- add :enabled_scm,- default: %w[subversion git]-- # Allow connections for trial creation and booking- add :enterprise_trial_creation_host,- description: 'Host for EE trial service',- default: 'https://augur.openproject.com',- writable: false-- add :enterprise_chargebee_site,- description: 'Site name for EE trial service',- default: 'openproject-enterprise',- writable: false-- add :enterprise_plan,- description: 'Default EE selected plan',- default: 'enterprise-on-premises---euro---1-year',- writable: false-- add :feeds_enabled,- default: true-- add :feeds_limit,- default: 15-- # Maximum size of files that can be displayed- # inline through the file viewer (in KB)- add :file_max_size_displayed,- default: 512-- add :first_week_of_year,- default: nil,- format: :integer,- allowed: [1, 4]-- add :fog,- description: 'Configure fog, e.g. when using an S3 uploader',- default: {}-- add :fog_download_url_expires_in,- description: 'Expiration time in seconds of created shared presigned URLs',- default: 21600, # 6h by default as 6 hours is max in S3 when using IAM roles- writable: false-- # Additional / overridden help links- add :force_help_link,- description: 'You can set a custom URL for the help button in application header menu.',- format: :string,- default: nil,- writable: false-- add :force_formatting_help_link,- description: 'You can set a custom URL for the help button in the WYSIWYG editor.',- format: :string,- default: nil,- writable: false-- add :forced_single_page_size,- description: 'Forced page size for manually sorted work package views',- default: 250-- add :host_name,- default: "localhost:3000"-- # Health check configuration- add :health_checks_authentication_password,- description: 'Add an authentication challenge for the /health_check endpoint',- format: :string,- default: nil,- writable: false-- # Maximum number of backed up jobs (that are not yet executed)- # before health check fails- add :health_checks_jobs_queue_count_threshold,- description: 'Set threshold of backed up background jobs to fail health check',- format: :integer,- default: 50,- writable: false-- ## Maximum number of minutes that jobs have not yet run after their designated 'run_at' time- add :health_checks_jobs_never_ran_minutes_ago,- description: 'Set threshold of outstanding background jobs to fail health check',- format: :integer,- default: 5,- writable: false-- ## Maximum number of unprocessed requests in puma's backlog.- add :health_checks_backlog_threshold,- description: 'Set threshold of outstanding HTTP requests to fail health check',- format: :integer,- default: 20,- writable: false-- # Default gravatar image, set to something other than 404- # to ensure a default is returned- add :gravatar_fallback_image,- description: 'Set default gravatar image fallback',- default: '404',- writable: false-- add :hidden_menu_items,- description: 'Hide menu items in the menu sidebar for each main menu (such as Administration and Projects).',- default: {},- writable: false-- add :impressum_link,- description: 'Impressum link to be set, hidden by default',- format: :string,- default: nil,- writable: false-- add :installation_type,- default: 'manual',- writable: false-- add :installation_uuid,- format: :string,- default: nil-- add :internal_password_confirmation,- description: 'Require password confirmations for certain administrative actions',- default: true,- writable: false-- add :invitation_expiration_days,- default: 7-- add :journal_aggregation_time_minutes,- default: 5-- add :ldap_force_no_page,- description: 'Force LDAP to respond as a single page, in case paged responses do not work with your server.',- format: :string,- default: nil,- writable: false-- add :ldap_groups_disable_sync_job,- description: 'Deactivate regular synchronization job for groups in case scheduled as a separate cronjob',- default: false,- writable: false-- add :ldap_users_disable_sync_job,- description: 'Deactive user attributes synchronization from LDAP',- default: false,- writable: false-- add :ldap_users_sync_status,- description: 'Enable user status (locked/unlocked) synchronization from LDAP',- format: :boolean,- default: false,- writable: false-- add :ldap_tls_options,- format: :hash,- default: {},- writable: true-- add :log_level,- description: 'Set the OpenProject logger level',- default: Rails.env.development? ? 'debug' : 'info',- allowed: %w[debug info warn error fatal],- writable: false-- add :log_requesting_user,- default: false-- # Use lograge to format logs, off by default- add :lograge_formatter,- description: 'Use lograge formatter for outputting logs',- default: nil,- format: :string,- writable: false-- add :login_required,- default: false-- add :lost_password,- description: 'Activate or deactivate lost password form',- default: true-- add :mail_from,- default: '[email protected]'-- add :mail_handler_api_key,- format: :string,- default: nil-- add :mail_handler_body_delimiters,- default: ''-- add :mail_handler_body_delimiter_regex,- default: ''-- add :mail_handler_ignore_filenames,- default: 'signature.asc'-- add :mail_suffix_separators,- default: '+'-- add :main_content_language,- default: 'english',- description: 'Main content language for PostgreSQL full text features',- writable: false,- allowed: %w[danish dutch english finnish french german hungarian- italian norwegian portuguese romanian russian simple spanish swedish turkish]-- add :migration_check_on_exceptions,- description: 'Check for missing migrations in internal errors',- default: true,- writable: false-- # Role given to a non-admin user who creates a project- add :new_project_user_role_id,- format: :integer,- default: nil,- allowed: -> { Role.pluck(:id) }-- add :oauth_allow_remapping_of_existing_users,- description: 'When set to false, prevent users from other identity providers to take over accounts connected ' \- 'to another identity provider.',- default: true-- add :omniauth_direct_login_provider,- description: 'Clicking on login sends a login request to the specified OmniAuth provider.',- format: :string,- default: nil,- writable: false-- add :override_bcrypt_cost_factor,- description: "Set a custom BCrypt cost factor for deriving a user's bcrypt hash.",- format: :string,- default: nil,- writable: false-- add :onboarding_video_url,- description: 'Onboarding guide instructional video URL',- default: 'https://player.vimeo.com/video/163426858?autoplay=1',- writable: false-- add :onboarding_enabled,- description: 'Enable or disable onboarding guided tour for new users',- default: true,- writable: false-- add :password_active_rules,- default: %w[lowercase uppercase numeric special],- allowed: %w[lowercase uppercase numeric special]-- add :password_count_former_banned,- default: 0-- add :password_days_valid,- default: 0-- add :password_min_length,- default: 10-- add :password_min_adhered_rules,- default: 0-- # TODO: turn into array of ints- # Requires a migration to be written- # replace Setting#per_page_options_array- add :per_page_options,- default: '20, 100'-- add :plain_text_mail,- default: false-- add :project_gantt_query,- default: nil,- format: :string-- add :rails_asset_host,- description: 'Custom asset hostname for serving assets (e.g., Cloudfront)',- format: :string,- default: nil,- writable: false-- add :rails_cache_store,- description: 'Set cache store implemenation to use with OpenProject',- format: :symbol,- default: :file_store,- writable: false,- allowed: %i[file_store memcache]-- add :rails_relative_url_root,- description: 'Set a URL prefix / base path to run OpenProject under, e.g., host.tld/openproject',- default: '',- writable: false-- add :https,- description: 'Set assumed connection security for the Rails processes',- format: :boolean,- default: -> { Rails.env.production? },- writable: false-- add :hsts,- description: 'Allow disabling of HSTS headers and http -> https redirects',- format: :boolean,- default: true,- writable: false-- add :registration_footer,- default: {- 'en' => ''- },- writable: false-- add :report_incoming_email_errors,- description: 'Respond to incoming mails with error details',- default: true-- add :repositories_automatic_managed_vendor,- default: nil,- format: :string,- allowed: -> { OpenProject::SCM::Manager.registered.keys.map(&:to_s) }-- # encodings used to convert repository files content to UTF-8- # multiple values accepted, comma separated- add :repositories_encodings,- default: nil,- format: :string-- add :repository_authentication_caching_enabled,- default: true-- add :repository_checkout_data,- default: {- "git" => { "enabled" => 0 },- "subversion" => { "enabled" => 0 }- }-- add :repository_log_display_limit,- default: 100-- add :repository_storage_cache_minutes,- default: 720-- add :repository_truncate_at,- default: 500-- add :rest_api_enabled,- default: true-- add :scm,- format: :hash,- default: {},- writable: false-- add :scm_git_command,- format: :string,- default: nil,- writable: false-- add :scm_local_checkout_path,- default: 'repositories', # relative to OpenProject directory- writable: false-- add :scm_subversion_command,- format: :string,- default: nil,- writable: false-- # Display update / security badge, enabled by default- add :security_badge_displayed,- default: true-- add :security_badge_url,- description: 'URL of the update check badge',- default: "https://releases.openproject.com/v1/check.svg",- writable: false-- add :self_registration,- default: 2-- add :sendmail_arguments,- description: 'Arguments to call sendmail with in case it is configured as outgoing email setup',- format: :string,- default: "-i",- writable: false-- add :sendmail_location,- description: 'Location of sendmail to call if it is configured as outgoing email setup',- format: :string,- default: "/usr/sbin/sendmail"-- # Allow separate error reporting for frontend errors- add :appsignal_frontend_key,- format: :string,- default: nil,- description: 'Appsignal API key for JavaScript error reporting',- writable: false-- add :session_cookie_name,- description: 'Set session cookie name',- default: '_open_project_session',- writable: false-- add :session_store,- description: 'Where to store session data',- default: :active_record_store,- writable: false-- add :session_ttl_enabled,- default: false-- add :session_ttl,- default: 120-- add :show_community_links,- description: 'Enable or disable links to OpenProject community instances',- default: true,- writable: false-- add :show_pending_migrations_warning,- description: 'Enable or disable warning bar in case of pending migrations',- default: true,- writable: false-- add :show_setting_mismatch_warning,- description: 'Show mismatched protocol/hostname warning. In cases where they must differ this can be disabled',- default: true,- writable: false-- # Render storage information- add :show_storage_information,- description: 'Show available and taken storage information under administration / info',- default: true,- writable: false-- add :show_warning_bars,- description: 'Render warning bars (pending migrations, deprecation, unsupported browsers)',- default: true,- writable: false-- add :smtp_authentication,- format: :string,- default: 'plain',- env_alias: 'SMTP_AUTHENTICATION'-- add :smtp_enable_starttls_auto,- format: :boolean,- default: false,- env_alias: 'SMTP_ENABLE_STARTTLS_AUTO'-- add :smtp_openssl_verify_mode,- description: 'Globally set verify mode for OpenSSL. Careful: Setting to none will disable any SSL verification!',- format: :string,- default: "peer",- allowed: %w[none peer client_once fail_if_no_peer_cert],- writable: false-- add :smtp_ssl,- format: :boolean,- default: false,- env_alias: 'SMTP_SSL'-- add :smtp_address,- format: :string,- default: '',- env_alias: 'SMTP_ADDRESS'-- add :smtp_domain,- format: :string,- default: 'your.domain.com',- env_alias: 'SMTP_DOMAIN'-- add :smtp_user_name,- format: :string,- default: '',- env_alias: 'SMTP_USER_NAME'-- add :smtp_port,- format: :integer,- default: 587,- env_alias: 'SMTP_PORT'-- add :smtp_password,- format: :string,- default: '',- env_alias: 'SMTP_PASSWORD'-- add :software_name,- description: 'Override software application name',- default: 'OpenProject'-- add :software_url,- description: 'Override software application URL',- default: 'https://www.openproject.org/'-- add :sql_slow_query_threshold,- description: 'Time limit in ms after which queries will be logged as slow queries',- default: 2000,- writable: false-- add :start_of_week,- default: nil,- format: :integer,- allowed: [1, 6, 7]-- add :statsd,- description: 'enable statsd metrics (currently puma only) by configuring host',- default: {- 'host' => nil,- 'port' => 8125- },- writable: false-- add :sys_api_enabled,- description: 'Enable internal system API for setting up managed repositories',- default: false-- add :sys_api_key,- description: 'Internal system API key for setting up managed repositories',- default: nil,- format: :string-- add :time_format,- format: :string,- default: nil,- allowed: [- '%H:%M',- '%I:%M %p'- ].freeze-- add :user_default_timezone,- default: nil,- format: :string,- allowed: ActiveSupport::TimeZone.all.map { |tz| tz.tzinfo.canonical_identifier }.sort.uniq + [nil]-- add :users_deletable_by_admins,- default: false-- add :users_deletable_by_self,- default: false-- add :user_format,- default: :firstname_lastname,- allowed: -> { User::USER_FORMATS_STRUCTURE.keys }-- add :web,- description: 'Web worker count and threads configuration',- default: {- 'workers' => 2,- 'timeout' => 120,- 'wait_timeout' => 10,- 'min_threads' => 4,- 'max_threads' => 16- },- writable: false-- add :welcome_text,- format: :string,- default: nil-- add :welcome_title,- format: :string,- default: nil-- add :welcome_on_homescreen,- default: false-- add :work_package_done_ratio,- default: 'field',- allowed: %w[field status disabled]-- add :work_packages_projects_export_limit,- default: 500-- add :work_package_list_default_highlighted_attributes,- default: [],- allowed: -> {- Query.available_columns(nil).select(&:highlightable).map(&:name).map(&:to_s)- }-- add :work_package_list_default_highlighting_mode,- format: :string,- default: -> { EnterpriseToken.allows_to?(:conditional_highlighting) ? 'inline' : 'none' },- allowed: -> { Query::QUERY_HIGHLIGHTING_MODES },- writable: -> { EnterpriseToken.allows_to?(:conditional_highlighting) }-- add :work_package_list_default_columns,- default: %w[id subject type status assigned_to priority],- allowed: -> { Query.new.displayable_columns.map(&:name).map(&:to_s) }-- add :work_package_startdate_is_adddate,- default: false-- add :working_days,- description: 'Set working days of the week (Array of 1 to 7, where 1=Monday, 7=Sunday)',- format: :array,- allowed: Array(1..7),- default: Array(1..5) # Sat, Sun being non-working days-- add :youtube_channel,- description: 'Link to YouTube channel in help menu',- default: 'https://www.youtube.com/c/OpenProjectCommunity',- writable: false-enddiff --git a/db/migrate/20190618115620_fix_available_languages.rb b/db/migrate/20190618115620_fix_available_languages.rbindex aad7954ebeb..e0a15cfb2b1 100644--- a/db/migrate/20190618115620_fix_available_languages.rb+++ b/db/migrate/20190618115620_fix_available_languages.rb@@ -1,6 +1,6 @@class FixAvailableLanguages < ActiveRecord::Migration[5.2]def up- if Setting.exists?(name: 'available_languages')+ if Setting.where(name: 'available_languages').exists?Setting.reset_column_informationSetting.available_languages = Setting.available_languages.map do |lang|@@ -16,7 +16,7 @@ class FixAvailableLanguages < ActiveRecord::Migration[5.2]enddef down- if Setting.exists?(name: 'available_languages')+ if Setting.where(name: 'available_languages').exists?Setting.reset_column_informationSetting.available_languages = Setting.available_languages.map do |lang|diff --git a/db/migrate/20200903064009_enable_current_project_custom_fields_columns.rb b/db/migrate/20200903064009_enable_current_project_custom_fields_columns.rbindex a2e32f52895..1f07c8a30fa 100644--- a/db/migrate/20200903064009_enable_current_project_custom_fields_columns.rb+++ b/db/migrate/20200903064009_enable_current_project_custom_fields_columns.rb@@ -1,6 +1,6 @@class EnableCurrentProjectCustomFieldsColumns < ActiveRecord::Migration[6.0]def up- return unless Setting.exists?(name: 'enabled_projects_column')+ return unless Setting.where(name: 'enabled_projects_column').exists?columns = Setting.enabled_projects_columnscf_columns = ProjectCustomField.pluck(:id).map { |id| "cf_#{id}" }diff --git a/db/migrate/20211103120946_clean_emails_footer.rb b/db/migrate/20211103120946_clean_emails_footer.rbindex 805463946b3..64f4d349b57 100644--- a/db/migrate/20211103120946_clean_emails_footer.rb+++ b/db/migrate/20211103120946_clean_emails_footer.rb@@ -1,6 +1,6 @@class CleanEmailsFooter < ActiveRecord::Migration[6.1]def up- return unless Setting.exists?(name: 'emails_footer')+ return unless Setting.where(name: 'emails_footer').exists?Setting.reset_column_informationfiltered_footer = Settingdiff --git a/db/migrate/20220811061024_rename_work_package_export_limit.rb b/db/migrate/20220811061024_rename_work_package_export_limit.rbindex 4a122ce1065..c7d627388be 100644--- a/db/migrate/20220811061024_rename_work_package_export_limit.rb+++ b/db/migrate/20220811061024_rename_work_package_export_limit.rb@@ -1,6 +1,6 @@class RenameWorkPackageExportLimit < ActiveRecord::Migration[7.0]def up- if Setting.exists?(name: 'work_packages_projects_export_limit')+ if Setting.where(name: 'work_packages_projects_export_limit').exists?Setting.where(name: 'work_packages_export_limit').delete_alldiff --git a/lib/tasks/setting.rake b/lib/tasks/setting.rakeindex f59f962da51..3701200682a 100644--- a/lib/tasks/setting.rake+++ b/lib/tasks/setting.rake@@ -61,7 +61,7 @@ namespace :setting dodesc 'List the supported environment variables to override settings'task available_envs: :environment do- Settings::Definition.all.sort_by(&:name).each do |definition|+ Settings::Definition.all.sort.each do |_name, definition|puts "#{Settings::Definition.possible_env_names(definition).first}" \" (default=#{definition.default.inspect}) #{definition.description}"enddiff --git a/lib_static/open_project/configuration.rb b/lib_static/open_project/configuration.rbindex 219038da47a..10f091e8222 100644--- a/lib_static/open_project/configuration.rb+++ b/lib_static/open_project/configuration.rb@@ -115,14 +115,6 @@ module OpenProjectTRUE_VALUES.include? self[definition.name]endend-- # Filters a hash with String keys by a key prefix and removes the prefix from the keys- def settings_of_prefix(prefix)- Settings::Definition- .all_of_prefix(prefix)- .to_h { |setting| [setting.name.delete_prefix(prefix), setting.value] }- .symbolize_keys!- endendendenddiff --git a/spec/constants/settings/definition_spec.rb b/spec/constants/settings/definition_spec.rbindex d527069eca5..1306d83104b 100644--- a/spec/constants/settings/definition_spec.rb+++ b/spec/constants/settings/definition_spec.rb@@ -28,187 +28,171 @@require 'spec_helper'-describe Settings::Definition do+describe Settings::Definition, :settings_reset dodescribe '.all' dosubject(:all) { described_class.all }- it "is a list of setting definitions" do- expect(all)- .to(be_all { |d| d.is_a?(described_class) })+ it "is a hash map of setting definitions" do+ expect(all.class).to eq(Hash)+ expect(all.values).to(be_all { |d| d.is_a?(described_class) })endit 'contains a definition from settings' do- expect(all)- .to(be_any { |d| d.name == 'smtp_address' })+ expect(all[:smtp_address]).to be_presentendit 'contains a definition from configuration' do- expect(all)- .to(be_any { |d| d.name == 'edition' })+ expect(all[:edition]).to be_presentendit 'contains a definition from settings.yml' do- expect(all)- .to(be_any { |d| d.name == 'sendmail_location' })+ expect(all[:sendmail_location]).to be_presentendit 'casts the value from settings.yml' do- expect(all.detect { |d| d.name == 'brute_force_block_after_failed_logins' }.value)- .to eq 20+ expect(all[:brute_force_block_after_failed_logins].value).to eq(20)end- context 'when overriding from ENV', :settings_reset do- def value_for(name)- all.detect { |d| d.name == name }.value- end-+ context 'when overriding from ENV' doit 'allows overriding configuration from ENV with OPENPROJECT_ prefix with double underscore case (legacy)' dostub_const('ENV',{'OPENPROJECT_EDITION' => 'bim','OPENPROJECT_DEFAULT__LANGUAGE' => 'de'})+ reset(:edition)+ reset(:default_language)- expect(value_for('edition')).to eql 'bim'- expect(value_for('default_language')).to eql 'de'+ expect(all[:edition].value).to eql 'bim'+ expect(all[:default_language].value).to eql 'de'endit 'allows overriding configuration from ENV with OPENPROJECT_ prefix with single underscore case' dostub_const('ENV', { 'OPENPROJECT_DEFAULT_LANGUAGE' => 'de' })-- expect(value_for('default_language')).to eql 'de'+ reset(:default_language)+ expect(all[:default_language].value).to eql 'de'endit 'allows overriding configuration from ENV without OPENPROJECT_ prefix' do- stub_const('ENV',- {- 'EDITION' => 'bim'- })-- expect(value_for('edition')).to eql 'bim'+ stub_const('ENV', { 'EDITION' => 'bim' })+ reset(:edition)+ expect(all[:edition].value).to eql 'bim'endit 'does not allows overriding configuration from ENV without OPENPROJECT_ prefix if setting is writable' do- stub_const('ENV',- {- 'DEFAULT_LANGUAGE' => 'de'- })-- expect(value_for('default_language')).to eql 'en'+ stub_const('ENV', { 'DEFAULT_LANGUAGE' => 'de' })+ reset(:default_language)+ expect(all[:default_language].value).to eql 'en'endit 'allows overriding email/smtp configuration from ENV without OPENPROJECT_ prefix even though setting is writable' do- stub_const('ENV',- {- 'EMAIL_DELIVERY_CONFIGURATION' => 'legacy',- 'EMAIL_DELIVERY_METHOD' => 'smtp',- 'SMTP_ADDRESS' => 'smtp.somedomain.org',- 'SMTP_AUTHENTICATION' => 'something',- 'SMTP_DOMAIN' => 'email.bogus.abc',- 'SMTP_ENABLE_STARTTLS_AUTO' => 'true',- 'SMTP_PASSWORD' => 'password',- 'SMTP_PORT' => '987',- 'SMTP_USER_NAME' => 'user',- 'SMTP_SSL' => 'true'- })+ env_vars = {+ 'EMAIL_DELIVERY_CONFIGURATION' => 'legacy',+ 'EMAIL_DELIVERY_METHOD' => 'smtp',+ 'SMTP_ADDRESS' => 'smtp.somedomain.org',+ 'SMTP_AUTHENTICATION' => 'something',+ 'SMTP_DOMAIN' => 'email.bogus.abc',+ 'SMTP_ENABLE_STARTTLS_AUTO' => 'true',+ 'SMTP_PASSWORD' => 'password',+ 'SMTP_PORT' => '987',+ 'SMTP_USER_NAME' => 'user',+ 'SMTP_SSL' => 'true'+ }+ stub_const('ENV', env_vars)++ env_vars.each_key do |env_var|+ reset(env_var.downcase.to_sym)+ end- expect(value_for('email_delivery_configuration')).to eql 'legacy'- expect(value_for('email_delivery_method')).to eq :smtp- expect(value_for('smtp_address')).to eql 'smtp.somedomain.org'- expect(value_for('smtp_authentication')).to eql 'something'- expect(value_for('smtp_domain')).to eql 'email.bogus.abc'- expect(value_for('smtp_enable_starttls_auto')).to be true- expect(value_for('smtp_password')).to eql 'password'- expect(value_for('smtp_port')).to eq 987- expect(value_for('smtp_user_name')).to eq 'user'- expect(value_for('smtp_ssl')).to be true+ expect(all[:email_delivery_configuration].value).to eql 'legacy'+ expect(all[:email_delivery_method].value).to eq :smtp+ expect(all[:smtp_address].value).to eql 'smtp.somedomain.org'+ expect(all[:smtp_authentication].value).to eql 'something'+ expect(all[:smtp_domain].value).to eql 'email.bogus.abc'+ expect(all[:smtp_enable_starttls_auto].value).to be true+ expect(all[:smtp_password].value).to eql 'password'+ expect(all[:smtp_port].value).to eq 987+ expect(all[:smtp_user_name].value).to eq 'user'+ expect(all[:smtp_ssl].value).to be trueendit 'logs a deprecation warning when overriding configuration from ENV without OPENPROJECT_ prefix' doallow(Rails.logger).to receive(:warn)stub_const('ENV', { 'EDITION' => 'bim' })- expect(value_for('edition')).to eql 'bim'- expect(Rails.logger)- .to have_received(:warn)- .with(a_string_including("use OPENPROJECT_EDITION instead of EDITION"))+ reset(:edition)++ expect(all[:edition].value).to eql 'bim'+ expect(Rails.logger).to have_received(:warn)+ .with(a_string_including("use OPENPROJECT_EDITION instead of EDITION"))endit 'overriding boolean configuration from ENV will cast the value' dostub_const('ENV', { 'OPENPROJECT_REST__API__ENABLED' => '0' })-- expect(all.detect { |d| d.name == 'rest_api_enabled' }.value)- .to be false+ reset(:rest_api_enabled)+ expect(all[:rest_api_enabled].value).to be falseendit 'overriding datetime configuration from ENV will cast the value' dostub_const('ENV', { 'OPENPROJECT_CONSENT__TIME' => '2222-01-01' })-- expect(all.detect { |d| d.name == 'consent_time' }.value)- .to eql DateTime.parse('2222-01-01')+ reset(:consent_time)+ expect(all[:consent_time].value).to eql DateTime.parse('2222-01-01')endit 'overriding timezone configuration from ENV will cast the value' dostub_const('ENV', { 'OPENPROJECT_USER__DEFAULT__TIMEZONE' => 'Europe/Berlin' })-- expect(value_for('user_default_timezone')).to eq 'Europe/Berlin'+ reset(:user_default_timezone)+ expect(all[:user_default_timezone].value).to eq 'Europe/Berlin'endit 'overriding timezone configuration from ENV with a bogus value' dostub_const('ENV', { 'OPENPROJECT_USER__DEFAULT__TIMEZONE' => 'foobar' })-- expect { value_for('user_default_timezone') }.to raise_error(ArgumentError)+ expect { reset(:user_default_timezone) }.to raise_error(ArgumentError)endit 'overriding configuration from ENV will set it to non writable' dostub_const('ENV', { 'OPENPROJECT_EDITION' => 'bim' })-- expect(all.detect { |d| d.name == 'edition' })- .not_to be_writable+ reset(:edition)+ expect(all[:edition]).not_to be_writableendit 'allows overriding settings array from ENV' dostub_const('ENV', { 'OPENPROJECT_PASSWORD__ACTIVE__RULES' => YAML.dump(['lowercase']) })-- expect(all.detect { |d| d.name == 'password_active_rules' }.value)- .to eql ['lowercase']+ reset(:password_active_rules)+ expect(all[:password_active_rules].value).to eql ['lowercase']endit 'overriding settings from ENV will set it to non writable' dostub_const('ENV', { 'OPENPROJECT_WELCOME__TITLE' => 'Some title' })-- expect(all.detect { |d| d.name == 'welcome_title' })- .not_to be_writable+ reset(:welcome_title)+ expect(all[:welcome_title]).not_to be_writableendit 'allows overriding settings hash partially from ENV' dostub_const('ENV', { 'OPENPROJECT_REPOSITORY__CHECKOUT__DATA_GIT_ENABLED' => '1' })-- expect(value_for('repository_checkout_data'))- .to eql({- 'git' => { 'enabled' => 1 },- 'subversion' => { 'enabled' => 0 }- })+ reset(:repository_checkout_data)+ expect(all[:repository_checkout_data].value).to eql({+ 'git' => { 'enabled' => 1 },+ 'subversion' => { 'enabled' => 0 }+ })endit 'allows overriding settings hash partially from ENV with single underscore name' dostub_const('ENV', { 'OPENPROJECT_REPOSITORY_CHECKOUT_DATA_GIT_ENABLED' => '1' })-- expect(value_for('repository_checkout_data'))- .to eql({- 'git' => { 'enabled' => 1 },- 'subversion' => { 'enabled' => 0 }- })+ reset(:repository_checkout_data)+ expect(all[:repository_checkout_data].value).to eql({+ 'git' => { 'enabled' => 1 },+ 'subversion' => { 'enabled' => 0 }+ })endit 'allows overriding settings hash partially from ENV with yaml data' dostub_const('ENV', { 'OPENPROJECT_REPOSITORY_CHECKOUT_DATA' => '{git: {enabled: 1}}' })-- expect(value_for('repository_checkout_data'))- .to eql({- 'git' => { 'enabled' => 1 },- 'subversion' => { 'enabled' => 0 }- })+ reset(:repository_checkout_data)+ expect(all[:repository_checkout_data].value).to eql({+ 'git' => { 'enabled' => 1 },+ 'subversion' => { 'enabled' => 0 }+ })endit 'allows overriding settings hash fully from repeated ENV values' do@@ -222,14 +206,13 @@ describe Settings::Definition do'OPENPROJECT_REPOSITORY_CHECKOUT_DATA_SUBVERSION_ENABLED' => '1'})-- expect(value_for('repository_checkout_data'))- .to eql({- 'cvs' => { 'enabled' => 0 },- 'git' => { 'enabled' => 1, 'minimum_version' => 42 },- 'hg' => { 'enabled' => 0 },- 'subversion' => { 'enabled' => 1 }- })+ reset(:repository_checkout_data)+ expect(all[:repository_checkout_data].value).to eql({+ 'cvs' => { 'enabled' => 0 },+ 'git' => { 'enabled' => 1, 'minimum_version' => 42 },+ 'hg' => { 'enabled' => 0 },+ 'subversion' => { 'enabled' => 1 }+ })endit 'allows overriding settings hash fully from ENV with yaml data' do@@ -239,13 +222,12 @@ describe Settings::Definition do'OPENPROJECT_REPOSITORY_CHECKOUT_DATA' => '{git: {enabled: 1, key: "42"}, cvs: {enabled: 0}}'})-- expect(all.detect { |d| d.name == 'repository_checkout_data' }.value)- .to eql({- 'git' => { 'enabled' => 1, 'key' => '42' },- 'cvs' => { 'enabled' => 0 },- 'subversion' => { 'enabled' => 0 }- })+ reset(:repository_checkout_data)+ expect(all[:repository_checkout_data].value).to eql({+ 'git' => { 'enabled' => 1, 'key' => '42' },+ 'cvs' => { 'enabled' => 0 },+ 'subversion' => { 'enabled' => 0 }+ })endit 'allows overriding settings hash fully from ENV with yaml data multiline' do@@ -262,13 +244,12 @@ describe Settings::Definition doYML})-- expect(all.detect { |d| d.name == 'repository_checkout_data' }.value)- .to eql({- 'git' => { 'enabled' => 1, 'key' => '42' },- 'cvs' => { 'enabled' => 0 },- 'subversion' => { 'enabled' => 0 }- })+ reset(:repository_checkout_data)+ expect(all[:repository_checkout_data].value).to eql({+ 'git' => { 'enabled' => 1, 'key' => '42' },+ 'cvs' => { 'enabled' => 0 },+ 'subversion' => { 'enabled' => 0 }+ })endit 'allows overriding settings hash fully from ENV with json data' do@@ -278,13 +259,12 @@ describe Settings::Definition do'OPENPROJECT_REPOSITORY_CHECKOUT_DATA' => '{"git": {"enabled": 1, "key": "42"}, "cvs": {"enabled": 0}}'})-- expect(all.detect { |d| d.name == 'repository_checkout_data' }.value)- .to eql({- 'git' => { 'enabled' => 1, 'key' => '42' },- 'cvs' => { 'enabled' => 0 },- 'subversion' => { 'enabled' => 0 }- })+ reset(:repository_checkout_data)+ expect(all[:repository_checkout_data].value).to eql({+ 'git' => { 'enabled' => 1, 'key' => '42' },+ 'cvs' => { 'enabled' => 0 },+ 'subversion' => { 'enabled' => 0 }+ })endit 'allows overriding configuration array from ENV with yaml/json data' do@@ -294,9 +274,8 @@ describe Settings::Definition do'OPENPROJECT_BLACKLISTED_ROUTES' => '["admin/info", "admin/plugins"]'})-- expect(value_for('blacklisted_routes'))- .to eq(['admin/info', 'admin/plugins'])+ reset(:blacklisted_routes)+ expect(all[:blacklisted_routes].value).to eq(['admin/info', 'admin/plugins'])endit 'allows overriding configuration array from ENV with space separated string' do@@ -307,6 +286,7 @@ describe Settings::Definition do})+ reset(:blacklisted_routes)# works for OpenProject::Configuration thanks to OpenProject::Configuration::Helper mixinexpect(OpenProject::Configuration.blacklisted_routes).to eq(['admin/info', 'admin/plugins'])@@ -316,14 +296,6 @@ describe Settings::Definition doendcontext 'with definitions from plugins' do- let(:definition_2fa) { definitions_before.find { _1.name == 'plugin_openproject_two_factor_authentication' }.dup }-- before do- # hack to have access to Setting.plugin_openproject_two_factor_authentication after- # having done- described_class.all << definition_2fa- end-it 'allows overriding settings hash partially from ENV with aliased env name' dostub_const('ENV',@@ -332,10 +304,10 @@ describe Settings::Definition do'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)+ # override from env manually because this settings are added by plugin intself+ described_class.send(:override_value, all[:plugin_openproject_two_factor_authentication])+ expect(all[:plugin_openproject_two_factor_authentication].value).to eq('active_strategies' => [:totp],+ 'enforced' => true, 'allow_remember_for_days' => 15)endit 'allows overriding settings hash from ENV with aliased env name' do@@ -345,34 +317,27 @@ describe Settings::Definition do'OPENPROJECT_2FA' => '{"enforced": true, "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'))+ # override from env manually because this settings are added by plugin intself+ described_class.send(:override_value, all[:plugin_openproject_two_factor_authentication])+ expect(all[:plugin_openproject_two_factor_authentication].value).to eq({ 'active_strategies' => [:totp], 'enforced' => true, 'allow_remember_for_days' => 15 })endendit 'will not handle ENV vars for which no definition exists' do- stub_const('ENV', { 'OPENPROJECT_BOGUS' => '1' })-- expect(all.detect { |d| d.name == 'bogus' })- .to be_nil+ stub_const('ENV', { 'OPENPROJECT_BOGUS' => '1234' })+ expect(all[:bogus]).to be_nilendit 'will handle ENV vars for definitions added after #all was called (e.g. in a module)' dostub_const('ENV', { 'OPENPROJECT_BOGUS' => '1' })-- all-- described_class.add 'bogus',- default: 0-- expect(all.detect { |d| d.name == 'bogus' }.value)- .to eq 1+ described_class.add(:bogus, default: 0)+ expect(all[:bogus].value).to eq 1endend- context 'when overriding from file', :settings_reset do- let(:file_contents) do+ context 'when overriding from file' do+ let(:configuration_yml) do<<~YAML---default:@@ -387,88 +352,70 @@ describe Settings::Definition doYAMLend- before do- allow(File)- .to receive(:file?)- .with(Rails.root.join('config/configuration.yml'))- .and_return(true)-- allow(File)- .to receive(:read)- .with(Rails.root.join('config/configuration.yml'))- .and_return(file_contents)-- # Loading of the config file is partially disabled in test env- allow(Rails.env)- .to receive(:test?)- .and_return(false)- end+ before { stub_configuration_yml }it 'overrides from file default' do- expect(all.detect { |d| d.name == 'edition' }.value)- .to eql 'bim'+ reset(:edition)+ expect(all[:edition].value).to eql 'bim'endit 'marks the value overwritten from file default unwritable' do- expect(all.detect { |d| d.name == 'edition' })- .not_to be_writable+ reset(:edition)+ expect(all[:edition]).not_to be_writableendit 'overrides from file default path but once again from current env' do- expect(all.detect { |d| d.name == 'sendmail_location' }.value)- .to eql 'test location'+ reset(:sendmail_location)+ expect(all[:sendmail_location].value).to eql 'test location'endit 'marks the value overwritten from file default and again from current unwritable' do- expect(all.detect { |d| d.name == 'sendmail_location' })- .not_to be_writable+ reset(:sendmail_location)+ expect(all[:sendmail_location]).not_to be_writableendit 'overrides from file current env' do- expect(all.detect { |d| d.name == 'smtp_address' }.value)- .to eql 'test address'+ reset(:smtp_address)+ expect(all[:smtp_address].value).to eql 'test address'endit 'marks the value overwritten from file current unwritable' do- expect(all.detect { |d| d.name == 'smtp_address' })- .not_to be_writable+ reset(:smtp_address)+ expect(all[:smtp_address]).not_to be_writableendit 'does not accept undefined settings' do- expect(all.detect { |d| d.name == 'bogus' })- .to be_nil+ expect(all[:bogus]).to be_nilendit 'correctly parses date objects' do- expect(all.detect { |d| d.name == 'consent_time' }.value)- .to eql DateTime.parse("2222-01-01")+ reset(:consent_time)+ expect(all[:consent_time].value).to eql DateTime.parse("2222-01-01")endit 'correctly overrides a default by a false value' do- expect(all.detect { |d| d.name == 'direct_uploads' }.value)- .to be false+ reset(:direct_uploads)+ expect(all[:direct_uploads].value).to be falseendcontext 'when Rails environment is test' dobefore do- allow(Rails.env)- .to receive(:test?)- .and_return(true)+ allow(Rails.env).to receive(:test?).and_return(true)endit 'does not override from file default' do- expect(all.detect { |d| d.name == 'edition' }.value)- .not_to eql 'bim'+ reset(:edition)+ expect(all[:edition].value).not_to eql 'bim'endit 'overrides from file current env' do- expect(all.detect { |d| d.name == 'smtp_address' }.value)- .to eql 'test address'+ reset(:smtp_address)+ expect(all[:smtp_address].value).to eql 'test address'endendcontext 'when having invalid values in the file' do- let(:file_contents) do+ let(:configuration_yml) do<<~YAML---default:@@ -477,8 +424,9 @@ describe Settings::Definition doendit 'is invalid' do- expect { all }- .to raise_error ArgumentError+ expect do+ reset(:smtp_openssl_verify_mode)+ end.to raise_error ArgumentErrorendend@@ -488,27 +436,21 @@ describe Settings::Definition doendit 'overrides from ENV' do- expect(all.detect { |d| d.name == 'sendmail_location' }.value)- .to eql 'env location'+ reset(:sendmail_location)+ expect(all[:sendmail_location].value).to eql 'env location'endit 'marks the overwritten value unwritable' do- expect(all.detect { |d| d.name == 'sendmail_location' })- .not_to be_writable+ reset(:sendmail_location)+ expect(all[:sendmail_location]).not_to be_writableendendend- context 'when adding an additional setting', :settings_reset do+ context 'when adding an additional setting' doit 'includes the setting' do- all-- described_class.add 'bogus',- default: 1,- format: :integer-- expect(all.detect { |d| d.name == 'bogus' }.value)- .to eq(1)+ described_class.add('bogus', default: 1, format: :integer)+ expect(all[:bogus].value).to eq(1)endendenddiff --git a/spec/seeders/setting_seeder_spec.rb b/spec/seeders/setting_seeder_spec.rbindex 05ff70ee229..2f739f777fc 100644--- a/spec/seeders/setting_seeder_spec.rb+++ b/spec/seeders/setting_seeder_spec.rb@@ -71,7 +71,7 @@ describe BasicData::SettingSeeder doendit 'does not seed settings whose default value is undefined' do- names_of_undefined_settings = Settings::Definition.all.select { _1.value == nil }.map(&:name)+ names_of_undefined_settings = Settings::Definition.all.values.select { _1.value == nil }.map(&:name)# these ones are special as their value is set based on database idsnames_of_undefined_settings -= ["new_project_user_role_id", "commit_fix_status_id"]expect(Setting.where(name: names_of_undefined_settings).pluck(:name)).to be_emptydiff --git a/spec/support/shared/with_settings.rb b/spec/support/shared/with_settings.rbindex 4fb49773b8c..1e03a39096f 100644--- a/spec/support/shared/with_settings.rb+++ b/spec/support/shared/with_settings.rb@@ -41,13 +41,34 @@ endRSpec.shared_context 'with settings reset' dolet!(:definitions_before) { Settings::Definition.all.dup }+ def reset(setting)+ Settings::Definition.all.delete(setting)+ Settings::Definition.add(setting, **Settings::Definition::DEFINITIONS[setting])+ end++ def stub_configuration_yml+ # disable test env detection because loading of the config file is partially disabled in test env+ allow(Rails.env).to receive(:test?).and_return(false)+ allow(File)+ .to receive(:file?)+ .with(Rails.root.join('config/configuration.yml'))+ .and_return(true)++ # It is added to avoid warning about other File.read calls.+ allow(File).to receive(:read).and_call_original+ allow(File)+ .to receive(:read)+ .with(Rails.root.join('config/configuration.yml'))+ .and_return(configuration_yml)+ end+before do- Settings::Definition.send(:reset)+ Settings::Definition.instance_variable_set(:@file_config, nil)endafter do- Settings::Definition.send(:reset)Settings::Definition.instance_variable_set(:@all, definitions_before)+ Settings::Definition.instance_variable_set(:@file_config, nil)endenddiff --git a/spec/tasks/setting_spec.rb b/spec/tasks/setting_spec.rbindex 0076ff1e9d8..699a2480201 100644--- a/spec/tasks/setting_spec.rb+++ b/spec/tasks/setting_spec.rb@@ -28,8 +28,16 @@require 'spec_helper'-RSpec.describe Rake::Task, 'setting', :settings_reset do+RSpec.describe Rake::Task, :settings_reset dodescribe 'setting:set' do+ let(:configuration_yml) do+ <<~YAML+ ---+ default:+ email_delivery_method: 'initial_file_value'+ YAML+ end+include_context 'rake' dolet(:task_name) { 'setting:set' }end@@ -43,11 +51,8 @@ RSpec.describe Rake::Task, 'setting', :settings_reset docontext 'if setting is overridden from config/configuration.yml file' dobefore do- # disable test env detection because loading of the config file is partially disabled in test env- allow(Rails.env).to receive(:test?).and_return(false)- allow(Settings::Definition).to receive(:file_config)- .and_return('default' => { 'email_delivery_method' => 'initial_file_value' })- Settings::Definition.send(:override_value_from_file, Settings::Definition['email_delivery_method'])+ stub_configuration_yml+ reset(:email_delivery_method)endit 'saves the setting in database' do@@ -79,25 +84,22 @@ RSpec.describe Rake::Task, 'setting', :settings_reset docontext 'if setting is overridden from config/configuration.yml file' dobefore do- # disable test env detection because loading of the config file is partially disabled in test env- allow(Rails.env).to receive(:test?).and_return(false)- allow(Settings::Definition).to receive(:file_config)- .and_return('default' => { 'email_delivery_method' => 'initial_file_value' })- Settings::Definition.send(:override_value_from_file, Settings::Definition['email_delivery_method'])+ stub_configuration_yml+ reset(:email_delivery_method)endit 'updates the setting in database' doexpect { subject.invoke('email_delivery_method=something') }.to change { Setting.find_by(name: 'email_delivery_method')&.value }- .from(:initial_db_value)- .to(:something)+ .from(:initial_db_value)+ .to(:something)endit 'keeps using the value from the file' doexpect(Setting.email_delivery_method).to eq(:initial_file_value)expect { subject.invoke('email_delivery_method=something') }.not_to change(Setting, :email_delivery_method)- .from(:initial_file_value)+ .from(:initial_file_value)endendend