From f993a484903992b443ca916a94bbbc6e5f7514ed Mon Sep 17 00:00:00 2001 From: stephensanchez Date: Wed, 3 Dec 2014 20:36:28 +0000 Subject: [PATCH] Only allow users who turned 13 before this year began to opt in. --- common/djangoapps/user_api/api/profile.py | 2 +- common/djangoapps/user_api/tests/test_profile_api.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/common/djangoapps/user_api/api/profile.py b/common/djangoapps/user_api/api/profile.py index 0970db267e..7f2e382ca3 100644 --- a/common/djangoapps/user_api/api/profile.py +++ b/common/djangoapps/user_api/api/profile.py @@ -191,7 +191,7 @@ def update_email_opt_in(username, org, optin): profile = UserProfile.objects.get(user=user) of_age = ( profile.year_of_birth is None or # If year of birth is not set, we assume user is of age. - datetime.datetime.now(UTC).year - profile.year_of_birth >= # pylint: disable=maybe-no-member + datetime.datetime.now(UTC).year - profile.year_of_birth > # pylint: disable=maybe-no-member getattr(settings, 'EMAIL_OPTIN_MINIMUM_AGE', 13) ) diff --git a/common/djangoapps/user_api/tests/test_profile_api.py b/common/djangoapps/user_api/tests/test_profile_api.py index 532831834d..9e0f7e554e 100644 --- a/common/djangoapps/user_api/tests/test_profile_api.py +++ b/common/djangoapps/user_api/tests/test_profile_api.py @@ -105,8 +105,11 @@ class ProfileApiTest(TestCase): # Check that a 32-year old can opt-out (32, False, u"False"), - # Check that someone 13 years old can opt-in - (13, True, u"True"), + # Check that someone 14 years old can opt-in + (14, True, u"True"), + + # Check that someone 13 years old cannot opt-in (must have turned 13 before this year) + (13, True, u"False"), # Check that someone 12 years old cannot opt-in (12, True, u"False")