gds-api-adapters 75.0.0 → 76.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 836544dd1d7130e6ba4f035b660be34e3b108b8ed16f93882cbeb3ee48ea2e6c
4
- data.tar.gz: 6052c7b0b52ad0bf354b8b97e42fc7e90c98a1ceed2253a8fc501cd4e10b0a6e
3
+ metadata.gz: c6fbbdd523fc7bf5afd6d23497c1adffa0c61d5cc0d836f377e7f836164cb886
4
+ data.tar.gz: cfeb1598eb0ef9409be473c362f682d72c0b4e26ba0889b596bb037a8327593f
5
5
  SHA512:
6
- metadata.gz: 220248bfb16db073e03b98e675278f9776eaa5965010ae737a829a352eb0baf9be23630d3eeec10288397341f6ded0bd4da53a94c70fcf53a09843d64c1bee83
7
- data.tar.gz: f0be992cf2e9324bcefafcbf167f5959d6e993ba9e8530d109785c3868e0961d77b16dd57ec48ac3176688d0dde5c608b7b82d75a8b53626d0ee942ff27294ba
6
+ metadata.gz: dc9c4199017d1f929c9a061767585ffc8dc4d49dcb70606f7e32336683f4061be6e00f1c265aed8c9f52a0761028f4da35527abccf30d5a3b8ebe98c2991eb34
7
+ data.tar.gz: 9d87aa59e50a159dac97564245334a132b6550bd946eace9260177882bafee15a82e1992fe7fb99708fdaf813c0f723fb15e971660315b58c5e309f5eaf073de
@@ -52,6 +52,17 @@ class GdsApi::AccountApi < GdsApi::Base
52
52
  get_json("#{endpoint}/api/user", auth_headers(govuk_account_session))
53
53
  end
54
54
 
55
+ # Find a user by email address, returning whether they match the given session (if any)
56
+ #
57
+ # @param [String] email The email address to search for
58
+ # @param [String, nil] govuk_account_session Value of the session header, if not given just checks if the given email address exists.
59
+ #
60
+ # @return [Hash] One field, "match", indicating whether the session matches the given email address
61
+ def match_user_by_email(email:, govuk_account_session: nil)
62
+ querystring = nested_query_string({ email: email })
63
+ get_json("#{endpoint}/api/user/match-by-email?#{querystring}", auth_headers(govuk_account_session))
64
+ end
65
+
55
66
  # Delete a users account
56
67
  #
57
68
  # @param [String] subject_identifier The identifier of the user, shared between the auth service and GOV.UK.
@@ -62,16 +73,18 @@ class GdsApi::AccountApi < GdsApi::Base
62
73
  # Update the user record with privileged information from the auth service. Only the auth service will call this.
63
74
  #
64
75
  # @param [String] subject_identifier The identifier of the user, shared between the auth service and GOV.UK.
65
- # @param [String, nil] email The user's current
76
+ # @param [String, nil] email The user's current email address
66
77
  # @param [Boolean, nil] email_verified Whether the user's current email address is verified
67
- # @param [Boolean, nil] has_unconfirmed_email Whether the user has a new, pending, email address
78
+ # @param [Boolean, nil] cookie_consent Whether the user has consented to analytics cookies
79
+ # @param [Boolean, nil] feedback_consent Whether the user has consented to being contacted for feedback
68
80
  #
69
81
  # @return [Hash] The user's subject identifier and email attributes
70
- def update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, has_unconfirmed_email: nil)
82
+ def update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, cookie_consent: nil, feedback_consent: nil)
71
83
  params = {
72
84
  email: email,
73
85
  email_verified: email_verified,
74
- has_unconfirmed_email: has_unconfirmed_email,
86
+ cookie_consent: cookie_consent,
87
+ feedback_consent: feedback_consent,
75
88
  }.compact
76
89
 
77
90
  patch_json("#{endpoint}/api/oidc-users/#{subject_identifier}", params)
@@ -134,6 +147,6 @@ private
134
147
  end
135
148
 
136
149
  def auth_headers(govuk_account_session)
137
- { AUTH_HEADER_NAME => govuk_account_session }
150
+ { AUTH_HEADER_NAME => govuk_account_session }.compact
138
151
  end
139
152
  end
@@ -10,8 +10,9 @@ class GdsApi::EmailAlertApi < GdsApi::Base
10
10
  #
11
11
  # @param attributes [Hash] document_type, links, tags used to search existing subscriber lists
12
12
  def find_or_create_subscriber_list(attributes)
13
- if attributes["tags"] && attributes["links"]
14
- message = "please provide either tags or links (or neither), but not both"
13
+ present_fields = [attributes["content_id"], attributes["links"], attributes["tags"]].compact.count
14
+ if present_fields > 1
15
+ message = "please provide content_id, tags, or links (or none), but not more than one of them"
15
16
  raise ArgumentError, message
16
17
  end
17
18
 
