Module: GovukPersonalisation::Urls

Defined in:
lib/govuk_personalisation/urls.rb

Class Method Summary collapse

Class Method Details

.digital_identity_domainString

Gets the Digital Identity domain for the current environment

Returns:

  • (String)

    the domain



97
98
99
100
101
102
103
104
# File 'lib/govuk_personalisation/urls.rb', line 97

def self.digital_identity_domain
  environment = ENV["DIGITAL_IDENTITY_ENVIRONMENT"]
  if environment
    "#{environment}.account.gov.uk"
  else
    "account.gov.uk"
  end
end

.feedbackString

Find the external URL for the “feedback” page

Returns:

  • (String)

    the URL



49
50
51
# File 'lib/govuk_personalisation/urls.rb', line 49

def self.feedback
  find_external_url(var: "FEEDBACK", url: "https://signin.account.gov.uk/support")
end

.find_external_url(var:, url:) ⇒ String

Finds a URL outside www.gov.uk

If ‘GOVUK_PERSONALISATION_#var_URI` is in the environment, that will be returned.

Otherwise, an application URL generated by Plek will be returned.

Parameters:

  • var (String)

    the name of the variable to look up

  • url (String)

    the url to default to if there is no environment variable set

Returns:

  • (String)

    the URL



90
91
92
# File 'lib/govuk_personalisation/urls.rb', line 90

def self.find_external_url(var:, url:)
  ENV.fetch("GOVUK_PERSONALISATION_#{var}_URI", url)
end

.find_govuk_url(var:, application:, path:) ⇒ String

Finds a URL on www.gov.uk. This method is used so we can have links which work both in production (where the website root is returned) and in local development (where an application URL is returned).

If ‘GOVUK_PERSONALISATION_#var_URI` is in the environment, that will be returned.

Otherwise, a ‘www.gov.uk` URL will be returned (a `dev.gov.uk` domain in development mode)

Parameters:

  • var (String)

    the name of the variable to look up

  • application (String)

    the name of the frontend application, passed to Plek, to use in development mode (if the env var is set, this is ignored)

  • path (String)

    the path to use (if the env var is set this is ignored)

Returns:

  • (String)

    the URL



69
70
71
72
73
74
75
76
77
# File 'lib/govuk_personalisation/urls.rb', line 69

def self.find_govuk_url(var:, application:, path:)
  value_from_env_var = ENV["GOVUK_PERSONALISATION_#{var}_URI"]
  if value_from_env_var
    value_from_env_var
  else
    plek_application_uri = Rails.env.development? ? Plek.find(application) : Plek.new.website_root
    "#{plek_application_uri}#{path}"
  end
end

.manageString

Find the external URL for the “manage” page

Returns:

  • (String)

    the URL



35
36
37
# File 'lib/govuk_personalisation/urls.rb', line 35

def self.manage
  find_external_url(var: "MANAGE", url: "https://#{digital_identity_domain}?link=manage-account")
end

.manage_emailString

Find the GOV.UK URL for the “email manager” page

Returns:

  • (String)

    the URL



21
22
23
# File 'lib/govuk_personalisation/urls.rb', line 21

def self.manage_email
  find_govuk_url(var: "SIGN_OUT", application: "email-alert-frontend", path: "/email/manage")
end

.securityString

Find the external URL for the “security” page

Returns:

  • (String)

    the URL



42
43
44
# File 'lib/govuk_personalisation/urls.rb', line 42

def self.security
  find_external_url(var: "SECURITY", url: "https://#{digital_identity_domain}?link=security-privacy")
end

.sign_inString

Find the GOV.UK URL for the “sign in” page

Returns:

  • (String)

    the URL



7
8
9
# File 'lib/govuk_personalisation/urls.rb', line 7

def self.
  find_govuk_url(var: "SIGN_IN", application: "frontend", path: "/account")
end

.sign_outString

Find the GOV.UK URL for the “sign out” page

Returns:

  • (String)

    the URL



14
15
16
# File 'lib/govuk_personalisation/urls.rb', line 14

def self.sign_out
  find_govuk_url(var: "SIGN_OUT", application: "frontend", path: "/sign-out")
end

.your_accountString

Find the external URL for the “your account” page

Returns:

  • (String)

    the URL



28
29
30
# File 'lib/govuk_personalisation/urls.rb', line 28

def self.
  find_external_url(var: "YOUR_ACCOUNT", url: "https://#{digital_identity_domain}")
end