diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index cb0404f..974d9e7 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -8,6 +8,7 @@ $magenta: #f206f9; // Redefinir variables de Bootstrap $primary: $magenta; +$jumbotron-bg: transparent; @import "bootstrap"; @@ -294,3 +295,7 @@ svg { height: auto; } } + +.vh-100 { + height: 100vh !important; +} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1b357c5..c7a5dc5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -9,9 +9,7 @@ class ApplicationController < ActionController::Base around_action :set_locale before_action do - if current_usuarie.try(:ends_with?, '@' + ENV.fetch('SUTTY', 'sutty.nl')) - Rack::MiniProfiler.authorize_request - end + Rack::MiniProfiler.authorize_request if current_usuarie.try(:ends_with?, '@' + ENV.fetch('SUTTY', 'sutty.nl')) end # No tenemos índice de sutty, vamos directamente a ver el listado de @@ -42,6 +40,11 @@ class ApplicationController < ActionController::Base 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 diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index ca001c9..35610b5 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -3,6 +3,8 @@ # Controlador para artículos class PostsController < ApplicationController include Pundit + rescue_from Pundit::NilPolicyError, with: :page_not_found + before_action :authenticate_usuarie! # Las URLs siempre llevan el idioma actual o el de le usuarie @@ -32,6 +34,7 @@ class PostsController < ApplicationController def show @site = find_site @post = @site.posts(lang: locale).find params[:id] + authorize @post @locale = locale diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb index 44c35a7..ebed91d 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -3,6 +3,8 @@ # Controlador de sitios class SitesController < ApplicationController include Pundit + rescue_from Pundit::NilPolicyError, with: :page_not_found + before_action :authenticate_usuarie! # Ver un listado de sitios diff --git a/app/policies/nil_class_policy.rb b/app/policies/nil_class_policy.rb new file mode 100644 index 0000000..ef84895 --- /dev/null +++ b/app/policies/nil_class_policy.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +# Una política para mostrar un error 404 cuando no se puede encontrar el +# recurso. +# +# @see app/controllers/application_controller.rb +# @see app/controllers/posts_controller.rb +# @see app/controllers/site_controller.rb +class Pundit::NilPolicyError < RuntimeError; end + +class NilClassPolicy + def initialize(_, _) + raise Pundit::NilPolicyError + end +end diff --git a/app/views/application/page_not_found.haml b/app/views/application/page_not_found.haml new file mode 100644 index 0000000..f6d260c --- /dev/null +++ b/app/views/application/page_not_found.haml @@ -0,0 +1,6 @@ +%main.vh-100.p-0.d-flex.align-items-center + %div + %h1= t('.title') + + %p= t('.description') + %p= link_to t('.button'), '/' diff --git a/config/locales/en.yml b/config/locales/en.yml index 723190b..edc2b3d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -457,3 +457,8 @@ en: invitaciones: 'You can invite new %{invite_as} by entering an email address per line. They will receive an email with your invitation and decide if they want to accept or not.' invitaciones: Send invitations to these addresses submit: Send invitations + application: + page_not_found: + title: '404: Page not found :(' + description: "You're reading this message because the page you wanted doesn't exist." + button: 'Back to panel' diff --git a/config/locales/es.yml b/config/locales/es.yml index 45aa689..e9d1345 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -465,3 +465,8 @@ es: invitaciones: 'Invita nueves %{invite_as} ingresando una dirección de correo electrónico por línea. Recibirán un correo con tu invitación y podrán aceptarla o no.' invitaciones: Invitar a estas direcciones submit: Enviar invitaciones + application: + page_not_found: + title: '404: Página no encontrada :(' + description: 'Estás leyendo este error porque la página que quisiste acceder no existe.' + button: 'Volver al panel' diff --git a/public/404.html b/public/404.html index 2be3af2..ead0a5a 100644 --- a/public/404.html +++ b/public/404.html @@ -1,67 +1,32 @@ - - The page you were looking for doesn't exist (404) - - - +

You're reading this message because the address you wanted doesn't exist :(

- - -
-
-

The page you were looking for doesn't exist.

-

You may have mistyped the address or the page may have moved.

+

Go to panel

+ + +
-

If you are the application owner check the logs for more information.

- - + diff --git a/public/500.html b/public/500.html index d2f03d4..52db30d 100644 --- a/public/500.html +++ b/public/500.html @@ -3,7 +3,8 @@ Sutty - + +