Merge pull request #7226 from edx/christina/update-accounts-api
Updates to account and profile APIs based on arch council feedback
This commit is contained in:
@@ -130,7 +130,7 @@ class EnrollmentTest(UrlResetMixin, ModuleStoreTestCase):
|
||||
# Verify that the profile API has been called as expected
|
||||
if email_opt_in is not None:
|
||||
opt_in = email_opt_in == 'true'
|
||||
mock_update_email_opt_in.assert_called_once_with(self.USERNAME, self.course.org, opt_in)
|
||||
mock_update_email_opt_in.assert_called_once_with(self.user, self.course.org, opt_in)
|
||||
else:
|
||||
self.assertFalse(mock_update_email_opt_in.called)
|
||||
|
||||
|
||||
@@ -797,7 +797,7 @@ def try_change_enrollment(request):
|
||||
log.exception(u"Exception automatically enrolling after login: %s", exc)
|
||||
|
||||
|
||||
def _update_email_opt_in(request, username, org):
|
||||
def _update_email_opt_in(request, org):
|
||||
"""Helper function used to hit the profile API if email opt-in is enabled."""
|
||||
|
||||
# TODO: remove circular dependency on openedx from common
|
||||
@@ -806,7 +806,7 @@ def _update_email_opt_in(request, username, org):
|
||||
email_opt_in = request.POST.get('email_opt_in')
|
||||
if email_opt_in is not None:
|
||||
email_opt_in_boolean = email_opt_in == 'true'
|
||||
profile_api.update_email_opt_in(username, org, email_opt_in_boolean)
|
||||
profile_api.update_email_opt_in(request.user, org, email_opt_in_boolean)
|
||||
|
||||
|
||||
@require_POST
|
||||
@@ -878,7 +878,7 @@ def change_enrollment(request, check_access=True):
|
||||
|
||||
# Record the user's email opt-in preference
|
||||
if settings.FEATURES.get('ENABLE_MKTG_EMAIL_OPT_IN'):
|
||||
_update_email_opt_in(request, user.username, course_id.org)
|
||||
_update_email_opt_in(request, course_id.org)
|
||||
|
||||
available_modes = CourseMode.modes_for_course_dict(course_id)
|
||||
|
||||
@@ -1909,7 +1909,8 @@ def reactivation_email_for_user(user):
|
||||
return JsonResponse({"success": True})
|
||||
|
||||
|
||||
# TODO: delete this method and redirect unit tests to do_email_change_request after accounts page work is done.
|
||||
# TODO: delete this method and redirect unit tests to validate_new_email and do_email_change_request
|
||||
# after accounts page work is done.
|
||||
@ensure_csrf_cookie
|
||||
def change_email_request(request):
|
||||
""" AJAX call from the profile page. User wants a new e-mail.
|
||||
@@ -1928,6 +1929,7 @@ def change_email_request(request):
|
||||
|
||||
new_email = request.POST['new_email']
|
||||
try:
|
||||
validate_new_email(request.user, new_email)
|
||||
do_email_change_request(request.user, new_email)
|
||||
except ValueError as err:
|
||||
return JsonResponse({
|
||||
@@ -1937,11 +1939,10 @@ def change_email_request(request):
|
||||
return JsonResponse({"success": True})
|
||||
|
||||
|
||||
def do_email_change_request(user, new_email, activation_key=uuid.uuid4().hex):
|
||||
def validate_new_email(user, new_email):
|
||||
"""
|
||||
Given a new email for a user, does some basic verification of the new address and sends an activation message
|
||||
to the new address. If any issues are encountered with verification or sending the message, a ValueError will
|
||||
be thrown.
|
||||
Given a new email for a user, does some basic verification of the new address If any issues are encountered
|
||||
with verification a ValueError will be thrown.
|
||||
"""
|
||||
try:
|
||||
validate_email(new_email)
|
||||
@@ -1954,6 +1955,13 @@ def do_email_change_request(user, new_email, activation_key=uuid.uuid4().hex):
|
||||
if User.objects.filter(email=new_email).count() != 0:
|
||||
raise ValueError(_('An account with this e-mail already exists.'))
|
||||
|
||||
|
||||
def do_email_change_request(user, new_email, activation_key=uuid.uuid4().hex):
|
||||
"""
|
||||
Given a new email for a user, does some basic verification of the new address and sends an activation message
|
||||
to the new address. If any issues are encountered with verification or sending the message, a ValueError will
|
||||
be thrown.
|
||||
"""
|
||||
pec_list = PendingEmailChange.objects.filter(user=user)
|
||||
if len(pec_list) == 0:
|
||||
pec = PendingEmailChange()
|
||||
|
||||
@@ -672,7 +672,7 @@ def change_enrollment(strategy, user=None, is_dashboard=False, *args, **kwargs):
|
||||
# TODO: remove circular dependency on openedx from common
|
||||
from openedx.core.djangoapps.user_api.api import profile
|
||||
opt_in = email_opt_in.lower() == 'true'
|
||||
profile.update_email_opt_in(user.username, course_id.org, opt_in)
|
||||
profile.update_email_opt_in(user, course_id.org, opt_in)
|
||||
|
||||
# Check whether we're blocked from enrolling by a
|
||||
# country access rule.
|
||||
|
||||
Reference in New Issue
Block a user