gds-api-adapters 74.0.0 → 75.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gds_api/account_api.rb +18 -43
- data/lib/gds_api/email_alert_api.rb +3 -2
- data/lib/gds_api/test_helpers/account_api.rb +41 -141
- data/lib/gds_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 207e19a65d19c45b030d88ccc1028e781def6a120dfedcc725615628b7d2f35d
|
4
|
+
data.tar.gz: a838e9f19dc4e7f8b45017aacd0fae259f1cb353ee44356c8c34066054fb1ea1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d95b69e442c280cf3fbe5fa84dbfc1d16e9462a1c160f0678d7cd78b8a1f0426b4a5878eac6e78a5755f5eff27b293f1832b5d4a35a0958c5aed50d86bee1736
|
7
|
+
data.tar.gz: c167d604668e3685b63c6d83e7a09d6332bd40b2099fa7f4d9afd29d482aa240eef8398b67a0e8aeced29fde34847fe0a3f28d980d7da571cb63efb5b3b251c8
|
data/lib/gds_api/account_api.rb
CHANGED
@@ -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,20 @@ 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
78
|
# @param [Boolean, nil] has_unconfirmed_email Whether the user has a new, pending, email address
|
79
|
+
# @param [Boolean, nil] cookie_consent Whether the user has consented to analytics cookies
|
80
|
+
# @param [Boolean, nil] feedback_consent Whether the user has consented to being contacted for feedback
|
68
81
|
#
|
69
82
|
# @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)
|
83
|
+
def update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, has_unconfirmed_email: nil, cookie_consent: nil, feedback_consent: nil)
|
71
84
|
params = {
|
72
85
|
email: email,
|
73
86
|
email_verified: email_verified,
|
74
87
|
has_unconfirmed_email: has_unconfirmed_email,
|
88
|
+
cookie_consent: cookie_consent,
|
89
|
+
feedback_consent: feedback_consent,
|
75
90
|
}.compact
|
76
91
|
|
77
92
|
patch_json("#{endpoint}/api/oidc-users/#{subject_identifier}", params)
|
@@ -127,46 +142,6 @@ class GdsApi::AccountApi < GdsApi::Base
|
|
127
142
|
delete_json("#{endpoint}/api/email-subscriptions/#{CGI.escape(name)}", {}, auth_headers(govuk_account_session))
|
128
143
|
end
|
129
144
|
|
130
|
-
# Look up all pages saved by a user in their Account
|
131
|
-
#
|
132
|
-
# @param [String] govuk_account_session Value of the session header
|
133
|
-
#
|
134
|
-
# @return [Hash] containing :saved_pages, an array of single saved page hashes
|
135
|
-
def get_saved_pages(govuk_account_session:)
|
136
|
-
get_json("#{endpoint}/api/saved-pages", auth_headers(govuk_account_session))
|
137
|
-
end
|
138
|
-
|
139
|
-
# Return a single page by unique URL
|
140
|
-
#
|
141
|
-
# @param [String] the path of a page to check
|
142
|
-
# @param [String] govuk_account_session Value of the session header
|
143
|
-
#
|
144
|
-
# @return [Hash] containing :saved_page, a hash of a single saved page value
|
145
|
-
def get_saved_page(page_path:, govuk_account_session:)
|
146
|
-
get_json("#{endpoint}/api/saved-pages/#{CGI.escape(page_path)}", auth_headers(govuk_account_session))
|
147
|
-
end
|
148
|
-
|
149
|
-
# Upsert a single saved page entry in a users account
|
150
|
-
#
|
151
|
-
# @param [String] the path of a page to check
|
152
|
-
# @param [String] govuk_account_session Value of the session header
|
153
|
-
#
|
154
|
-
# @return [Hash] A single saved page value (if sucessful)
|
155
|
-
def save_page(page_path:, govuk_account_session:)
|
156
|
-
put_json("#{endpoint}/api/saved-pages/#{CGI.escape(page_path)}", {}, auth_headers(govuk_account_session))
|
157
|
-
end
|
158
|
-
|
159
|
-
# Delete a single saved page entry from a users account
|
160
|
-
#
|
161
|
-
# @param [String] the path of a page to check
|
162
|
-
# @param [String] govuk_account_session Value of the session header
|
163
|
-
#
|
164
|
-
# @return [GdsApi::Response] A status code of 204 indicates the saved page has been successfully deleted.
|
165
|
-
# A status code of 404 indicates there is no saved page with this path.
|
166
|
-
def delete_saved_page(page_path:, govuk_account_session:)
|
167
|
-
delete_json("#{endpoint}/api/saved-pages/#{CGI.escape(page_path)}", {}, auth_headers(govuk_account_session))
|
168
|
-
end
|
169
|
-
|
170
145
|
private
|
171
146
|
|
172
147
|
def nested_query_string(params)
|
@@ -174,6 +149,6 @@ private
|
|
174
149
|
end
|
175
150
|
|
176
151
|
def auth_headers(govuk_account_session)
|
177
|
-
{ AUTH_HEADER_NAME => govuk_account_session }
|
152
|
+
{ AUTH_HEADER_NAME => govuk_account_session }.compact
|
178
153
|
end
|
179
154
|
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
|
-
|
14
|
-
|
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
|
|
@@ -102,6 +102,41 @@ module GdsApi
|
|
102
102
|
)
|
103
103
|
end
|
104
104
|
|
105
|
+
##############################
|
106
|
+
# GET /api/user/match-by-email
|
107
|
+
##############################
|
108
|
+
|
109
|
+
def stub_account_api_match_user_by_email_matches(email:, **options)
|
110
|
+
stub_account_api_request(
|
111
|
+
:get,
|
112
|
+
"/api/user/match-by-email?#{Rack::Utils.build_nested_query({ email: email })}",
|
113
|
+
response_body: {
|
114
|
+
match: true,
|
115
|
+
},
|
116
|
+
**options,
|
117
|
+
)
|
118
|
+
end
|
119
|
+
|
120
|
+
def stub_account_api_match_user_by_email_does_not_match(email:, **options)
|
121
|
+
stub_account_api_request(
|
122
|
+
:get,
|
123
|
+
"/api/user/match-by-email?#{Rack::Utils.build_nested_query({ email: email })}",
|
124
|
+
response_body: {
|
125
|
+
match: false,
|
126
|
+
},
|
127
|
+
**options,
|
128
|
+
)
|
129
|
+
end
|
130
|
+
|
131
|
+
def stub_account_api_match_user_by_email_does_not_exist(email:, **options)
|
132
|
+
stub_account_api_request(
|
133
|
+
:get,
|
134
|
+
"/api/user/match-by-email?#{Rack::Utils.build_nested_query({ email: email })}",
|
135
|
+
response_status: 404,
|
136
|
+
**options,
|
137
|
+
)
|
138
|
+
end
|
139
|
+
|
105
140
|
############################################
|
106
141
|
# DELETE /api/oidc-users/:subject_identifier
|
107
142
|
############################################
|
@@ -125,16 +160,18 @@ module GdsApi
|
|
125
160
|
###########################################
|
126
161
|
# PATCH /api/oidc-users/:subject_identifier
|
127
162
|
###########################################
|
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)
|
163
|
+
def stub_update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, has_unconfirmed_email: nil, cookie_consent: nil, feedback_consent: nil, old_email: nil, old_email_verified: nil, old_has_unconfirmed_email: nil, old_cookie_consent: nil, old_feedback_consent: nil)
|
129
164
|
stub_account_api_request(
|
130
165
|
:patch,
|
131
166
|
"/api/oidc-users/#{subject_identifier}",
|
132
|
-
with: { body: hash_including({ email: email, email_verified: email_verified, has_unconfirmed_email: has_unconfirmed_email }.compact) },
|
167
|
+
with: { body: hash_including({ email: email, email_verified: email_verified, has_unconfirmed_email: has_unconfirmed_email, cookie_consent: cookie_consent, feedback_consent: feedback_consent }.compact) },
|
133
168
|
response_body: {
|
134
169
|
sub: subject_identifier,
|
135
170
|
email: email || old_email,
|
136
171
|
email_verified: email_verified || old_email_verified,
|
137
172
|
has_unconfirmed_email: has_unconfirmed_email || old_has_unconfirmed_email,
|
173
|
+
cookie_consent: cookie_consent || old_cookie_consent,
|
174
|
+
feedback_consent: feedback_consent || old_feedback_consent,
|
138
175
|
},
|
139
176
|
)
|
140
177
|
end
|
@@ -297,143 +334,6 @@ module GdsApi
|
|
297
334
|
**options,
|
298
335
|
)
|
299
336
|
end
|
300
|
-
|
301
|
-
######################
|
302
|
-
# GET /api/saved-pages
|
303
|
-
######################
|
304
|
-
def stub_account_api_returning_saved_pages(saved_pages: [], **options)
|
305
|
-
stub_account_api_request(
|
306
|
-
:get,
|
307
|
-
"/api/saved-pages",
|
308
|
-
response_body: { saved_pages: saved_pages },
|
309
|
-
**options,
|
310
|
-
)
|
311
|
-
end
|
312
|
-
|
313
|
-
def stub_account_api_unauthorized_get_saved_pages(**options)
|
314
|
-
stub_account_api_request(
|
315
|
-
:get,
|
316
|
-
"/api/saved-pages",
|
317
|
-
response_status: 401,
|
318
|
-
**options,
|
319
|
-
)
|
320
|
-
end
|
321
|
-
|
322
|
-
#################################
|
323
|
-
# GET /api/saved_pages/:page_path
|
324
|
-
#################################
|
325
|
-
def stub_account_api_get_saved_page(page_path:, content_id: "46163ed2-1777-4ee6-bdd4-6a2007e49d8f", title: "Ministry of Magic", **options)
|
326
|
-
stub_account_api_request(
|
327
|
-
:get,
|
328
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
329
|
-
response_body: {
|
330
|
-
saved_page: {
|
331
|
-
page_path: page_path,
|
332
|
-
content_id: content_id,
|
333
|
-
title: title,
|
334
|
-
},
|
335
|
-
},
|
336
|
-
**options,
|
337
|
-
)
|
338
|
-
end
|
339
|
-
|
340
|
-
def stub_account_api_does_not_have_saved_page(page_path:, **options)
|
341
|
-
stub_account_api_request(
|
342
|
-
:get,
|
343
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
344
|
-
response_status: 404,
|
345
|
-
**options,
|
346
|
-
)
|
347
|
-
end
|
348
|
-
|
349
|
-
def stub_account_api_unauthorized_get_saved_page(page_path:, **options)
|
350
|
-
stub_account_api_request(
|
351
|
-
:get,
|
352
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
353
|
-
response_status: 401,
|
354
|
-
**options,
|
355
|
-
)
|
356
|
-
end
|
357
|
-
|
358
|
-
#################################
|
359
|
-
# PUT /api/saved-pages/:page_path
|
360
|
-
#################################
|
361
|
-
def stub_account_api_save_page(page_path:, content_id: "c840bfa2-011a-42cc-ac7a-a6da990aff0b", title: "Ministry of Magic", **options)
|
362
|
-
stub_account_api_request(
|
363
|
-
:put,
|
364
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
365
|
-
response_body: {
|
366
|
-
saved_page: {
|
367
|
-
page_path: page_path,
|
368
|
-
content_id: content_id,
|
369
|
-
title: title,
|
370
|
-
},
|
371
|
-
},
|
372
|
-
**options,
|
373
|
-
)
|
374
|
-
end
|
375
|
-
|
376
|
-
def stub_account_api_save_page_already_exists(page_path:, **options)
|
377
|
-
stub_account_api_save_page(page_path: page_path, **options)
|
378
|
-
end
|
379
|
-
|
380
|
-
def stub_account_api_save_page_cannot_save_page(page_path:, **options)
|
381
|
-
stub_account_api_request(
|
382
|
-
:put,
|
383
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
384
|
-
response_status: 422,
|
385
|
-
response_body: cannot_save_page_problem_detail({ page_path: page_path }),
|
386
|
-
**options,
|
387
|
-
)
|
388
|
-
end
|
389
|
-
|
390
|
-
def stub_account_api_unauthorized_save_page(page_path:, **options)
|
391
|
-
stub_account_api_request(
|
392
|
-
:put,
|
393
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
394
|
-
response_status: 401,
|
395
|
-
**options,
|
396
|
-
)
|
397
|
-
end
|
398
|
-
|
399
|
-
def cannot_save_page_problem_detail(option = {})
|
400
|
-
{
|
401
|
-
title: "Cannot save page",
|
402
|
-
detail: "Cannot save page with path #{option['page_path']}, check it is not blank, and is a well formatted url path.",
|
403
|
-
type: "https://github.com/alphagov/account-api/blob/main/docs/api.md#cannot-save-page",
|
404
|
-
**option,
|
405
|
-
}
|
406
|
-
end
|
407
|
-
|
408
|
-
####################################
|
409
|
-
# DELETE /api/saved-pages/:page_path
|
410
|
-
####################################
|
411
|
-
def stub_account_api_delete_saved_page(page_path:, **options)
|
412
|
-
stub_account_api_request(
|
413
|
-
:delete,
|
414
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
415
|
-
response_status: 204,
|
416
|
-
**options,
|
417
|
-
)
|
418
|
-
end
|
419
|
-
|
420
|
-
def stub_account_api_delete_saved_page_does_not_exist(page_path:, **options)
|
421
|
-
stub_account_api_request(
|
422
|
-
:delete,
|
423
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
424
|
-
response_status: 404,
|
425
|
-
**options,
|
426
|
-
)
|
427
|
-
end
|
428
|
-
|
429
|
-
def stub_account_api_unauthorized_delete_saved_page(page_path:, **options)
|
430
|
-
stub_account_api_request(
|
431
|
-
:delete,
|
432
|
-
"/api/saved-pages/#{CGI.escape(page_path)}",
|
433
|
-
response_status: 401,
|
434
|
-
**options,
|
435
|
-
)
|
436
|
-
end
|
437
337
|
end
|
438
338
|
end
|
439
339
|
end
|
data/lib/gds_api/version.rb
CHANGED
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:
|
4
|
+
version: 75.3.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-
|
11
|
+
date: 2021-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|