diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index cb0404f6..974d9e70 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 1b357c56..c7a5dc56 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 ca001c9a..35610b5a 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 44c35a74..ebed91d0 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 00000000..ef848955 --- /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 00000000..f6d260c7 --- /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 723190b4..edc2b3db 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 45aa689a..e9d1345a 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 2be3af26..ead0a5ab 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 d2f03d4b..52db30d1 100644 --- a/public/500.html +++ b/public/500.html @@ -3,7 +3,8 @@ Sutty - + +