From 31723620638bb461cc46eaf8d598ddb876b118cb Mon Sep 17 00:00:00 2001 From: kethlinmil Date: Wed, 4 Sep 2024 12:05:34 +0200 Subject: [PATCH 1/4] feat APPS-2388 Page Not Found --- app/assets/stylesheets/base/base.scss | 1 + .../base/templates/_error-page.scss | 36 +++++++++++++++++++ app/controllers/application_controller.rb | 3 +- app/controllers/errors_controller.rb | 4 +++ app/views/errors/not_found.html.erb | 20 +++++++++++ spec/controllers/catalog_controller_spec.rb | 11 ++++-- spec/system/view_unauthorized_work_spec.rb | 2 +- 7 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 app/assets/stylesheets/base/templates/_error-page.scss create mode 100644 app/controllers/errors_controller.rb create mode 100644 app/views/errors/not_found.html.erb diff --git a/app/assets/stylesheets/base/base.scss b/app/assets/stylesheets/base/base.scss index 32b37cc86..62fdd444e 100644 --- a/app/assets/stylesheets/base/base.scss +++ b/app/assets/stylesheets/base/base.scss @@ -18,6 +18,7 @@ @import 'templates/static-page'; @import 'templates/item-page'; @import 'templates/collection-page'; +@import 'templates/error-page'; @import 'templates/index-page'; @import 'templates/homepage'; @import 'components/banner/collection-banner'; diff --git a/app/assets/stylesheets/base/templates/_error-page.scss b/app/assets/stylesheets/base/templates/_error-page.scss new file mode 100644 index 000000000..2324e7a53 --- /dev/null +++ b/app/assets/stylesheets/base/templates/_error-page.scss @@ -0,0 +1,36 @@ +.content-container--error-page { + max-width: 832px; + margin: 0 auto; + + .error-page__title-row { + margin-bottom: 48px; + color: $ucla-darkest-blue; + + h1 { + font-size: 52px; + font-weight: 700; + line-height: 62px; + text-align: center; + } + + h4 { + font-size: 24px; + line-height: 36px; + } + } + + ul { + margin-left: 40px; + + li { + margin-bottom: 10px; + + a { + font-size: 16px; + line-height: 24px; + text-decoration: underline; + color: #000000; + } + } + } +} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 766df0d35..f894f618b 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -52,9 +52,10 @@ def cors_preflight_check protect_from_forgery with: :exception rescue_from Blacklight::AccessControls::AccessDenied, with: :render_404 + rescue_from Blacklight::Exceptions::RecordNotFound, with: :render_404 def render_404 - render file: Rails.root.join('public', '404.html'), status: :not_found, layout: false + render 'errors/not_found' end def solr_document_path(*args) diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb new file mode 100644 index 000000000..58cc96911 --- /dev/null +++ b/app/controllers/errors_controller.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true +class ErrorsController < ApplicationController + def not_found; end +end diff --git a/app/views/errors/not_found.html.erb b/app/views/errors/not_found.html.erb new file mode 100644 index 000000000..f2b1d497c --- /dev/null +++ b/app/views/errors/not_found.html.erb @@ -0,0 +1,20 @@ +
+
+

Page not found.

+
+ +
+

+ We can’t find the page you are looking for, but we're here to help. Try + these regularly visited links. +

+
+ + +
diff --git a/spec/controllers/catalog_controller_spec.rb b/spec/controllers/catalog_controller_spec.rb index b0d059bcc..9e9d4df71 100644 --- a/spec/controllers/catalog_controller_spec.rb +++ b/spec/controllers/catalog_controller_spec.rb @@ -276,9 +276,16 @@ context 'when the URL contains the ID of a hyrax object without an ark (e.g. a permissions object)' do let(:solr_document) { SolrDocument.new(id: 'cba-321') } - it 'raises an exception' do + before do allow(SolrDocument).to receive(:find).and_call_original - expect { get('/catalog/cba-321') } .to raise_exception(Blacklight::Exceptions::RecordNotFound) + end + + it 'catches not_found and renders errors/not_found' do + expect(get('/catalog/cba-321')).to render_template('errors/not_found') + end + + it 'raises an exception' do + expect { get('/catalog/cba-321') }.not_to raise_exception(Blacklight::Exceptions::RecordNotFound) end end end diff --git a/spec/system/view_unauthorized_work_spec.rb b/spec/system/view_unauthorized_work_spec.rb index b1ce9f535..657cc5076 100644 --- a/spec/system/view_unauthorized_work_spec.rb +++ b/spec/system/view_unauthorized_work_spec.rb @@ -23,6 +23,6 @@ it 'denies access' do visit "/catalog/#{ark}" - expect(page).to have_content 'The page you were looking for doesn\'t exist' + expect(page).to have_content 'Page not found' end end From 117df51169294d207f45d812dd96fec71f52faf6 Mon Sep 17 00:00:00 2001 From: kethlinmil Date: Mon, 23 Sep 2024 15:32:06 +0200 Subject: [PATCH 2/4] added links --- app/views/errors/not_found.html.erb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/errors/not_found.html.erb b/app/views/errors/not_found.html.erb index f2b1d497c..85ee81e08 100644 --- a/app/views/errors/not_found.html.erb +++ b/app/views/errors/not_found.html.erb @@ -11,10 +11,10 @@ From ffe86a0e25e32dcfe63a503efbabd7758d80a636 Mon Sep 17 00:00:00 2001 From: kethlinmil Date: Mon, 23 Sep 2024 15:33:15 +0200 Subject: [PATCH 3/4] whitespace removed --- app/views/errors/not_found.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/errors/not_found.html.erb b/app/views/errors/not_found.html.erb index 85ee81e08..71d68ab34 100644 --- a/app/views/errors/not_found.html.erb +++ b/app/views/errors/not_found.html.erb @@ -12,7 +12,7 @@
  • UCLA Library Digital Collections Home
  • -
  • UCLA Library Home
  • +
  • UCLA Library Home
  • Research Help
  • Ask a Librarian
  • Accessibility Resources
  • From 3360ff1fad49974395379188312a0465f6e9ce6a Mon Sep 17 00:00:00 2001 From: kethlinmil Date: Mon, 23 Sep 2024 15:59:28 +0200 Subject: [PATCH 4/4] styles update --- app/assets/stylesheets/base/templates/_error-page.scss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/base/templates/_error-page.scss b/app/assets/stylesheets/base/templates/_error-page.scss index 2324e7a53..06baa993d 100644 --- a/app/assets/stylesheets/base/templates/_error-page.scss +++ b/app/assets/stylesheets/base/templates/_error-page.scss @@ -1,6 +1,6 @@ .content-container--error-page { - max-width: 832px; margin: 0 auto; + max-width: 832px; .error-page__title-row { margin-bottom: 48px; @@ -29,7 +29,7 @@ font-size: 16px; line-height: 24px; text-decoration: underline; - color: #000000; + color: #000; } } }