commit
19ed50a6da
@ -0,0 +1,55 @@ |
|||||||
|
module ::TwoFactorAuthentication |
||||||
|
class SettingsController < ApplicationController |
||||||
|
|
||||||
|
before_action :require_admin |
||||||
|
before_action :check_enabled |
||||||
|
|
||||||
|
layout 'admin' |
||||||
|
menu_item :two_factor_authentication |
||||||
|
|
||||||
|
def show |
||||||
|
render template: 'two_factor_authentication/settings', |
||||||
|
locals: { |
||||||
|
settings: Setting.plugin_openproject_two_factor_authentication, |
||||||
|
strategy_manager: manager, |
||||||
|
configuration: manager.configuration |
||||||
|
} |
||||||
|
end |
||||||
|
|
||||||
|
def update |
||||||
|
current_settings = Setting.plugin_openproject_two_factor_authentication |
||||||
|
begin |
||||||
|
merge_settings!(current_settings, permitted_params) |
||||||
|
manager.validate_configuration! |
||||||
|
flash[:notice] = I18n.t(:notice_successful_update) |
||||||
|
rescue ArgumentError => e |
||||||
|
Setting.plugin_openproject_two_factor_authentication = current_settings |
||||||
|
flash[:error] = I18n.t('two_factor_authentication.settings.failed_to_save_settings', message: e.message) |
||||||
|
Rails.logger.error "Failed to save 2FA settings: #{e.message}" |
||||||
|
end |
||||||
|
|
||||||
|
redirect_to action: :show |
||||||
|
end |
||||||
|
|
||||||
|
private |
||||||
|
|
||||||
|
def permitted_params |
||||||
|
params.require(:settings).permit(:enforced, :allow_remember_for_days) |
||||||
|
end |
||||||
|
|
||||||
|
def merge_settings!(current, permitted) |
||||||
|
Setting.plugin_openproject_two_factor_authentication = current.merge( |
||||||
|
enforced: !!permitted[:enforced], |
||||||
|
allow_remember_for_days: permitted[:allow_remember_for_days] |
||||||
|
) |
||||||
|
end |
||||||
|
|
||||||
|
def check_enabled |
||||||
|
render_403 unless manager.configurable_by_ui? |
||||||
|
end |
||||||
|
|
||||||
|
def manager |
||||||
|
::OpenProject::TwoFactorAuthentication::TokenStrategyManager |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,80 @@ |
|||||||
|
<% html_title(t(:label_administration), t('two_factor_authentication.settings.title')) -%> |
||||||
|
|
||||||
|
<%= breadcrumb_toolbar(t('two_factor_authentication.settings.title')) %> |
||||||
|
<section class="admin--edit-section"> |
||||||
|
<%= styled_form_tag({ action: :update }, |
||||||
|
method: :post, |
||||||
|
id: 'update-ldap-group-settings-form') do %> |
||||||
|
<fieldset class="form--fieldset"> |
||||||
|
<legend class="form--fieldset-legend"><%= t('two_factor_authentication.settings.current_configuration') %></legend> |
||||||
|
<p> |
||||||
|
<%= t('two_factor_authentication.settings.text_configuration') %> |
||||||
|
<br/> |
||||||
|
<% configuration_link = OpenProject::Static::Links.links.fetch :configuration_guide %> |
||||||
|
<%= link_to t('two_factor_authentication.settings.text_configuration_guide'), configuration_link[:href] %> |
||||||
|
</p> |
||||||
|
<div class="attributes-key-value"> |
||||||
|
<div class="attributes-key-value--key"><%= t('two_factor_authentication.settings.label_active_strategies') %></div> |
||||||
|
<div class="attributes-key-value--value-container"> |
||||||
|
<div class="attributes-key-value--value"> |
||||||
|
<%= t(:label_none) if configuration[:active_strategies].empty? %> |
||||||
|
<% configuration[:active_strategies].each do |key| %> |
||||||
|
<span> |
||||||
|
<%= t("two_factor_authentication.strategies.#{key}") %> |
||||||
|
</span> |
||||||
|
<br/> |
||||||
|
<% end %> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<div class="attributes-key-value--key"><%= t('two_factor_authentication.settings.label_enforced') %></div> |
||||||
|
<div class="attributes-key-value--value-container"> |
||||||
|
<div class="attributes-key-value--value"> |
||||||
|
<span><%= !!configuration[:enforced] %></span> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<div class="attributes-key-value--key"><%= t('two_factor_authentication.settings.label_remember') %></div> |
||||||
|
<div class="attributes-key-value--value-container"> |
||||||
|
<div class="attributes-key-value--value"> |
||||||
|
<% if configuration[:allow_remember_for_days].to_i == 0 %> |
||||||
|
<span><%= t(:label_disabled) %></span> |
||||||
|
<% else %> |
||||||
|
<span><%= configuration[:allow_remember_for_days] %> (<%= t(:label_day_plural) %>)</span> |
||||||
|
<% end %> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</fieldset> |
||||||
|
<fieldset class="form--fieldset"> |
||||||
|
<legend class="form--fieldset-legend"><%= t(:label_settings) %></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?(:enforced) || configuration[:active_strategies].empty?, |
||||||
|
container_class: '-middle' %> |
||||||
|
</div> |
||||||
|
<div class="form--field-instructions"> |
||||||
|
<%= I18n.t('two_factor_authentication.settings.text_enforced') %> |
||||||
|
</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', |
||||||
|
disabled: strategy_manager.enforced_by_configuration?(:allow_remember_for_days), |
||||||
|
container_class: '-middle' %> |
||||||
|
</div> |
||||||
|
<div class="form--field-instructions"> |
||||||
|
<%= I18n.t('two_factor_authentication.settings.text_remember') %> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</fieldset> |
||||||
|
<%= styled_submit_tag l(:button_apply), class: '-highlight' %> |
||||||
|
<% end %> |
||||||
|
</section> |
@ -0,0 +1,30 @@ |
|||||||
|
<% html_title(t(:label_administration), t('two_factor_authentication.settings.title')) -%> |
||||||
|
|
||||||
|
<%= breadcrumb_toolbar(t('two_factor_authentication.settings.title')) %> |
||||||
|
<div class="notification-box upsale-notification"> |
||||||
|
<div class="notification-box--content"> |
||||||
|
<h3><%= t('admin.enterprise.upgrade_to_ee') %></h3> |
||||||
|
<%= image_tag "enterprise_edition.png", class: "widget-box--teaser-image" %> |
||||||
|
|
||||||
|
<p><%= t('homescreen.blocks.upsale.description') %></p> |
||||||
|
|
||||||
|
<ul class=""> |
||||||
|
<li> |
||||||
|
<%= t('homescreen.blocks.upsale.additional_features') %> |
||||||
|
</li> |
||||||
|
<li> |
||||||
|
<%= t('homescreen.blocks.upsale.professional_support') %> |
||||||
|
</li> |
||||||
|
</ul> |
||||||
|
<p> |
||||||
|
<b><%= t('homescreen.blocks.upsale.become_hero') %></b> <%= t('homescreen.blocks.upsale.you_contribute') %> |
||||||
|
</p> |
||||||
|
<%= link_to( "#{OpenProject::Static::Links.links[:upsale][:href]}/?utm_source=unknown&utm_medium=community-edition&utm_campaign=2fa", |
||||||
|
{ class: 'button -alt-highlight', |
||||||
|
aria: {label: t('admin.enterprise.order')}, |
||||||
|
title: t('admin.enterprise.order')}) do %> |
||||||
|
<%= op_icon('button--icon icon-add') %> |
||||||
|
<span class="button--text"><%= t('admin.enterprise.order') %></span> |
||||||
|
<% end %> |
||||||
|
</div> |
||||||
|
</div> |
Loading…
Reference in new issue