From a1785b0c6d9816913704ee62d4a6c27c25c69c93 Mon Sep 17 00:00:00 2001 From: "Jon R. Humphrey" Date: Thu, 7 Mar 2024 11:28:59 +0000 Subject: [PATCH 01/17] fix: added additional `rescue_from` clauses specifically rescues from `::BadRequest` and `::RecordNotFound` instead of relying on catching a routing error; also added the ability to render a 400 error in the correct template --- app/controllers/application_controller.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 827bad9..680f4bf 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -24,6 +24,8 @@ def log_request_result unless Rails.application.config.consider_all_requests_local rescue_from Exception, with: :render_exception + rescue_from ActiveRecord::RecordNotFound, with: :render404 + rescue_from ActionController::BadRequest, with: :render400 rescue_from ActionController::RoutingError, with: :render404 rescue_from ActionController::InvalidCrossOriginRequest, with: :render403 end @@ -40,6 +42,10 @@ def render_exception(exception) end end + def render_400(_exception = nil) # rubocop:disable Naming/VariableNumber + render_error(400) + end + def render_404(_exception = nil) # rubocop:disable Naming/VariableNumber render_error(404) end From f20a60394233c385d0bc9cbeb5268b30f1362319 Mon Sep 17 00:00:00 2001 From: "Jon R. Humphrey" Date: Thu, 7 Mar 2024 11:30:16 +0000 Subject: [PATCH 02/17] chore: removing erroneous files these were originally created at the project start and are not used in any manner for the error control or presentation. --- public/404.html | 58 ------------------------------------------------- public/422.html | 58 ------------------------------------------------- public/500.html | 57 ------------------------------------------------ 3 files changed, 173 deletions(-) delete mode 100644 public/404.html delete mode 100644 public/422.html delete mode 100644 public/500.html diff --git a/public/404.html b/public/404.html deleted file mode 100644 index a0daa0c..0000000 --- a/public/404.html +++ /dev/null @@ -1,58 +0,0 @@ - - - - The page you were looking for doesn't exist (404) - - - - - -
-

The page you were looking for doesn't exist.

-

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

-
-

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

- - diff --git a/public/422.html b/public/422.html deleted file mode 100644 index fbb4b84..0000000 --- a/public/422.html +++ /dev/null @@ -1,58 +0,0 @@ - - - - The change you wanted was rejected (422) - - - - - -
-

The change you wanted was rejected.

-

Maybe you tried to change something you didn't have access to.

-
-

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

- - diff --git a/public/500.html b/public/500.html deleted file mode 100644 index e9052d3..0000000 --- a/public/500.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - We're sorry, but something went wrong (500) - - - - - -
-

We're sorry, but something went wrong.

-
-

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

- - From 771470c23bcfc6d9f1e0e0f346cb41be155bd2d1 Mon Sep 17 00:00:00 2001 From: "Jon R. Humphrey" Date: Thu, 7 Mar 2024 11:30:36 +0000 Subject: [PATCH 03/17] feat: addition of 403 error template --- public/landing/403.html | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 public/landing/403.html diff --git a/public/landing/403.html b/public/landing/403.html new file mode 100644 index 0000000..f4528c1 --- /dev/null +++ b/public/landing/403.html @@ -0,0 +1,26 @@ + +
+
+
+

+ Forbidden +

+

+ We're sorry, but it seems you don't have permission to access this resource. Please check the spelling + of the page address (URL). If you require further assistance, please see the contact details below. +

+

+ Who to contact +

+

+ If you are unable to access the data please fill in our contact form. +

+

+ For general transaction data enquiries email DRO@landregistry.gov.uk +

+

+ For general price paid data enquiries contact data.services@mail.landregistry.gov.uk. +

