Skip to content

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

Disable writing of ENV enforced settings

Oliver Günther06b885717c4d
diff --git a/modules/two_factor_authentication/app/controllers/two_factor_authentication/two_factor_settings_controller.rb b/modules/two_factor_authentication/app/controllers/two_factor_authentication/two_factor_settings_controller.rb
index f92c098a2d7..f15550a793a 100644
--- a/modules/two_factor_authentication/app/controllers/two_factor_authentication/two_factor_settings_controller.rb
+++ b/modules/two_factor_authentication/app/controllers/two_factor_authentication/two_factor_settings_controller.rb
@@ -3,6 +3,7 @@ module ::TwoFactorAuthentication
include EnterpriseTrialHelper
before_action :require_admin
before_action :check_enabled
+ before_action :check_writable, only: :update
layout "admin"
menu_item :two_factor_authentication
@@ -33,6 +34,12 @@ module ::TwoFactorAuthentication
private
+ def check_writable
+ unless Setting.plugin_openproject_two_factor_authentication_writable?
+ render_403 message: I18n.t("two_factor_authentication.notice_not_writable")
+ end
+ end
+
def permitted_params
params.require(:settings).permit(:enforced, :allow_remember_for_days)
end
diff --git a/modules/two_factor_authentication/app/views/two_factor_authentication/settings.html.erb b/modules/two_factor_authentication/app/views/two_factor_authentication/settings.html.erb
index 8c757951f4a..21db5b4a3cc 100644
--- a/modules/two_factor_authentication/app/views/two_factor_authentication/settings.html.erb
+++ b/modules/two_factor_authentication/app/views/two_factor_authentication/settings.html.erb
@@ -25,59 +25,62 @@
target: '_blank' %>
</p>
<%= render(AttributeGroups::AttributeGroupComponent.new) do |component|
- component.with_attribute(key: t('two_factor_authentication.settings.label_active_strategies'),
- value: if configuration['active_strategies'].empty?
- t(:label_none)
- else
- strategies = configuration['active_strategies'].map do |key|
- content_tag(:span) do
- t("two_factor_authentication.strategies.#{key}")
- end
- end
- safe_join(strategies, tag(:br))
- end)
+ if configuration['active_strategies'].empty?
+ component.with_attribute(key: t('two_factor_authentication.settings.label_active_strategies'),
+ value: t(:label_none))
+ else
+ strategies = configuration['active_strategies'].map do |key|
+ content_tag(:span) do
+ t("two_factor_authentication.strategies.#{key}")
+ end
+ end
+ component.with_attribute(key: t('two_factor_authentication.settings.label_active_strategies'),
+ value: safe_join(strategies, tag(:br)))
+ end
component.with_attribute(key: t('two_factor_authentication.settings.label_enforced'),
value: !!configuration['enforced'])
component.with_attribute(key: t('two_factor_authentication.settings.label_remember'),
value: if configuration['allow_remember_for_days'].to_i == 0
- t(:label_disabled)
- else
- "#{configuration['allow_remember_for_days']} (#{t(:label_day_plural)})"
- end)
+ t(:label_disabled)
+ else
+ "#{configuration['allow_remember_for_days']} (#{t(:label_day_plural)})"
+ end)
end %>
</fieldset>
- <fieldset class="form--fieldset">
- <legend class="form--fieldset-legend"><%= t(:label_setting_plural) %></legend>
- <div class="form--field">
- <label class="form--label" for='settings[enforced]'><%= t('two_factor_authentication.settings.label_enforced') %></label>
- <div class="form--field-container ">
- <%= styled_check_box_tag 'settings[enforced]',
- '1',
- !!configuration['enforced'],
- disabled: strategy_manager.enforced_by_configuration? || configuration['active_strategies'].empty?,
- container_class: '-middle' %>
- </div>
- <div class="form--field-instructions">
- <%= I18n.t('two_factor_authentication.settings.text_enforced') %>
+ <% if Setting.plugin_openproject_two_factor_authentication_writable? %>
+ <fieldset class="form--fieldset">
+ <legend class="form--fieldset-legend"><%= t(:label_setting_plural) %></legend>
+ <div class="form--field">
+ <label class="form--label" for='settings[enforced]'><%= t('two_factor_authentication.settings.label_enforced') %></label>
+ <div class="form--field-container ">
+ <%= styled_check_box_tag 'settings[enforced]',
+ '1',
+ !!configuration['enforced'],
+ disabled: strategy_manager.enforced_by_configuration? || configuration['active_strategies'].empty?,
+ container_class: '-middle' %>
+ </div>
+ <div class="form--field-instructions">
+ <%= I18n.t('two_factor_authentication.settings.text_enforced') %>
+ </div>
</div>
- </div>
- <div class="form--field">
- <label class="form--label" for='settings[allow_remember_for_days]'><%= t('two_factor_authentication.settings.label_remember') %></label>
- <div class="form--field-container">
- <%= styled_number_field_tag 'settings[allow_remember_for_days]',
- configuration['allow_remember_for_days'],
- min: '0',
- max: '365',
- step: '1',
- container_class: '-middle' %>
+ <div class="form--field">
+ <label class="form--label" for='settings[allow_remember_for_days]'><%= t('two_factor_authentication.settings.label_remember') %></label>
+ <div class="form--field-container">
+ <%= styled_number_field_tag 'settings[allow_remember_for_days]',
+ configuration['allow_remember_for_days'],
+ min: '0',
+ max: '365',
+ step: '1',
+ container_class: '-middle' %>
+ </div>
+ <div class="form--field-instructions">
+ <%= I18n.t('two_factor_authentication.settings.text_remember') %>
+ </div>
</div>
- <div class="form--field-instructions">
- <%= I18n.t('two_factor_authentication.settings.text_remember') %>
- </div>
- </div>
- </fieldset>
- <%= styled_submit_tag t(:button_apply), class: '-primary' %>
+ </fieldset>
+ <%= styled_submit_tag t(:button_apply), class: '-primary' %>
+ <% end %>
+ </section>
<% end %>
-</section>
diff --git a/modules/two_factor_authentication/config/locales/en.yml b/modules/two_factor_authentication/config/locales/en.yml
index f1874d48fc7..717f3cdde2a 100644
--- a/modules/two_factor_authentication/config/locales/en.yml
+++ b/modules/two_factor_authentication/config/locales/en.yml
@@ -30,6 +30,7 @@ en:
two_factor_authentication:
error_2fa_disabled: "2FA delivery has been disabled."
+ notice_not_writable: "2FA Settings were provided through environment variables and cannot be overwritten."
error_no_device: "No registered 2FA device found for this user, despite being required for this instance."
error_no_matching_strategy: "No matching 2FA strategy available for this user. Please contact your administratior."
error_is_enforced_not_active: "Configuration error: Two-factor authentication has been enforced, but no active strategies exist."