Files
grecia/app/controllers/management/base_controller.rb
Javi Martín 6de4737b70 Allow different default locales per tenant
Note that, for everything to work consistently, we need to make sure
that the default locale is one of the available locales.

Also note that we aren't overwriting the `#save ` method set by
globalize. I didn't feel too comfortable changing a monkey-patch which
ideally shouldn't be there in the first place, I haven't found a case
where `Globalize.locale` is `nil` (since it defaults to `I18n.locale`,
which should never be `nil`), so using `I18n.default_locale` probably
doesn't affect us.
2024-06-05 16:10:56 +02:00

62 lines
1.5 KiB
Ruby

class Management::BaseController < ActionController::Base
include TenantVariants
include GlobalizeFallbacks
layout "management"
default_form_builder ConsulFormBuilder
before_action :verify_manager
around_action :switch_locale
helper_method :managed_user
helper_method :current_user
helper_method :manager_logged_in
private
def verify_manager
raise ActionController::RoutingError, "Not Found" if current_manager.blank?
end
def current_manager
session[:manager]
end
def current_user
managed_user
end
def managed_user
@managed_user ||= Verification::Management::ManagedUser.find(
session[:document_type],
session[:document_number]
)
end
def check_verified_user(alert_msg)
return if managed_user.persisted? && managed_user.level_two_or_three_verified?
message = managed_user.persisted? ? alert_msg : t("management.sessions.need_managed_user")
redirect_to management_document_verifications_path, alert: message
end
def switch_locale(&action)
if params[:locale] && Setting.enabled_locales.include?(params[:locale].to_sym)
session[:locale] = params[:locale].to_s
end
session[:locale] ||= Setting.default_locale.to_s
I18n.with_locale(session[:locale], &action)
end
def clear_password
session[:new_password] = nil
end
def manager_logged_in
if current_manager
@manager_logged_in = User.find_by_manager_login(session[:manager]["login"])
end
end
end