+
+
+
From 7290305a67a5bfeebd8bbd6369666cbb6d012dcb Mon Sep 17 00:00:00 2001 From: "Jon R. Humphrey" Date: Thu, 7 Mar 2024 11:34:28 +0000 Subject: [PATCH 04/17] fix: Removed erroneous method from StandardError rescue status doesn't exist in this way on the StandardError Exception --- app/controllers/search_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 00f2706..e4c03cb 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -26,11 +26,12 @@ def create end rescue StandardError => e e = e.cause || e + status = case e when MalformedSearchError, ArgumentError :bad_request else - e.status || :internal_server_error + :internal_server_error end render_error_page(e, e.message, status) From 7970c9cd328573347ca9038d8b2bb9dbf987b959 Mon Sep 17 00:00:00 2001 From: "Jon R. Humphrey" Date: Thu, 7 Mar 2024 11:34:54 +0000 Subject: [PATCH 05/17] fix: updated .gitignore to ensure expected files are included! --- .gitignore | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index afe7ca7..e99b22f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,14 +12,13 @@ /db/*.sqlite3 /db/*.sqlite3-journal /log/*.log +/tmp /public/packs /public/packs-test -/tmp +/public/assets/ coverage/ fc.json fc_simple.json index-names.txt index.json -public/ -public/assets/ -tags \ No newline at end of file +tags From 2f71e2bf98c1220be68800f816b7815f22d3472b Mon Sep 17 00:00:00 2001 From: "Jon R. Humphrey" Date: Thu, 7 Mar 2024 11:35:57 +0000 Subject: [PATCH 06/17] build: updated Makefile targets minor adjustments to improve local development --- Makefile | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 50ec49b..b394b53 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: assets clean image lint publish realclean run tag test vars +.PHONY: assets auth check clean image lint local publish realclean run tag test vars ACCOUNT?=$(shell aws sts get-caller-identity | jq -r .Account) ALPINE_VERSION?=3.13 @@ -37,13 +37,16 @@ ${BUNDLE_CFG}: ${GITHUB_TOKEN} ${GITHUB_TOKEN}: @echo ${PAT} > ${GITHUB_TOKEN} -assets: +assets: auth @./bin/bundle config set --local without 'development test' @./bin/bundle install @./bin/rails assets:clean assets:precompile auth: ${GITHUB_TOKEN} ${BUNDLE_CFG} +check: lint test + @echo "All checks passed." + clean: @[ -d public/assets ] && ./bin/rails assets:clobber || : @@ -65,6 +68,12 @@ image: auth lint: assets @./bin/bundle exec rubocop +local: + @echo "Installing all packages ..." + @./bin/bundle install + @echo "Starting local server ..." + @./bin/rails server -p ${PORT} + publish: image @echo Publishing image: ${REPO}:${TAG} ... @docker push ${REPO}:${TAG} 2>&1 @@ -89,7 +98,10 @@ tag: @echo ${TAG} test: assets - @./bin/rails test + @echo "Running unit tests ..." + @./bin/rails test:unit + @echo "Running system tests ..." + @./bin/rails test:system vars: @echo "Docker: ${REPO}:${TAG}" From 4ef491cb4b0ebacde17acc8428fe74c51cccf904 Mon Sep 17 00:00:00 2001 From: "Jon R. Humphrey" Date: Thu, 7 Mar 2024 11:44:00 +0000 Subject: [PATCH 07/17] build: resolve build error lock rubygems-update to version that supports ruby 2.6.6 --- Gemfile | 3 +++ Gemfile.lock | 2 ++ 2 files changed, 5 insertions(+) diff --git a/Gemfile b/Gemfile index 14c5606..cdb87ef 100644 --- a/Gemfile +++ b/Gemfile @@ -20,6 +20,9 @@ gem 'uglifier', '>= 1.3.0' # gem 'therubyracer', platforms: :ruby gem 'libv8-node', '>= 16.10.0.0' +# lock down the version of rubygems-update to avoid issues with rubygems +gem 'rubygems-update', '~> 3.4', '>= 3.4.22' + gem 'jbuilder' gem 'jquery-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 207b2cc..8bec532 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -268,6 +268,7 @@ GEM ruby2_keywords (0.0.5) ruby_parser (3.19.0) sexp_processor (~> 4.16) + rubygems-update (3.4.22) rubyzip (2.3.2) sass (3.7.4) sass-listen (~> 4.0.0) @@ -398,6 +399,7 @@ DEPENDENCIES rb-readline rubocop rubocop-rails + rubygems-update (~> 3.4, >= 3.4.22) sass-rails sdoc sentry-rails (~> 5.2) From 796c661f5af749a0e3259d2e36fc9cd33870bd74 Mon Sep 17 00:00:00 2001 From: "Jon R. Humphrey" Date: Thu, 7 Mar 2024 11:51:06 +0000 Subject: [PATCH 08/17] build: resolve build error in docker container RubyGems version (3.0.3) has a bug that prevents `required_ruby_version` from working for Bundler. Any scripts that use `gem install bundler` will break as soon as Bundler drops support for your Ruby version. Please upgrade RubyGems to avoid future breakage and silence this warning by running `gem update --system 3.2.3` --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 00dc5ec..453ba1e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ RUN apk add --update \ nodejs \ tzdata \ && rm -rf /var/cache/apk/* \ - && gem update --system \ + && gem update --system 3.2.3 \ && gem install bundler:$BUNDLER_VERSION \ && bundle config --global frozen 1 From 6c8c09cd817e234ce84c1502f5e563102399d900 Mon Sep 17 00:00:00 2001 From: "Jon R. Humphrey" Date: Thu, 7 Mar 2024 13:17:53 +0000 Subject: [PATCH 09/17] fix: resolve app failures Removed unknown constants from application_controller.rb as well as reordered rescues to ensure specific errors are not caught early by the generic `Exception` rescue --- app/controllers/application_controller.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 680f4bf..77eedbe 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -23,11 +23,10 @@ def log_request_result end unless Rails.application.config.consider_all_requests_local - rescue_from Exception, with: :render_exception - rescue_from ActiveRecord::RecordNotFound, with: :render404 - rescue_from ActionController::BadRequest, with: :render400 - rescue_from ActionController::RoutingError, with: :render404 rescue_from ActionController::InvalidCrossOriginRequest, with: :render403 + rescue_from ActionController::RoutingError, with: :render404 + rescue_from ActionController::BadRequest, with: :render400 + rescue_from Exception, with: :render_exception end def render_exception(exception) From 89bdde6eaf25e558dae560f8f07afe9e2fa4762a Mon Sep 17 00:00:00 2001 From: "Jon R. Humphrey" Date: Fri, 8 Mar 2024 10:11:42 +0000 Subject: [PATCH 10/17] fix: resolving missing template rescue added the ActionView::MissingTemplate rescue --- app/controllers/application_controller.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 77eedbe..cb023bc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -22,10 +22,13 @@ def log_request_result detailed_request_log(duration) end + # Handle specific types of exceptions and render the appropriate error page + # or attempt to render a generic error page if no specific error page exists unless Rails.application.config.consider_all_requests_local rescue_from ActionController::InvalidCrossOriginRequest, with: :render403 rescue_from ActionController::RoutingError, with: :render404 rescue_from ActionController::BadRequest, with: :render400 + rescue_from ActionView::MissingTemplate, with: :render404 rescue_from Exception, with: :render_exception end From a21c44d2e69c23c23b33a3c2e02b309adb0bdc0e Mon Sep 17 00:00:00 2001 From: "Jon R. Humphrey" Date: Fri, 8 Mar 2024 10:12:13 +0000 Subject: [PATCH 11/17] chore: rearranged for readability --- app/controllers/application_controller.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cb023bc..b1a3f70 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -9,12 +9,20 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :null_session before_action :set_phase, :change_default_caching_policy + around_action :log_request_result def set_phase @phase = :released end - around_action :log_request_result + # * Set cache control headers for HMLR apps to be public and cacheable + # * Price Paid Data uses a time limit of 5 minutes (300 seconds) + # Sets the default `Cache-Control` header for all requests, + # unless overridden in the action + def change_default_caching_policy + expires_in 5.minutes, public: true, must_revalidate: true if Rails.env.production? + end + def log_request_result start = Process.clock_gettime(Process::CLOCK_MONOTONIC, :microsecond) yield @@ -110,12 +118,4 @@ def detailed_request_log(duration) def instrument_internal_error(exception) ActiveSupport::Notifications.instrument('internal_error.application', exception: exception) end - - # * Set cache control headers for HMLR apps to be public and cacheable - # * Price Paid Data uses a time limit of 5 minutes (300 seconds) - # Sets the default `Cache-Control` header for all requests, - # unless overridden in the action - def change_default_caching_policy - expires_in 5.minutes, public: true, must_revalidate: true if Rails.env.production? - end end From 5dfe39ed3a7cac6f687ef00ddacfe81cd8c78ad0 Mon Sep 17 00:00:00 2001 From: "Jon R. Humphrey" Date: Fri, 8 Mar 2024 10:16:50 +0000 Subject: [PATCH 12/17] docs: Updated CHANGELOG --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8df2626..d7fa554 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ This app allows the user to explore HMLR price-paid open linked data. +## 1.7.6 - 2024-03-08 + +- (Jon) Updated the application_controller to include a + `ActionView::MissingTemplate` rescue to ensure the correct 404 template is + displayed when a template is not found + [GH-138](https://github.com/epimorphics/hmlr-linked-data/issues/138) + ## 1.7.5 - 2023-11-27 - (Jon) Updated the `lr_common_styles` gem to the latest 1.9.3 patch release. From e36cf54a79d4ec76d084d0f9f4eb2c15325cdc6b Mon Sep 17 00:00:00 2001 From: "Jon R. Humphrey" Date: Fri, 8 Mar 2024 10:17:09 +0000 Subject: [PATCH 13/17] build: incremented Patch Version cadence for release --- app/lib/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/version.rb b/app/lib/version.rb index 011f92f..2e2f290 100644 --- a/app/lib/version.rb +++ b/app/lib/version.rb @@ -3,7 +3,7 @@ module Version MAJOR = 1 MINOR = 7 - PATCH = 5 + PATCH = 6 SUFFIX = nil VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}#{SUFFIX && ".#{SUFFIX}"}" end From 4fba3e16784e67a8c5ee26f5473f7b19e7aea763 Mon Sep 17 00:00:00 2001 From: "Jon R. Humphrey" Date: Fri, 8 Mar 2024 10:21:33 +0000 Subject: [PATCH 14/17] chore: Fixed typo in latest CHANGELOG entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7fa554..f02764d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ This app allows the user to explore HMLR price-paid open linked data. ## 1.7.6 - 2024-03-08 -- (Jon) Updated the application_controller to include a +- (Jon) Updated the application_controller to include an `ActionView::MissingTemplate` rescue to ensure the correct 404 template is displayed when a template is not found [GH-138](https://github.com/epimorphics/hmlr-linked-data/issues/138) From 0944a1fa172976e05fb7acbb0a8664509408d92e Mon Sep 17 00:00:00 2001 From: "Jon R. Humphrey" Date: Fri, 8 Mar 2024 15:11:32 +0000 Subject: [PATCH 15/17] fix: resolves missing template error now returns the error status as human readable plain string which does not require a specific template --- app/controllers/application_controller.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b1a3f70..21c3b27 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -69,9 +69,8 @@ def render_error(status) respond_to do |format| format.html { render_html_error_page(status) } - format.all do - render nothing: true, status: status - end + # Anything else returns the status as human readable plain string + format.all { render plain: Rack::Utils::HTTP_STATUS_CODES[status].to_s, status: status } end end From 3f6cbe4c3e1ec73d83b26dc912dff16789f87269 Mon Sep 17 00:00:00 2001 From: "Jon R. Humphrey" Date: Fri, 8 Mar 2024 15:12:51 +0000 Subject: [PATCH 16/17] style: Unnecessary disabling of `Metrics/PerceivedComplexity` --- app/controllers/search_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index e4c03cb..ec0ce04 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -8,7 +8,7 @@ def index create end - # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity + # rubocop:disable Metrics/MethodLength def create @preferences = UserPreferences.new(params) From a44ef49dab988acf1f56e683577f618c3dd29530 Mon Sep 17 00:00:00 2001 From: "Jon R. Humphrey" Date: Fri, 8 Mar 2024 16:20:45 +0000 Subject: [PATCH 17/17] build: temporarily disable deployment to production instance --- deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment.yaml b/deployment.yaml index a059395..f2a3d01 100644 --- a/deployment.yaml +++ b/deployment.yaml @@ -3,7 +3,7 @@ name: epimorphics/ppd-explorer key: ppd deployments: - branch: "prod" - deploy: "prod" + # deploy: "prod" publish: "prod" - branch: "preprod" deploy: "preprod"