mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-26 09:56:21 +00:00
74 lines
2 KiB
Ruby
74 lines
2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# Forma de ingreso a Sutty
|
|
class ApplicationController < ActionController::Base
|
|
include ExceptionHandler
|
|
|
|
protect_from_forgery with: :null_session, prepend: true
|
|
|
|
before_action :prepare_exception_notifier
|
|
before_action :configure_permitted_parameters, if: :devise_controller?
|
|
around_action :set_locale
|
|
|
|
rescue_from ActionController::RoutingError, with: :page_not_found
|
|
rescue_from ActionController::ParameterMissing, with: :page_not_found
|
|
|
|
before_action do
|
|
Rack::MiniProfiler.authorize_request if current_usuarie&.email&.ends_with?('@' + ENV.fetch('SUTTY', 'sutty.nl'))
|
|
end
|
|
|
|
# No tenemos índice de sutty, vamos directamente a ver el listado de
|
|
# sitios
|
|
def index
|
|
redirect_to sites_path
|
|
end
|
|
|
|
private
|
|
|
|
def uuid?(string)
|
|
/[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}/ =~ string
|
|
end
|
|
|
|
# Encontrar un sitio por su nombre
|
|
def find_site
|
|
id = params[:site_id] || params[:id]
|
|
|
|
unless (site = current_usuarie.sites.find_by_name(id))
|
|
raise SiteNotFound
|
|
end
|
|
|
|
site
|
|
end
|
|
|
|
# Devuelve el idioma actual y si no lo encuentra obtiene uno por
|
|
# defecto.
|
|
#
|
|
# Esto se refiere al idioma de la interfaz, no de los artículos.
|
|
def current_locale(include_params: true, site: nil)
|
|
return params[:locale] if include_params && params[:locale].present?
|
|
|
|
current_usuarie&.lang || I18n.locale
|
|
end
|
|
|
|
# El idioma es el preferido por le usuarie, pero no necesariamente se
|
|
# corresponde con el idioma de los artículos, porque puede querer
|
|
# traducirlos.
|
|
def set_locale(&action)
|
|
I18n.with_locale(current_locale(include_params: false), &action)
|
|
end
|
|
|
|
# Muestra una página 404
|
|
def page_not_found
|
|
render 'application/page_not_found', status: :not_found
|
|
end
|
|
|
|
protected
|
|
|
|
def configure_permitted_parameters
|
|
devise_parameter_sanitizer.permit(:account_update, keys: %i[lang])
|
|
end
|
|
|
|
def prepare_exception_notifier
|
|
request.env['exception_notifier.exception_data'] = { usuarie: current_usuarie }
|
|
end
|
|
end
|