Skip to content

Commit 464736e

Browse files
Merge pull request #554 from biocore/csymons_minors_update_age
Allow Minors to Change age_range on Source
2 parents ace52ec + 4933300 commit 464736e

9 files changed

+353
-114
lines changed

microsetta_private_api/api/_consent.py

+37-19
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
from microsetta_private_api import localization
44
from microsetta_private_api.api._account import \
55
_validate_account_access
6-
from microsetta_private_api.model.consent import ConsentSignature
6+
from microsetta_private_api.model.consent import ConsentSignature,\
7+
HUMAN_CONSENT_AGE_GROUPS
78
from microsetta_private_api.repo.consent_repo import ConsentRepo
89
from microsetta_private_api.repo.source_repo import SourceRepo
910
from microsetta_private_api.repo.transaction import Transaction
@@ -63,36 +64,53 @@ def sign_consent_doc(account_id, source_id, consent_type, body, token_info):
6364
_validate_account_access(token_info, account_id)
6465

6566
with Transaction() as t:
66-
# Sources with an age_range of "legacy" will select an age range
67-
# the first time they sign a new consent document. We need to
68-
# catch legacy sources as they come in and update their age.
67+
# Sources are now permitted to update their age range, but only if it
68+
# moves the source to an older age group. For this purpose, "legacy"
69+
# is treated as younger than "0-6", as they're choosing an age group
70+
# for the first time.
6971
source_repo = SourceRepo(t)
7072
source = source_repo.get_source(account_id, source_id)
7173
if source is None:
7274
return jsonify(code=404, message=SRC_NOT_FOUND_MSG), 404
7375

74-
if source.source_data.age_range == "legacy":
75-
update_success = source_repo.update_legacy_source_age_range(
76+
if source.source_data.age_range != body['age_range']:
77+
# Let's make sure it's a valid change. First, grab the index of
78+
# their current age range.
79+
try:
80+
cur_age_index = HUMAN_CONSENT_AGE_GROUPS.index(
81+
source.source_data.age_range
82+
)
83+
except ValueError:
84+
# Catch any sources that have a blank, "legacy", or faulty
85+
# age_range
86+
cur_age_index = -1
87+
88+
# Next, make sure their new age range is valid
89+
try:
90+
new_age_index = HUMAN_CONSENT_AGE_GROUPS.index(
91+
body['age_range']
92+
)
93+
except ValueError:
94+
# Shouldn't reach this point, but if we do, reject it
95+
return jsonify(
96+
code=403, message="Invalid age_range update"
97+
), 403
98+
99+
# Finally, make sure the new age_range isn't younger than the
100+
# current age_range.
101+
if new_age_index < cur_age_index:
102+
return jsonify(
103+
code=403, message="Invalid age_range update"
104+
), 403
105+
106+
update_success = source_repo.update_source_age_range(
76107
source_id, body['age_range']
77108
)
78109
if not update_success:
79110
return jsonify(
80111
code=403, message="Invalid age_range update"
81112
), 403
82113

83-
# NB For the time being, we need to block any pre-overhaul under-18
84-
# profiles from re-consenting. For API purposes, the safest way to
85-
# check whether it's a pre-overhaul or post-overhaul source is to look
86-
# at the creation_time on the source. Anything pre-overhaul is
87-
# prevented from signing a new consent document.
88-
if source.source_data.age_range not in ["legacy", "18-plus"] and\
89-
not source_repo.check_source_post_overhaul(
90-
account_id, source_id
91-
):
92-
return jsonify(
93-
code=403, message="Minors may not sign new consent documents"
94-
), 403
95-
96114
# Now back to the normal flow of signing a consent document
97115
consent_repo = ConsentRepo(t)
98116
sign_id = str(uuid.uuid4())

microsetta_private_api/api/microsetta_private_api.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -392,14 +392,16 @@ paths:
392392
$ref: '#/components/schemas/consent_content'
393393
assent_content:
394394
$ref: '#/components/schemas/assent_content'
395+
consent_type:
396+
$ref: '#/components/schemas/consent_type'
395397
'401':
396398
$ref: '#/components/responses/401Unauthorized'
397399
'403':
398400
$ref: '#/components/responses/403Forbidden'
399401
'404':
400402
$ref: '#/components/responses/404NotFound'
401403

402-
'/accounts/{account_id}/source/{source_id}/consent/{consent_type}':
404+
'/accounts/{account_id}/sources/{source_id}/consent/{consent_type}':
403405
get:
404406
operationId: microsetta_private_api.api.check_consent_signature
405407
tags:

0 commit comments

Comments
 (0)