def post(self, request): """ Unenrolls the specified user from all courses. """ try: # Get the username from the request. username = request.data['username'] # Ensure that a retirement request status row exists for this username. UserRetirementStatus.get_retirement_for_retirement_action(username) enrollments = api.get_enrollments(username) active_enrollments = [ enrollment for enrollment in enrollments if enrollment['is_active'] ] if len(active_enrollments) < 1: return Response(status=status.HTTP_204_NO_CONTENT) return Response(api.unenroll_user_from_all_courses(username)) except KeyError: return Response(u'Username not specified.', status=status.HTTP_404_NOT_FOUND) except UserRetirementStatus.DoesNotExist: return Response(u'No retirement request status for username.', status=status.HTTP_404_NOT_FOUND) except Exception as exc: # pylint: disable=broad-except return Response(text_type(exc), status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def fake_completed_retirement(user): """ Makes an attempt to put user for the given user into a "COMPLETED" retirement state by faking important parts of retirement. Use to test idempotency for retirement API calls. Since there are many configurable retirement steps this is only a "best guess" and may need additional changes added to more accurately reflect post-retirement state. """ # Deactivate / logout and hash username & email UserSocialAuth.objects.filter(user_id=user.id).delete() _fake_logged_out_user(user, retire_username=True) user.first_name = '' user.last_name = '' user.is_active = False user.save() # Clear profile AccountRetirementView.clear_pii_from_userprofile(user) # Unenroll from all courses api.unenroll_user_from_all_courses(user.username)
def fake_completed_retirement(user): """ Makes an attempt to put user for the given user into a "COMPLETED" retirement state by faking important parts of retirement. Use to test idempotency for retirement API calls. Since there are many configurable retirement steps this is only a "best guess" and may need additional changes added to more accurately reflect post-retirement state. """ # Deactivate / logout and hash username & email UserSocialAuth.objects.filter(user_id=user.id).delete() _fake_logged_out_user(user, retire_username=True) user.first_name = '' user.last_name = '' user.is_active = False user.save() # Clear profile AccountRetirementView.clear_pii_from_userprofile(user) # Unenroll from all courses api.unenroll_user_from_all_courses(user.username)
def post(self, request): """ Unenrolls the specified user from all courses. """ try: # Get the username from the request. username = request.data['username'] # Ensure that a retirement request status row exists for this username. UserRetirementStatus.get_retirement_for_retirement_action(username) enrollments = api.get_enrollments(username) active_enrollments = [enrollment for enrollment in enrollments if enrollment['is_active']] if len(active_enrollments) < 1: return Response(status=status.HTTP_204_NO_CONTENT) return Response(api.unenroll_user_from_all_courses(username)) except KeyError: return Response(u'Username not specified.', status=status.HTTP_404_NOT_FOUND) except UserRetirementStatus.DoesNotExist: return Response(u'No retirement request status for username.', status=status.HTTP_404_NOT_FOUND) except Exception as exc: # pylint: disable=broad-except return Response(text_type(exc), status=status.HTTP_500_INTERNAL_SERVER_ERROR)