def post(self, request): """ Unenrolls the specified user from all courses. """ username = None user_model = get_user_model() try: # Get the username from the request and check that it exists username = request.data['username'] user_model.objects.get(username=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_200_OK) return Response(api.unenroll_user_from_all_courses(username)) except KeyError: return Response(u'Username not specified.', status=status.HTTP_404_NOT_FOUND) except user_model.DoesNotExist: return Response(u'The user "{}" does not exist.'.format(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 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 post(self, request): """ Unenrolls the specified user from all courses. """ # Get the User from the request. username = request.data.get('user', None) if not username: return Response(status=status.HTTP_404_NOT_FOUND, data={'message': u'The user was not specified.'}) try: # make sure the specified user exists User.objects.get(username=username) except ObjectDoesNotExist: return Response( status=status.HTTP_404_NOT_FOUND, data={ 'message': u'The user "{}" does not exist.'.format(username) }) try: 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_200_OK) return Response(api.unenroll_user_from_all_courses(username)) 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) 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)
def post(self, request): """ Unenrolls the specified user from all courses. """ username = None user_model = get_user_model() try: # Get the username from the request and check that it exists username = request.data['username'] user_model.objects.get(username=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_200_OK) return Response(api.unenroll_user_from_all_courses(username)) except KeyError: return Response(u'Username not specified.', status=status.HTTP_404_NOT_FOUND) except user_model.DoesNotExist: return Response(u'The user "{}" does not exist.'.format(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)