Redirigir al nombre del sitio sin incluir dominio
This commit is contained in:
parent
22a7a811b4
commit
b2508de39b
3 changed files with 44 additions and 12 deletions
|
@ -8,13 +8,14 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
before_action :prepare_exception_notifier
|
||||
before_action :configure_permitted_parameters, if: :devise_controller?
|
||||
before_action :redirect_to_site_name!, only: %i[index show edit new], if: :site_id_contains_hostname?
|
||||
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'))
|
||||
Rack::MiniProfiler.authorize_request if Rails.env.development?
|
||||
end
|
||||
|
||||
# No tenemos índice de sutty, vamos directamente a ver el listado de
|
||||
|
@ -29,15 +30,11 @@ class ApplicationController < ActionController::Base
|
|||
/[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}/ =~ string
|
||||
end
|
||||
|
||||
# Encontrar un sitio por su nombre
|
||||
# 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
|
||||
current_usuarie.sites.find_by_name(site_id).tap do |site|
|
||||
raise SiteNotFound unless site
|
||||
end
|
||||
|
||||
site
|
||||
end
|
||||
|
||||
# Devuelve el idioma actual y si no lo encuentra obtiene uno por
|
||||
|
@ -62,6 +59,39 @@ class ApplicationController < ActionController::Base
|
|||
render 'application/page_not_found', status: :not_found
|
||||
end
|
||||
|
||||
# Retrocompatibilidad con sitios cuyo nombre era su hostname.
|
||||
#
|
||||
# @see Deploy
|
||||
def site_id_contains_hostname?
|
||||
site_id&.end_with? '.'
|
||||
end
|
||||
|
||||
# Redirigir a la misma URL con el site_id cambiado.
|
||||
#
|
||||
# TODO: Eliminar cuando detectemos que no hay más redirecciones.
|
||||
def redirect_to_site_name!
|
||||
params.permit!
|
||||
params[:site_id] = Deploy.site_name_from_hostname(site_id[0..-2])
|
||||
|
||||
redirect_to params, status: :moved_permanently
|
||||
end
|
||||
|
||||
# Los controladores dentro de SitesController van a usar site_id
|
||||
# mientras que SiteController va a usar ID.
|
||||
#
|
||||
# @see SitesController
|
||||
# @return [String,Nil]
|
||||
def site_id
|
||||
@site_id ||= params[:site_id]
|
||||
end
|
||||
|
||||
# El sitio actual
|
||||
#
|
||||
# @return [Site]
|
||||
def site
|
||||
@site ||= find_site
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def configure_permitted_parameters
|
||||
|
|
|
@ -7,7 +7,7 @@ class CollaborationsController < ApplicationController
|
|||
include Pundit
|
||||
|
||||
def collaborate
|
||||
@site = Site.find_by_name(params[:site_id])
|
||||
@site = find_site
|
||||
authorize Collaboration.new(@site)
|
||||
|
||||
@invitade = current_usuarie || @site.usuaries.build
|
||||
|
@ -21,7 +21,7 @@ class CollaborationsController < ApplicationController
|
|||
#
|
||||
# * Si le usuarie existe y no está logueade, pedirle la contraseña
|
||||
def accept_collaboration
|
||||
@site = Site.find_by_name(params[:site_id])
|
||||
@site = find_site
|
||||
authorize Collaboration.new(@site)
|
||||
|
||||
@invitade = current_usuarie
|
||||
|
|
|
@ -139,8 +139,10 @@ class SitesController < ApplicationController
|
|||
|
||||
private
|
||||
|
||||
def site
|
||||
@site ||= find_site
|
||||
# En los controladores dentro de este controlador vamos a usar :id
|
||||
# para obtener el nombre.
|
||||
def site_id
|
||||
@site_id ||= params[:id]
|
||||
end
|
||||
|
||||
def site_params
|
||||
|
|
Loading…
Reference in a new issue