Module: GovukPersonalisation::Urls

Defined in:
lib/govuk_personalisation/urls.rb

Constant Summary collapse

DIGITAL_IDENTITY_ENVIRONMENT_MAP =

DI/One Login’s environments don’t map exactly to ours - their staging points to our integration and vice versa. So translate here.

{
  "production" => "production",
  "staging" => "integration",
  "integration" => "staging",
}.freeze

Class Method Summary collapse

Class Method Details

.digital_identity_domain(host) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/govuk_personalisation/urls.rb', line 103

def self.digital_identity_domain(host)
  if ["production", nil].include?(digital_identity_environment)
    "#{host}.account.gov.uk"
  else
    "#{host}.#{digital_identity_environment}.account.gov.uk"
  end
end

.digital_identity_environmentObject



119
120
121
122
123
# File 'lib/govuk_personalisation/urls.rb', line 119

def self.digital_identity_environment
  return ENV["DIGITAL_IDENTITY_ENVIRONMENT"] if ENV["DIGITAL_IDENTITY_ENVIRONMENT"]

  DIGITAL_IDENTITY_ENVIRONMENT_MAP[ENV["GOVUK_ENVIRONMENT"]] || ENV["GOVUK_ENVIRONMENT"]
end

.feedbackObject



58
59
60
# File 'lib/govuk_personalisation/urls.rb', line 58

def self.feedback
  
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



99
100
101
# File 'lib/govuk_personalisation/urls.rb', line 99

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



78
79
80
81
82
83
84
85
86
# File 'lib/govuk_personalisation/urls.rb', line 78

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

.manageObject



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

def self.manage
  
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

.one_login_feedbackString

Find the external URL for the “feedback” page on One Login

Returns:

  • (String)

    the URL



54
55
56
# File 'lib/govuk_personalisation/urls.rb', line 54

def self.
  find_external_url(var: "ONE_LOGIN_FEEDBACK", url: "https://#{digital_identity_domain('signin')}/support?supportType=PUBLIC")
end

.one_login_securityString

Find the external URL for the “security” page on One Login

Returns:

  • (String)

    the URL



39
40
41
# File 'lib/govuk_personalisation/urls.rb', line 39

def self.
  find_external_url(var: "ONE_LOGIN_SECURITY", url: "https://#{digital_identity_domain('home')}/security")
end

.one_login_your_servicesString

Find the external URL for the “your services” page on One Login

Returns:

  • (String)

    the URL



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

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

.securityObject



47
48
49
# File 'lib/govuk_personalisation/urls.rb', line 47

def self.security
  
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_accountObject



32
33
34
# File 'lib/govuk_personalisation/urls.rb', line 32

def self.
  
end