@@ -31,12 +31,12 @@ module GdsApi
31
31
  ###########################
32
32
  # POST /api/oauth2/callback
33
33
  ###########################
34
- def stub_account_api_validates_auth_response(code: nil, state: nil, govuk_account_session: "govuk-account-session", redirect_path: "/", ga_client_id: "ga-client-id", cookie_consent: false)
34
+ def stub_account_api_validates_auth_response(code: nil, state: nil, govuk_account_session: "govuk-account-session", redirect_path: "/", ga_client_id: "ga-client-id", cookie_consent: false, feedback_consent: false)
35
35
  stub_request(:post, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/callback")
36
36
  .with(body: hash_including({ code: code, state: state }.compact))
37
37
  .to_return(
38
38
  status: 200,
39
- body: { govuk_account_session: govuk_account_session, redirect_path: redirect_path, ga_client_id: ga_client_id, cookie_consent: cookie_consent }.to_json,
39
+ body: { govuk_account_session: govuk_account_session, redirect_path: redirect_path, ga_client_id: ga_client_id, cookie_consent: cookie_consent, feedback_consent: feedback_consent }.to_json,
40
40
  )
41
41
  end
42
42
 
@@ -69,7 +69,7 @@ module GdsApi
69
69
  ###############
70
70
  # GET /api/user
71
71
  ###############
72
- def stub_account_api_user_info(id: "user-id", mfa: false, email: "email@example.com", email_verified: true, has_unconfirmed_email: false, services: {}, **options)
72
+ def stub_account_api_user_info(id: "user-id", mfa: false, email: "email@example.com", email_verified: true, services: {}, **options)
73
73
  stub_account_api_request(
74
74
  :get,
75
75
  "/api/user",
@@ -78,7 +78,6 @@ module GdsApi
78
78
  mfa: mfa,
79
79
  email: email,
80
80
  email_verified: email_verified,
81
- has_unconfirmed_email: has_unconfirmed_email,
82
81
  services: services,
83
82
  },
84
83
  **options,
@@ -102,6 +101,41 @@ module GdsApi
102
101
  )
103
102
  end
104
103
 
104
+ ##############################
105
+ # GET /api/user/match-by-email
106
+ ##############################
107
+
108
+ def stub_account_api_match_user_by_email_matches(email:, **options)
109
+ stub_account_api_request(
110
+ :get,
111
+ "/api/user/match-by-email?#{Rack::Utils.build_nested_query({ email: email })}",
112
+ response_body: {
113
+ match: true,
114
+ },
115
+ **options,
116
+ )
117
+ end
118
+
119
+ def stub_account_api_match_user_by_email_does_not_match(email:, **options)
120
+ stub_account_api_request(
121
+ :get,
122
+ "/api/user/match-by-email?#{Rack::Utils.build_nested_query({ email: email })}",
123
+ response_body: {
124
+ match: false,
125
+ },
126
+ **options,
127
+ )
128
+ end
129
+
130
+ def stub_account_api_match_user_by_email_does_not_exist(email:, **options)
131
+ stub_account_api_request(
132
+ :get,
133
+ "/api/user/match-by-email?#{Rack::Utils.build_nested_query({ email: email })}",
134
+ response_status: 404,
135
+ **options,
136
+ )
137
+ end
138
+
105
139
  ############################################
106
140
  # DELETE /api/oidc-users/:subject_identifier
107
141
  ############################################
@@ -125,16 +159,17 @@ module GdsApi
125
159
  ###########################################
126
160
  # PATCH /api/oidc-users/:subject_identifier
127
161
  ###########################################
128
- def stub_update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, has_unconfirmed_email: nil, old_email: nil, old_email_verified: nil, old_has_unconfirmed_email: nil)
162
+ def stub_update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, cookie_consent: nil, feedback_consent: nil, old_email: nil, old_email_verified: nil, old_cookie_consent: nil, old_feedback_consent: nil)
129
163
  stub_account_api_request(
130
164
  :patch,
131
165
  "/api/oidc-users/#{subject_identifier}",
132
- with: { body: hash_including({ email: email, email_verified: email_verified, has_unconfirmed_email: has_unconfirmed_email }.compact) },
166
+ with: { body: hash_including({ email: email, email_verified: email_verified, cookie_consent: cookie_consent, feedback_consent: feedback_consent }.compact) },
133
167
  response_body: {
134
168
  sub: subject_identifier,
135
169
  email: email || old_email,
136
170
  email_verified: email_verified || old_email_verified,
137
- has_unconfirmed_email: has_unconfirmed_email || old_has_unconfirmed_email,
171
+ cookie_consent: cookie_consent || old_cookie_consent,
172
+ feedback_consent: feedback_consent || old_feedback_consent,
138
173
  },
139
174
  )
140
175
  end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = "75.0.0".freeze
2
+ VERSION = "76.0.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 75.0.0
4
+ version: 76.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-28 00:00:00.000000000 Z
11
+ date: 2021-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable