Skip to content
This repository has been archived by the owner on Oct 27, 2020. It is now read-only.

Commit

Permalink
Change redirect path for renewals (#279)
Browse files Browse the repository at this point in the history
We had to implement a change to how URLs, and specifically any URL that points to a page which handles transient registrations are formed.

DEFRA/waste-carriers-engine#579

Essentially we needed to switch to using a token rather than the registration identifier. That specific change does not affect the frontend, but as part of the same PR, we also fixed an issue with validation errors, where generating one would break backlinks.

This turned out to just be because we were putting the ID for a 'resource' at the end of the URL, rather than before the action we wanted to carry out against it. This seems to break a rails convention hence generated back links stopped working in certain cases.

That fix does impact this project because it now needs to ensure that the path it redirects users to when renewing matches what the new front and back-office apps expect.

This change covers everything needed to update the frontend to redirect users correctly.

N.B. This also removes the check whether to show the renewals holding page

PR #278 removed the renewals holding page. We should have probably removed the check whether to show the holding page as well, but forgot we had one!
  • Loading branch information
Cruikshanks committed Dec 12, 2019
1 parent f942b92 commit 459303d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 35 deletions.
4 changes: 2 additions & 2 deletions app/models/concerns/can_be_renewed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def expired?
end

def renewals_url
"#{Rails.configuration.renewals_service_url}#{regIdentifier}"
File.join(Rails.configuration.front_office_url, regIdentifier, "renew")
end

def back_office_renewals_url
"#{Rails.configuration.back_office_renewals_url}#{regIdentifier}"
File.join(Rails.configuration.back_office_url, regIdentifier, "ad-privacy-policy")
end
end
42 changes: 15 additions & 27 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,26 @@ class Application < Rails::Application
# config/initializers; all .rb files in that directory are automatically
# loaded.

def renewal_service_url(app_path)
base_url = base_url(app_path)
path = if ENV['WCRS_HOLD_RENEWALS']
'/renew/'
else
"/#{app_path}/renew/"
end
"#{base_url}#{path}"
end

def ad_verbal_privacy_policy_renewal_url(app_path)
base_url = base_url(app_path)

"#{base_url}/#{app_path}/ad-privacy-policy/"
end

def base_url(app_path)
if Rails.env.production?
# In production the base url needs to match the external url, hence we
# can just pull from our config.
back_office = config.waste_exemplar_frontend_admin_url
front_office = config.waste_exemplar_frontend_url
backend = config.waste_exemplar_frontend_admin_url
frontend = config.waste_exemplar_frontend_url
else
back_office = ENV['WCRS_BACKOFFICE_DOMAIN'] || 'http://localhost:8001'
front_office = ENV['WCRS_RENEWALS_DOMAIN'] || 'http://localhost:3000'
backend = ENV['WCRS_BACKOFFICE_DOMAIN'] || 'http://localhost:8001'
frontend = ENV['WCRS_RENEWALS_DOMAIN'] || 'http://localhost:3000'
end

return front_office if app_path == "fo"
back_office
return frontend if app_path == "fo"

backend
end

def base_office_url(app_path)
return base_url(app_path) unless Rails.env.production?

File.join(base_url(app_path), app_path)
end

config.time_zone = "Europe/London"
Expand Down Expand Up @@ -80,11 +71,8 @@ def base_url(app_path)
config.waste_exemplar_services_admin_url = ENV['WCRS_SERVICES_ADMIN_DOMAIN'] || 'http://localhost:8004'
config.waste_exemplar_addresses_url = ENV['WCRS_OS_PLACES_DOMAIN'] || 'http://localhost:8005'

config.renewals_service_url = renewal_service_url("fo")
config.back_office_renewals_url = ad_verbal_privacy_policy_renewal_url("bo")

config.front_office_url = base_url("fo")
config.back_office_url = base_url("bo")
config.front_office_url = base_office_url("fo")
config.back_office_url = base_office_url("bo")

# The subdomains used in links for password reset and other e-mails sent by
# the Devise authentication component.
Expand Down
12 changes: 6 additions & 6 deletions spec/models/concerns/can_be_renewed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,21 @@

describe "#renewals_url" do
before do
allow(Rails.configuration).to receive(:renewals_service_url).and_return("http://localhost:3000/renew/")
allow(Rails.configuration).to receive(:front_office_url).and_return("http://localhost:3000/fo")
end

it "returns the configured url with the registration number appended to the end" do
expect(registration.renewals_url).to eq("http://localhost:3000/renew/CBDU1")
it "returns the configured url with the registration number as part of the path" do
expect(registration.renewals_url).to eq("http://localhost:3000/fo/CBDU1/renew")
end
end

describe "#back_office_renewals_url" do
before do
allow(Rails.configuration).to receive(:back_office_renewals_url).and_return("http://localhost:8001/bo/renew/")
allow(Rails.configuration).to receive(:back_office_url).and_return("http://localhost:8001/bo")
end

it "returns the configured url with the registration number appended to the end" do
expect(registration.back_office_renewals_url).to eq("http://localhost:8001/bo/renew/CBDU1")
it "returns the configured url with the registration number as part of the path" do
expect(registration.back_office_renewals_url).to eq("http://localhost:8001/bo/CBDU1/ad-privacy-policy")
end
end
end

0 comments on commit 459303d

Please sign in to comment.