Skip to content

Commit

Permalink
Merge tag '2024-04-16-01' into feature/impot-2024-04-18
Browse files Browse the repository at this point in the history
# Conflicts:
#	db/schema.rb
#	public/404.html
#	public/404_procedure_not_found.html
#	public/422.html
#	public/500.html
  • Loading branch information
maatinito committed Jun 6, 2024
2 parents 6fce00f + 216c5d8 commit 3755c86
Show file tree
Hide file tree
Showing 35 changed files with 9,096 additions and 306 deletions.
16 changes: 16 additions & 0 deletions app/assets/images/dsfr/artwork/background/ovoid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,17 @@ def set_customizable_view_path
prepend_view_path "app/custom_views"
end

def try_nav_bar_profile_from_referrer
# detect context from referer, simple (no detection when refreshing the page)
params = Rails.application.routes.recognize_path(request&.referer)

controller_class = "#{params[:controller].camelize}Controller".safe_constantize
return if controller_class.nil?

controller_instance = controller_class.new
controller_instance.try(:nav_bar_profile)
end

# Extract a value from params based on the "path"
#
# params: { dossiers: { champs_public_attributes: { 1234 => { value: "hello" } } } }
Expand Down
50 changes: 50 additions & 0 deletions app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

class ErrorsController < ApplicationController
def nav_bar_profile = try_nav_bar_profile_from_referrer

rescue_from Exception do
# catch any error, except errors triggered by middlewares outside controller (like warden middleware)
render file: Rails.public_path.join('500.html'), layout: false, status: :internal_server_error
end

def internal_server_error
# This dynamic template is rendered when a "normal" error occurs, (ie. a bug which is 99.99% of errors.)
# However if this action fails (error in the view or in a middlewares)
# the exceptions are rescued and a basic 100% static html file is rendererd instead.
render_error 500
end

def not_found = render_error 404
def unprocessable_entity = render_error 422

def show # generic page for others errors
@status = params[:status].to_i
@error_name = Rack::Utils::HTTP_STATUS_CODES[@status]

render_error @status
end

private

def render_error(status)
respond_to do |format|
format.html { render status: }
format.json { render status:, json: { status:, name: Rack::Utils::HTTP_STATUS_CODES[status] } }
end
end

# Intercept errors in before_action when fetching user or roles
# when db is unreachable so we can still display a nice 500 static page
def current_user
super
rescue
nil
end

def current_user_roles
super
rescue
nil
end
end
11 changes: 1 addition & 10 deletions app/controllers/release_notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,7 @@ def index
render "scrollable_list" if params[:page].present?
end

def nav_bar_profile
# detect context from referer, simple (no detection when refreshing the page)
params = Rails.application.routes.recognize_path(request&.referer)

controller_class = "#{params[:controller].camelize}Controller".safe_constantize
return if controller_class.nil?

controller_instance = controller_class.new
controller_instance.try(:nav_bar_profile)
end
def nav_bar_profile = try_nav_bar_profile_from_referrer

private

Expand Down
9 changes: 8 additions & 1 deletion app/models/concerns/attachment_virus_scanner_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ module AttachmentVirusScannerConcern
private

def scan_for_virus_later
blob&.scan_for_virus_later
return if blob.nil?

# do not scan if the blob is already marked as safe
# usually because of metadata[:virus_scan_result] = ActiveStorage::VirusScanner::SAFE
# added on a blob built by the application itself
return if blob.virus_scan_result == ActiveStorage::VirusScanner::SAFE

