From adc0a460bde2cd04dd3f7247815142bf47d174f5 Mon Sep 17 00:00:00 2001 From: sboursen-scinote Date: Thu, 21 Sep 2023 20:43:58 +0200 Subject: [PATCH] Improve logic for custom logos on error pages [SCI-9147] - Switch to dynamic ERB templates. - Move text to I18n --- app/controllers/application_controller.rb | 6 +- app/views/errors/403.html.erb | 118 ++++++++++++++++++++++ app/views/errors/404.html.erb | 81 +++++++++++++++ app/views/errors/422.html.erb | 80 +++++++++++++++ config/locales/en.yml | 21 ++++ 5 files changed, 303 insertions(+), 3 deletions(-) create mode 100644 app/views/errors/403.html.erb create mode 100644 app/views/errors/404.html.erb create mode 100644 app/views/errors/422.html.erb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4b3fda052..acbfdd4d9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -46,7 +46,7 @@ class ApplicationController < ActionController::Base def render_403(style = 'danger') respond_to do |format| format.html do - render file: 'public/403.html', status: :forbidden, layout: false + render 'errors/403', status: :forbidden, layout: false end format.json do render json: { style: style }, status: :forbidden @@ -60,7 +60,7 @@ class ApplicationController < ActionController::Base def render_404 respond_to do |format| format.html do - render file: 'public/404.html', status: :not_found, layout: false + render 'errors/404', status: :not_found, layout: false end format.json do render json: {}, status: :not_found @@ -74,7 +74,7 @@ class ApplicationController < ActionController::Base def render_422(message = t('client_api.permission_error')) respond_to do |format| format.html do - render file: 'public/422.html', status: :unprocessable_entity, layout: false + render 'errors/422', status: :unprocessable_entity, layout: false end format.json do render json: { message: message }, status: :unprocessable_entity diff --git a/app/views/errors/403.html.erb b/app/views/errors/403.html.erb new file mode 100644 index 000000000..2152c64b4 --- /dev/null +++ b/app/views/errors/403.html.erb @@ -0,0 +1,118 @@ + + + + <%= t("errors.forbidden.title") %> + + + + + + +
+ +

<%= t("errors.forbidden.dialog.title") %>

+

<%= t("errors.forbidden.dialog.text") %>

+ + + + <%= t("errors.forbidden.dialog.button") %> + +
+ + diff --git a/app/views/errors/404.html.erb b/app/views/errors/404.html.erb new file mode 100644 index 000000000..4721396d1 --- /dev/null +++ b/app/views/errors/404.html.erb @@ -0,0 +1,81 @@ + + + + <%= t("errors.not_found.title") %> + + + + + + +
+ +

<%= t("errors.not_found.dialog.title") %>

+

<%= t("errors.not_found.dialog.text_1") %>

+

<%= t("errors.not_found.dialog.text_2_html", home_url: root_url, search_url: new_search_url) %>

+
+ + diff --git a/app/views/errors/422.html.erb b/app/views/errors/422.html.erb new file mode 100644 index 000000000..fa8fde02f --- /dev/null +++ b/app/views/errors/422.html.erb @@ -0,0 +1,80 @@ + + + + <%= t("errors.unprocessable_entity.title") %> + + + + + + +
+ +

<%= t("errors.unprocessable_entity.dialog.title") %>

+

<%= t("errors.unprocessable_entity.dialog.text") %>

+
+ + diff --git a/config/locales/en.yml b/config/locales/en.yml index a163773e4..385ff2c81 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3759,3 +3759,24 @@ en: canvas_view: "Canvas view" active_state: "Active state" archived_state: "Archived state" + + errors: + forbidden: + title: "Access to this page is denied (403)." + dialog: + title: "It would seem that you are not allowed in here." + text: "You should request access from your team administrators." + button: "Go back" + not_found: + title: "This page could not be found (404)." + dialog: + title: "This page could not be found (404)." + text_1: "You may have mistyped the address or the page may have moved." + text_2_html: | + "If you are the application owner check the logs for more information. + You can go back to home page or try searching." + unprocessable_entity: + title: "The change you wanted was rejected (422)." + dialog: + title: "Ooops, something went wrong." + text: "Please contact your SciNote administrator."