Skip to content

Commit

Permalink
Merge pull request #1110 from alphagov/msw/consents
Browse files Browse the repository at this point in the history
Add cookie & feedback consents for updating users in account-api
  • Loading branch information
barrucadu authored Oct 14, 2021
2 parents e4c6615 + 5ac8165 commit b4d6fd3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# unreleased

- Add `cookie_consent` and `feedback_consent` to `update_user_by_subject_identifier` (for Account API)

# 75.0.0

- BREAKING: Remove `get_saved_pages` (for Account API)
Expand Down
6 changes: 5 additions & 1 deletion lib/gds_api/account_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,17 @@ def delete_user_by_subject_identifier(subject_identifier:)
# @param [String, nil] email The user's current
# @param [Boolean, nil] email_verified Whether the user's current email address is verified
# @param [Boolean, nil] has_unconfirmed_email Whether the user has a new, pending, email address
# @param [Boolean, nil] cookie_consent Whether the user has consented to analytics cookies
# @param [Boolean, nil] feedback_consent Whether the user has consented to being contacted for feedback
#
# @return [Hash] The user's subject identifier and email attributes
def update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, has_unconfirmed_email: nil)
def update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, has_unconfirmed_email: nil, cookie_consent: nil, feedback_consent: nil)
params = {
email: email,
email_verified: email_verified,
has_unconfirmed_email: has_unconfirmed_email,
cookie_consent: cookie_consent,
feedback_consent: feedback_consent,
}.compact

patch_json("#{endpoint}/api/oidc-users/#{subject_identifier}", params)
Expand Down
6 changes: 4 additions & 2 deletions lib/gds_api/test_helpers/account_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,18 @@ def stub_account_api_delete_user_by_subject_identifier_does_not_exist(subject_id
###########################################
# PATCH /api/oidc-users/:subject_identifier
###########################################
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)
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)
stub_account_api_request(
:patch,
"/api/oidc-users/#{subject_identifier}",
with: { body: hash_including({ email: email, email_verified: email_verified, has_unconfirmed_email: has_unconfirmed_email }.compact) },
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) },
response_body: {
sub: subject_identifier,
email: email || old_email,
email_verified: email_verified || old_email_verified,
has_unconfirmed_email: has_unconfirmed_email || old_has_unconfirmed_email,
cookie_consent: cookie_consent || old_cookie_consent,
feedback_consent: feedback_consent || old_feedback_consent,
},
)
end
Expand Down

0 comments on commit b4d6fd3

Please sign in to comment.