5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-07-03 00:56:07 +00:00
panel/app/controllers/application_controller.rb

66 lines
1.6 KiB
Ruby
Raw Normal View History

2019-03-26 15:32:20 +00:00
# frozen_string_literal: true
2018-01-29 22:19:10 +00:00
# Forma de ingreso a Sutty
2018-01-02 17:19:25 +00:00
class ApplicationController < ActionController::Base
include ExceptionHandler
2018-01-02 17:19:25 +00:00
protect_from_forgery with: :exception
before_action :prepare_exception_notifier
before_action :configure_permitted_parameters, if: :devise_controller?
2020-05-23 15:38:03 +00:00
around_action :set_locale
2018-01-29 18:09:30 +00:00
rescue_from ActionController::RoutingError, with: :page_not_found
2020-05-11 21:56:42 +00:00
before_action do
Rack::MiniProfiler.authorize_request if current_usuarie.try(:ends_with?, '@' + ENV.fetch('SUTTY', 'sutty.nl'))
2020-05-11 21:56:42 +00:00
end
2018-01-29 22:19:10 +00:00
# No tenemos índice de sutty, vamos directamente a ver el listado de
# sitios
2018-01-29 18:09:30 +00:00
def index
redirect_to sites_path
end
2018-01-29 22:19:10 +00:00
2019-03-26 15:32:20 +00:00
def markdown; end
2018-02-25 01:10:37 +00:00
2018-01-29 22:19:10 +00:00
private
def uuid?(string)
/[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}/ =~ string
end
2019-07-03 23:25:23 +00:00
# Encontrar un sitio por su nombre
2018-01-29 22:19:10 +00:00
def find_site
id = params[:site_id] || params[:id]
unless (site = current_usuarie.sites.find_by_name(id))
raise SiteNotFound
end
2019-07-04 16:23:43 +00:00
site
2018-01-29 22:19:10 +00:00
end
2018-01-30 15:20:19 +00:00
2020-05-23 15:38:03 +00:00
# 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_usuarie.try(:lang) || I18n.default_locale, &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])
2018-02-26 22:08:21 +00:00
end
def prepare_exception_notifier
request.env['exception_notifier.exception_data'] = { current_user: current_user }
end
2018-01-02 17:19:25 +00:00
end