gds-api-adapters 75.2.0 → 77.1.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 +4 -4
- data/lib/gds_api/account_api.rb +14 -9
- data/lib/gds_api/email_alert_api.rb +19 -2
- data/lib/gds_api/test_helpers/account_api.rb +38 -7
- data/lib/gds_api/test_helpers/email_alert_api.rb +47 -0
- 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: 4ae9935a6f00ed43737c077e942ba2fb89deff13e02bac93917b1db6215162d2
|
4
|
+
data.tar.gz: 0c7da0e74c80afc296468a98cd79f11f357957b12ba9ed90247c2d2ac0b0aff0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0279189027b025193a9340b849a3fea6c682563af8affbf73ebdae40a83f4aecbaa878b039d6d23311bda729c7ab7fb94f1fa6b9739e867ac44136830f145c0e'
|
7
|
+
data.tar.gz: dc55f3c73fb2c1e45ac97dcd74581f3c52701186ca7f96171abbea8178d6721629f1c6deee08e7dce3d68bcf5277544f2bced1189fa9bbeb49f2b179d0da14af
|
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,20 +73,14 @@ 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
|
68
|
-
# @param [Boolean, nil] cookie_consent Whether the user has consented to analytics cookies
|
69
|
-
# @param [Boolean, nil] feedback_consent Whether the user has consented to being contacted for feedback
|
70
78
|
#
|
71
79
|
# @return [Hash] The user's subject identifier and email attributes
|
72
|
-
def update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil
|
80
|
+
def update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil)
|
73
81
|
params = {
|
74
82
|
email: email,
|
75
83
|
email_verified: email_verified,
|
76
|
-
has_unconfirmed_email: has_unconfirmed_email,
|
77
|
-
cookie_consent: cookie_consent,
|
78
|
-
feedback_consent: feedback_consent,
|
79
84
|
}.compact
|
80
85
|
|
81
86
|
patch_json("#{endpoint}/api/oidc-users/#{subject_identifier}", params)
|
@@ -138,6 +143,6 @@ private
|
|
138
143
|
end
|
139
144
|
|
140
145
|
def auth_headers(govuk_account_session)
|
141
|
-
{ AUTH_HEADER_NAME => govuk_account_session }
|
146
|
+
{ AUTH_HEADER_NAME => govuk_account_session }.compact
|
142
147
|
end
|
143
148
|
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
|
|
@@ -246,6 +247,22 @@ class GdsApi::EmailAlertApi < GdsApi::Base
|
|
246
247
|
)
|
247
248
|
end
|
248
249
|
|
250
|
+
# Unsubscribe all users for a subscription list
|
251
|
+
# optionally send a notification email explaining the reason
|
252
|
+
#
|
253
|
+
# @param [string] subscriber_list_id Identifier for the subscription list
|
254
|
+
# @param [string] (optional) body Optional email body to send to alert users they are being unsubscribed
|
255
|
+
# @param [string] (optional) sender_message_id A UUID to prevent multiple emails for the same event
|
256
|
+
def bulk_unsubscribe(subscriber_list_id:, body: nil, sender_message_id: nil)
|
257
|
+
post_json(
|
258
|
+
"#{endpoint}/subscriber-lists/#{subscriber_list_id}/bulk-unsubscribe",
|
259
|
+
{
|
260
|
+
body: body,
|
261
|
+
sender_message_id: sender_message_id,
|
262
|
+
}.compact,
|
263
|
+
)
|
264
|
+
end
|
265
|
+
|
249
266
|
private
|
250
267
|
|
251
268
|
def nested_query_string(params)
|
@@ -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,
|
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,18 +159,15 @@ 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,
|
162
|
+
def stub_update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, old_email: nil, old_email_verified: 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
|
166
|
+
with: { body: hash_including({ email: email, email_verified: email_verified }.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,
|
138
|
-
cookie_consent: cookie_consent || old_cookie_consent,
|
139
|
-
feedback_consent: feedback_consent || old_feedback_consent,
|
140
171
|
},
|
141
172
|
)
|
142
173
|
end
|
@@ -408,6 +408,53 @@ module GdsApi
|
|
408
408
|
.to_return(status: 404)
|
409
409
|
end
|
410
410
|
|
411
|
+
def stub_email_alert_api_bulk_unsubscribe(subscriber_list_id:)
|
412
|
+
stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{subscriber_list_id}/bulk-unsubscribe")
|
413
|
+
.to_return(status: 202)
|
414
|
+
end
|
415
|
+
|
416
|
+
def stub_email_alert_api_bulk_unsubscribe_with_message(subscriber_list_id:, body:, sender_message_id:)
|
417
|
+
stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{subscriber_list_id}/bulk-unsubscribe")
|
418
|
+
.with(
|
419
|
+
body: {
|
420
|
+
body: body,
|
421
|
+
sender_message_id: sender_message_id,
|
422
|
+
}.to_json,
|
423
|
+
).to_return(status: 202)
|
424
|
+
end
|
425
|
+
|
426
|
+
def stub_email_alert_api_bulk_unsubscribe_not_found(subscriber_list_id:)
|
427
|
+
stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{subscriber_list_id}/bulk-unsubscribe")
|
428
|
+
.to_return(status: 404)
|
429
|
+
end
|
430
|
+
|
431
|
+
def stub_email_alert_api_bulk_unsubscribe_not_found_with_message(subscriber_list_id:, body:, sender_message_id:)
|
432
|
+
stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{subscriber_list_id}/bulk-unsubscribe")
|
433
|
+
.with(
|
434
|
+
body: {
|
435
|
+
body: body,
|
436
|
+
sender_message_id: sender_message_id,
|
437
|
+
}.to_json,
|
438
|
+
).to_return(status: 404)
|
439
|
+
end
|
440
|
+
|
441
|
+
def stub_email_alert_api_bulk_unsubscribe_conflict_with_message(subscriber_list_id:, body:, sender_message_id:)
|
442
|
+
stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{subscriber_list_id}/bulk-unsubscribe")
|
443
|
+
.with(
|
444
|
+
body: {
|
445
|
+
body: body,
|
446
|
+
sender_message_id: sender_message_id,
|
447
|
+
}.to_json,
|
448
|
+
).to_return(status: 409)
|
449
|
+
end
|
450
|
+
|
451
|
+
def stub_email_alert_api_bulk_unsubscribe_bad_request(subscriber_list_id:, body:)
|
452
|
+
stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{subscriber_list_id}/bulk-unsubscribe")
|
453
|
+
.with(
|
454
|
+
body: { body: body }.to_json,
|
455
|
+
).to_return(status: 422)
|
456
|
+
end
|
457
|
+
|
411
458
|
private
|
412
459
|
|
413
460
|
def get_subscriber_response(id, address, govuk_account_id)
|
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: 77.1.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:
|
11
|
+
date: 2022-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|