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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 8df2626..f02764d 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 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) + ## 1.7.5 - 2023-11-27 - (Jon) Updated the `lr_common_styles` gem to the latest 1.9.3 patch release. 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 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) 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}" diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 827bad9..21c3b27 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 @@ -22,10 +30,14 @@ 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 Exception, with: :render_exception - 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 ActionView::MissingTemplate, with: :render404 + rescue_from Exception, with: :render_exception end def render_exception(exception) @@ -40,6 +52,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 @@ -53,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 @@ -102,12 +117,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 diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 00f2706..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) @@ -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) 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 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" 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 @@ - - -
-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 @@ - - - -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 @@ - - - -If you are the application owner check the logs for more information.
- - 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 @@ + ++ 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. +
++ 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. +
+