govuk_personalisation 0.1.0 → 0.2.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: 922a14712a1ece8f373a38c9671ef7341d0276c5cbb0b3cb5dc71d34d44aa8a8
4
- data.tar.gz: f4c5e2bcd60c9dfe75a568adb6f2f1a1729c7c674e08c86a6666c6413382aee7
3
+ metadata.gz: 4f19f176c2aa1874082e94b2798bc865b4b612ec92682ba41d8b6ed386239543
4
+ data.tar.gz: 50c849e85a7d2115316c7db368e16f2c15649f82265b1a2c87a787aae49018e1
5
5
  SHA512:
6
- metadata.gz: 98a278d857beb6ab8f4da47699f6ee8fe0f53366f6727f6eb488b36cdfe46a3ac9873dad4a7dd99660df69d8bad2bd10ffa51b7306affa53ecda79d9f7186526
7
- data.tar.gz: 7476b8a28b809bb65f1079bcbc1458d11bfdc0fa588c0e89041fe91229b2635efbd4b6d16dd7c8e30c4f73c23d54fb7be7e7a77185c124ed7b0187bb9e33458e
6
+ metadata.gz: e9ddd7d63d119782c1a8663ba076f233881dbfd04fadd9007d53afaaa68555145a10c30e1a0e2e04f65867d79c13ba662a9febb0e2ba4ba657bf056056efa6f2
7
+ data.tar.gz: '02950b7e918f99b08f2cbeeec51da89e8aeaaa7be115250c4e918aebf0a06e6fb7768c59cf208f20dc17c11c7edf346fcc2edbe1c4ff9a3c2caabad9673d4941'
data/.gitignore CHANGED
@@ -3,10 +3,16 @@
3
3
  /_yardoc/
4
4
  /coverage/
5
5
  /doc/
6
+ /log/*.log
6
7
  /pkg/
7
8
  /spec/reports/
8
9
  /tmp/
10
+
11
+ /spec/test_app/log/*.log
12
+ /spec/test_app/storage/
13
+ /spec/test_app/tmp/
14
+
9
15
  Gemfile.lock
10
16
 
11
17
  # rspec failure tracking
12
- .rspec_status
18
+ /spec/examples.txt
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.3
1
+ 2.6.6
data/CHANGELOG.md CHANGED
@@ -1,4 +1,6 @@
1
- ## [Unreleased]
1
+ ## [0.2.0]
2
+
3
+ - Add AccountConcern to extract common account-related functionality ([#3](https://github.com/alphagov/govuk_personalisation/pull/3))
2
4
 
3
5
  ## [0.1.0] - 2021-05-12
4
6
 
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.description = "A gem to hold shared code which other GOV.UK apps will use to implement accounts-related functionality."
15
15
  spec.homepage = "https://github.com/alphagov/govuk_personalisation"
16
16
  spec.license = "MIT"
17
- spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
17
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.6")
18
18
 
19
19
  # Specify which files should be added to the gem when it is released.
20
20
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "govuk_personalisation/version"
4
+ require "govuk_personalisation/account_concern"
4
5
 
5
6
  module GovukPersonalisation
6
7
  class Error < StandardError; end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module GovukPersonalisation
6
+ module AccountConcern
7
+ extend ActiveSupport::Concern
8
+
9
+ ACCOUNT_SESSION_REQUEST_HEADER_NAME = "HTTP_GOVUK_ACCOUNT_SESSION"
10
+ ACCOUNT_SESSION_RESPONSE_HEADER_NAME = "GOVUK-Account-Session"
11
+ ACCOUNT_END_SESSION_RESPONSE_HEADER_NAME = "GOVUK-Account-End-Session"
12
+ ACCOUNT_SESSION_DEV_COOKIE_NAME = "govuk_account_session"
13
+
14
+ included do
15
+ before_action :fetch_account_session_header
16
+ attr_accessor :account_session_header
17
+ end
18
+
19
+ def logged_in?
20
+ account_session_header.present?
21
+ end
22
+
23
+ def fetch_account_session_header
24
+ @account_session_header =
25
+ if request.headers[ACCOUNT_SESSION_REQUEST_HEADER_NAME]
26
+ request.headers[ACCOUNT_SESSION_REQUEST_HEADER_NAME].presence
27
+ elsif Rails.env.development?
28
+ cookies[ACCOUNT_SESSION_DEV_COOKIE_NAME]
29
+ end
30
+ end
31
+
32
+ def set_account_session_header(govuk_account_session = nil)
33
+ @account_session_header = govuk_account_session if govuk_account_session
34
+ response.headers[ACCOUNT_SESSION_RESPONSE_HEADER_NAME] = @account_session_header
35
+ if Rails.env.development?
36
+ cookies[ACCOUNT_SESSION_DEV_COOKIE_NAME] = {
37
+ value: @account_session_header,
38
+ domain: "dev.gov.uk",
39
+ }
40
+ end
41
+ end
42
+
43
+ def logout!
44
+ response.headers[ACCOUNT_END_SESSION_RESPONSE_HEADER_NAME] = "1"
45
+ @account_session_header = nil
46
+ if Rails.env.development?
47
+ cookies[ACCOUNT_SESSION_DEV_COOKIE_NAME] = {
48
+ value: "",
49
+ domain: "dev.gov.uk",
50
+ expires: 1.second.ago,
51
+ }
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GovukPersonalisation
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_personalisation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.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-05-26 00:00:00.000000000 Z
11
+ date: 2021-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -116,6 +116,7 @@ files:
116
116
  - bin/setup
117
117
  - govuk_personalisation.gemspec
118
118
  - lib/govuk_personalisation.rb
119
+ - lib/govuk_personalisation/account_concern.rb
119
120
  - lib/govuk_personalisation/version.rb
120
121
  homepage: https://github.com/alphagov/govuk_personalisation
121
122
  licenses:
@@ -129,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
130
  requirements:
130
131
  - - ">="
131
132
  - !ruby/object:Gem::Version
132
- version: 2.4.0
133
+ version: 2.6.6
133
134
  required_rubygems_version: !ruby/object:Gem::Requirement
134
135
  requirements:
135
136
  - - ">="