blob.scan_for_virus_later
end
end
9 changes: 9 additions & 0 deletions app/views/errors/_artwork.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.fr-col-12.fr-col-md-3.fr-col-offset-md-1.fr-px-6w.fr-px-md-0.fr-py-0
%svg.fr-responsive-img.fr-artwork{ xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true", width: "160", height: "200", viewBox: "0 0 160 200" }
%use.fr-artwork-motif{ href: image_path("dsfr/artwork/background/ovoid.svg#artwork-motif") }

%use.fr-artwork-background{ href: image_path('dsfr/artwork/background/ovoid.svg#artwork-background') }
%g{ transform: "translate(40, 60)" }
%use.fr-artwork-decorative{ href: image_path('dsfr/artwork/pictograms/system/technical-error.svg#artwork-decorative') }
%use.fr-artwork-minor{ href: image_path('dsfr/artwork/pictograms/system/technical-error.svg#artwork-minor') }
%use.fr-artwork-major{ href: image_path('dsfr/artwork/pictograms/system/technical-error.svg#artwork-major') }
19 changes: 19 additions & 0 deletions app/views/errors/internal_server_error.en.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%main#content{ role: "main" }
.fr-container
.fr-my-7w.fr-mt-md-12w.fr-mb-md-10w.fr-grid-row.fr-grid-row--gutters.fr-grid-row--middle.fr-grid-row--center
.fr-py-0.fr-col-12.fr-col-md-6
%h1 Unexpected Error
%p.fr-text--sm.fr-mb-3w Error 500
%p.fr-text--lead.fr-mb-3w
Sorry, an error has occurred. Our teams have been notified
to resolve the issue as quickly as possible.
%p.fr-text--sm.fr-mb-5w
Try refreshing the page or try again a little later.
%br
If you need immediate assistance, please contact us.

%ul.fr-btns-group.fr-btns-group--inline-md
%li
= link_to("Contact Us", contact_path, class: "fr-btn fr-btn--secondary")

= render partial: "artwork"
19 changes: 19 additions & 0 deletions app/views/errors/internal_server_error.fr.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%main#content{ role: "main" }
.fr-container
.fr-my-7w.fr-mt-md-12w.fr-mb-md-10w.fr-grid-row.fr-grid-row--gutters.fr-grid-row--middle.fr-grid-row--center
.fr-py-0.fr-col-12.fr-col-md-6
%h1 Erreur inattendue
%p.fr-text--sm.fr-mb-3w Erreur 500
%p.fr-text--lead.fr-mb-3w
Désolé, une erreur est survenue. Nos équipes ont été averties
pour résoudre le problème le plus rapidement possible.
%p.fr-text--sm.fr-mb-5w
Essayez de rafraîchir la page ou réessayez un peu plus tard.
%br
Si le problème persiste, merci de nous contacter.

%ul.fr-btns-group.fr-btns-group--inline-md
%li
= link_to("Contactez-nous", contact_path, class: "fr-btn fr-btn--secondary")

= render partial: "artwork"
20 changes: 20 additions & 0 deletions app/views/errors/not_found.en.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
%main#content{ role: "main" }
.fr-container
.fr-my-7w.fr-mt-md-12w.fr-mb-md-10w.fr-grid-row.fr-grid-row--gutters.fr-grid-row--middle.fr-grid-row--center
.fr-py-0.fr-col-12.fr-col-md-6
%h1 Page not found
%p.fr-text--sm.fr-mb-3w Error 404
%p.fr-text--lead.fr-mb-3w The page you are looking for cannot be found. We apologize for the inconvenience.
%p.fr-text--sm.fr-mb-5w
If you typed the web address in the browser, check that it is correct. The page may no longer be available.
%br
In this case, to continue your visit you can check our homepage.
%br
Otherwise, contact us so we can direct you to the correct information.
%ul.fr-btns-group.fr-btns-group--inline-md
%li
= link_to("Homepage", root_path, class: "fr-btn")
%li
= link_to("Contact us", contact_path, class: "fr-btn fr-btn--secondary")

= render partial: "artwork"
22 changes: 22 additions & 0 deletions app/views/errors/not_found.fr.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
%main#content{ role: "main" }
.fr-container
.fr-my-7w.fr-mt-md-12w.fr-mb-md-10w.fr-grid-row.fr-grid-row--gutters.fr-grid-row--middle.fr-grid-row--center
.fr-py-0.fr-col-12.fr-col-md-6
%h1 Page non trouvée
%p.fr-text--sm.fr-mb-3w Erreur 404
%p.fr-text--lead.fr-mb-3w La page que vous cherchez est introuvable. Excusez-nous pour la gène occasionnée.
%p.fr-text--sm.fr-mb-3w
Si vous avez tapé l’adresse web dans le navigateur, vérifiez qu’elle est correcte. La page n’est peut-être plus disponible.
%br
Dans ce cas, pour continuer votre visite vous pouvez consulter notre page d’accueil.
%br
Sinon contactez-nous pour que l’on puisse vous rediriger vers la bonne information.
%p.fr-text--sm.fr-mb-5w
Pour le laissez-passer A-38, relatif à l’enregistrement d'une galère, veuillez vous adresser à la capitainerie au port.
%ul.fr-btns-group.fr-btns-group--inline-md
%li
= link_to("Page d’accueil", root_path, class: "fr-btn")
%li
= link_to("Contactez-nous", contact_path, class: "fr-btn fr-btn--secondary")

= render partial: "artwork"
19 changes: 19 additions & 0 deletions app/views/errors/show.en.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%main#content{ role: "main" }
.fr-container
.fr-my-7w.fr-mt-md-12w.fr-mb-md-10w.fr-grid-row.fr-grid-row--gutters.fr-grid-row--middle.fr-grid-row--center
.fr-py-0.fr-col-12.fr-col-md-6
%h1= @error_name
%p.fr-text--sm.fr-mb-3w Error #{@status}
%p.fr-text--lead.fr-mb-3w An error prevents this page from loading.

- if @error_name.present? # valid error code
%p.fr-text--sm.fr-mb-5w
= link_to("What does that mean?", "https://developer.mozilla.org/en/docs/Web/HTTP/Status/#{@status}", **external_link_attributes)

%ul.fr-btns-group.fr-btns-group--inline-md
%li
= link_to("Homepage", root_path, class: "fr-btn")
%li
= link_to("Contact us", contact_path, class: "fr-btn fr-btn--secondary")

= render partial: "artwork"
19 changes: 19 additions & 0 deletions app/views/errors/show.fr.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%main#content{ role: "main" }
.fr-container
.fr-my-7w.fr-mt-md-12w.fr-mb-md-10w.fr-grid-row.fr-grid-row--gutters.fr-grid-row--middle.fr-grid-row--center
.fr-py-0.fr-col-12.fr-col-md-6
%h1= @error_name
%p.fr-text--sm.fr-mb-3w Erreur #{@status}
%p.fr-text--lead.fr-mb-3w Une erreur empêche le chargement de cette page.

- if @error_name.present? # valid error code
%p.fr-text--sm.fr-mb-5w
= link_to("Qu’est-ce que cela veut dire ?", "https://developer.mozilla.org/fr/docs/Web/HTTP/Status/#{@status}", **external_link_attributes)

%ul.fr-btns-group.fr-btns-group--inline-md
%li
= link_to("Page d’accueil", root_path, class: "fr-btn")
%li
= link_to("Contactez-nous", contact_path, class: "fr-btn fr-btn--secondary")

= render partial: "artwork"
24 changes: 24 additions & 0 deletions app/views/errors/unprocessable_entity.en.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
%main#content{ role: "main" }
.fr-container
.fr-my-7w.fr-mt-md-12w.fr-mb-md-10w.fr-grid-row.fr-grid-row--gutters.fr-grid-row--middle.fr-grid-row--center
.fr-py-0.fr-col-12.fr-col-md-6
%h1 The requested action has been rejected
%p.fr-text--sm.fr-mb-3w Error 422
%p.fr-text--lead.fr-mb-3w We're sorry, but we can't process your request.
%p.fr-text--sm.fr-mb-5w
This may be due to a request that cannot be processed in its current state.
%br
Go back to
= link_to("the previous page", "javascript:window.location = document.referrer", class: "fr-link")
and then try again.
%br

If the problem persists, please don't hesitate to contact us for assistance.

%ul.fr-btns-group.fr-btns-group--inline-md
%li
= link_to 'Back', 'javascript:window.location = document.referrer', class: 'fr-btn'
%li
= link_to 'Contact us', contact_path, class: 'fr-btn fr-btn--secondary'

= render partial: "artwork"
24 changes: 24 additions & 0 deletions app/views/errors/unprocessable_entity.fr.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
%main#content{ role: "main" }
.fr-container
.fr-my-7w.fr-mt-md-12w.fr-mb-md-10w.fr-grid-row.fr-grid-row--gutters.fr-grid-row--middle.fr-grid-row--center
.fr-py-0.fr-col-12.fr-col-md-6
%h1 L’action demandée a été rejetée
%p.fr-text--sm.fr-mb-3w Erreur 422
%p.fr-text--lead.fr-mb-3w Nous sommes désolés, mais nous ne pouvons pas traiter votre requête.
%p.fr-text--sm.fr-mb-5w
Cela peut être dû à une requête qui ne peut être traitée dans son état actuel.
%br
Revenez à
= link_to("la page précédente", "javascript:window.location = document.referrer", class: "fr-link")
puis réessayez.
%br

Si le problème persiste, n’hésitez pas à nous contacter pour obtenir de l’aide.

%ul.fr-btns-group.fr-btns-group--inline-md
%li
= link_to 'Retour', 'javascript:window.location = document.referrer', class: 'fr-btn'
%li
= link_to 'Contactez-nous', contact_path, class: 'fr-btn fr-btn--secondary'

= render partial: "artwork"
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class Application < Rails::Application
config.active_record.encryption.primary_key = Rails.application.secrets.active_record_encryption.fetch(:primary_key)
config.active_record.encryption.key_derivation_salt = Rails.application.secrets.active_record_encryption.fetch(:key_derivation_salt)

config.exceptions_app = self.routes

# Copied from rgeo/activerecord-postgis-adapter
ActiveRecord::SchemaDumper.ignore_tables |= [
'geography_columns',
Expand Down
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,11 @@

resources :release_notes, only: [:index]

get '/404', to: 'errors#not_found'
get '/422', to: 'errors#unprocessable_entity'
get '/500', to: 'errors#internal_server_error'
get '/:status', to: 'errors#show', constraints: { status: /[4-5][0-5]\d/ }

if Rails.env.test?
scope 'test/api_geo' do
get 'regions' => 'api_geo_test#regions'
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240415192417_drop_virus_scan_table.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class DropVirusScanTable < ActiveRecord::Migration[7.0]
def up
drop_table :virus_scans
end
end
7 changes: 7 additions & 0 deletions db/migrate/20240416062900_add_stable_id_index_to_champs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddStableIdIndexToChamps < ActiveRecord::Migration[7.0]
disable_ddl_transaction!

def change
add_index :champs, :stable_id, algorithm: :concurrently
end
end
Loading

0 comments on commit 3755c86

Please sign in to comment.