govuk_personalisation 0.6.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '08b691342c4c22592162f9eb11e8c8f74b8fea75af5669568c71d15337166626'
4
- data.tar.gz: 0e266ec1d1f91a7537ccef2c1a4398e90b4c0435546772d41877cfd34e9df092
3
+ metadata.gz: d966869deca66c3fbea1730d7b2478ca77bc019d499b824269a9456eeffa82d9
4
+ data.tar.gz: fc4735bde8c3077c1e8e2795e4deb496b2c7816bfe6006057b0c8e59ceb27196
5
5
  SHA512:
6
- metadata.gz: 5f265633173eee3b60e436c781ddb4047d849471cc1760d88e8c3e497a79d8a0fd188a4c3908feb33fecf3b8c2b171dbbc1ea7f08ed837fae2d58cfc5658ae35
7
- data.tar.gz: d90dc8a74720981e16d7d379939c08072806ead930d012bb40c1a57ac2e90ae3879a10d7fb0bfbe3d874d39c70312952d72c0c9eca452fd757906c253ecb402e
6
+ metadata.gz: 826c826f13b08be03d467655bab27bab323ec6b8823bdddc25b52f0d20906344ee4ece5c95a31bf7726e2aabdea0511b46934b5a37137d7e8788d496b570395f
7
+ data.tar.gz: a74b510d5f549e3d0cc9df6b533763d5ac9a3c9211e424f49372b705acb9bb64229f35794f0aadaeee5492d8108040a5780acdc9a8e4d5c7bb4cf54a88b4b979
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ # 0.10.0
2
+ - Add `url_with_analytics` helper to allow apps to access the URL used for `redirect_with_analytics` ([#22](https://github.com/alphagov/govuk_personalisation/pull/22))
3
+
4
+ # 0.9.0
5
+ - Add `redirect_with_analytics` helper, attaches _ga and cookie_consent values from existing params to redirects. ([#19](https://github.com/alphagov/govuk_personalisation/pull/19))
6
+ - Add `GovukPersonalisation::Redirect` and `.build_url` helper to construct valid URLs with additional parameters. ([#19](https://github.com/alphagov/govuk_personalisation/pull/19))
7
+
8
+ # 0.8.0
9
+
10
+ - Change sign in path to `/sign-in/redirect` ([#17](https://github.com/alphagov/govuk_personalisation/pull/17))
11
+
12
+ # 0.7.0
13
+
14
+ - Add `GovukPersonalisation::Urls` module ([#14](https://github.com/alphagov/govuk_personalisation/pull/14) [#16](https://github.com/alphagov/govuk_personalisation/pull/16))
15
+
1
16
  # 0.6.0
2
17
 
3
18
  - Add `GovukPersonalisation::Flash` and helper methods to the concern ([#9](https://github.com/alphagov/govuk_personalisation/pull/9))
@@ -25,9 +25,11 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = %w[lib]
27
27
 
28
+ spec.add_dependency "plek", ">= 1.9.0"
28
29
  spec.add_dependency "rails", "~> 6"
29
30
 
30
31
  spec.add_development_dependency "bundler"
32
+ spec.add_development_dependency "climate_control"
31
33
  spec.add_development_dependency "pry-byebug"
32
34
  spec.add_development_dependency "rake"
33
35
  spec.add_development_dependency "rspec-rails"
@@ -125,5 +125,21 @@ module GovukPersonalisation
125
125
  @new_account_flash = @account_flash.merge(@new_account_flash)
126
126
  set_account_session_header
127
127
  end
128
+
129
+ # Redirect to a URL adding parameters necessary for cross-domain analytics
130
+ # and cookie consent
131
+ #
132
+ # @param url [String] The URL to redirect to
133
+ def redirect_with_analytics(url)
134
+ redirect_to url_with_analytics(url)
135
+ end
136
+
137
+ # Build a URL adding parameters necessary for cross-domain analytics
138
+ # and cookie consent
139
+ #
140
+ # @param url [String] The URL
141
+ def url_with_analytics(url)
142
+ GovukPersonalisation::Redirect.build_url(url, params.permit(:_ga, :cookie_consent).to_h)
143
+ end
128
144
  end
129
145
  end
@@ -0,0 +1,23 @@
1
+ module GovukPersonalisation::Redirect
2
+ # Builds a URL with additional query parameters
3
+ #
4
+ # Allows for a simple method call to add params on to an existing
5
+ # URL, for instance when adding _ga tracking params to a redirect
6
+ #
7
+ # @param base_url [String] The URL to attach additional parameters to
8
+ # @param optional additional_params [Hash{String,Symbol => String}] additional parameters
9
+ # to be added to the URL. If empty, returns the base URL.
10
+ #
11
+ # @return [String] a new URL with additional parameters
12
+ def self.build_url(base_url, additional_params = {})
13
+ return base_url if additional_params.empty?
14
+
15
+ additional_query = additional_params.to_a.map { |param| param.join("=") }.join("&")
16
+
17
+ if base_url.include? "?"
18
+ "#{base_url}&#{additional_query}"
19
+ else
20
+ "#{base_url}?#{additional_query}"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,87 @@
1
+ require "plek"
2
+
3
+ module GovukPersonalisation::Urls
4
+ # Find the GOV.UK URL for the "sign in" page
5
+ #
6
+ # @return [String] the URL
7
+ def self.sign_in
8
+ find_govuk_url(var: "SIGN_IN", application: "frontend", path: "/sign-in/redirect")
9
+ end
10
+
11
+ # Find the GOV.UK URL for the "sign out" page
12
+ #
13
+ # @return [String] the URL
14
+ def self.sign_out
15
+ find_govuk_url(var: "SIGN_OUT", application: "frontend", path: "/sign-out")
16
+ end
17
+
18
+ # Find the GOV.UK URL for the "your account" page
19
+ #
20
+ # @return [String] the URL
21
+ def self.your_account
22
+ find_govuk_url(var: "YOUR_ACCOUNT", application: "frontend", path: "/account/home")
23
+ end
24
+
25
+ # Find the external URL for the "manage" page
26
+ #
27
+ # @return [String] the URL
28
+ def self.manage
29
+ find_external_url(var: "MANAGE", application: "account-manager", path: "/account/manage")
30
+ end
31
+
32
+ # Find the external URL for the "security" page
33
+ #
34
+ # @return [String] the URL
35
+ def self.security
36
+ find_external_url(var: "SECURITY", application: "account-manager", path: "/account/security")
37
+ end
38
+
39
+ # Find the external URL for the "feedback" page
40
+ #
41
+ # @return [String] the URL
42
+ def self.feedback
43
+ find_external_url(var: "FEEDBACK", application: "account-manager", path: "/feedback")
44
+ end
45
+
46
+ # Finds a URL on www.gov.uk. This method is used so we can have
47
+ # links which work both in production (where the website root is
48
+ # returned) and in local development (where an application URL is
49
+ # returned).
50
+ #
51
+ # If `GOVUK_PERSONALISATION_#{var}_URI` is in the environment, that
52
+ # will be returned.
53
+ #
54
+ # Otherwise, a `www.gov.uk` URL will be returned (a `dev.gov.uk`
55
+ # domain in development mode)
56
+ #
57
+ # @param var [String] the name of the variable to look up
58
+ # @param 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)
59
+ # @param path [String] the path to use (if the env var is set this is ignored)
60
+ #
61
+ # @return [String] the URL
62
+ def self.find_govuk_url(var:, application:, path:)
63
+ value_from_env_var = ENV["GOVUK_PERSONALISATION_#{var}_URI"]
64
+ if value_from_env_var
65
+ value_from_env_var
66
+ else
67
+ plek_application_uri = Rails.env.development? ? Plek.find(application) : Plek.new.website_root
68
+ "#{plek_application_uri}#{path}"
69
+ end
70
+ end
71
+
72
+ # Finds a URL outside www.gov.uk
73
+ #
74
+ # If `GOVUK_PERSONALISATION_#{var}_URI` is in the environment, that
75
+ # will be returned.
76
+ #
77
+ # Otherwise, an application URL generated by Plek will be returned.
78
+ #
79
+ # @param var [String] the name of the variable to look up
80
+ # @param application [String] the name of the frontend application, passed to Plek (if the env var is set, this is ignored)
81
+ # @param path [String] the path to use (if the env var is set this is ignored)
82
+ #
83
+ # @return [String] the URL
84
+ def self.find_external_url(var:, application:, path:)
85
+ ENV.fetch("GOVUK_PERSONALISATION_#{var}_URI", "#{Plek.find(application)}#{path}")
86
+ end
87
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GovukPersonalisation
4
- VERSION = "0.6.0"
4
+ VERSION = "0.10.0"
5
5
  end
@@ -3,7 +3,9 @@
3
3
  require "govuk_personalisation/version"
4
4
  require "govuk_personalisation/controller_concern"
5
5
  require "govuk_personalisation/flash"
6
+ require "govuk_personalisation/redirect"
6
7
  require "govuk_personalisation/test_helpers/features"
7
8
  require "govuk_personalisation/test_helpers/requests"
9
+ require "govuk_personalisation/urls"
8
10
 
9
11
  module GovukPersonalisation; end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_personalisation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-06 00:00:00.000000000 Z
11
+ date: 2021-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: plek
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.9.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.9.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rails
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +52,20 @@ dependencies:
38
52
  - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: climate_control
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: pry-byebug
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -118,8 +146,10 @@ files:
118
146
  - lib/govuk_personalisation.rb
119
147
  - lib/govuk_personalisation/controller_concern.rb
120
148
  - lib/govuk_personalisation/flash.rb
149
+ - lib/govuk_personalisation/redirect.rb
121
150
  - lib/govuk_personalisation/test_helpers/features.rb
122
151
  - lib/govuk_personalisation/test_helpers/requests.rb
152
+ - lib/govuk_personalisation/urls.rb
123
153
  - lib/govuk_personalisation/version.rb
124
154
  homepage: https://github.com/alphagov/govuk_personalisation
125
155
  licenses: