EDUCAOTR-2870: move oauth token retirement to dea deactivation endpoint
This commit is contained in:
@@ -1112,7 +1112,8 @@ class TestDeactivateLogout(RetirementTestCase):
|
|||||||
def build_post(self, password):
|
def build_post(self, password):
|
||||||
return {'password': password}
|
return {'password': password}
|
||||||
|
|
||||||
def test_user_can_deactivate_self(self):
|
@mock.patch('openedx.core.djangolib.oauth2_retirement_utils')
|
||||||
|
def test_user_can_deactivate_self(self, retirement_utils_mock):
|
||||||
"""
|
"""
|
||||||
Verify a user calling the deactivation endpoint logs out the user, deletes all their SSO tokens,
|
Verify a user calling the deactivation endpoint logs out the user, deletes all their SSO tokens,
|
||||||
and creates a user retirement row.
|
and creates a user retirement row.
|
||||||
@@ -1128,6 +1129,9 @@ class TestDeactivateLogout(RetirementTestCase):
|
|||||||
self.assertEqual(list(UserSocialAuth.objects.filter(user=self.test_user)), [])
|
self.assertEqual(list(UserSocialAuth.objects.filter(user=self.test_user)), [])
|
||||||
self.assertEqual(list(Registration.objects.filter(user=self.test_user)), [])
|
self.assertEqual(list(Registration.objects.filter(user=self.test_user)), [])
|
||||||
self.assertEqual(len(UserRetirementStatus.objects.filter(user_id=self.test_user.id)), 1)
|
self.assertEqual(len(UserRetirementStatus.objects.filter(user_id=self.test_user.id)), 1)
|
||||||
|
# these retirement utils are tested elsewhere; just make sure we called them
|
||||||
|
retirement_utils_mock.retire_dop_oauth2_models.assertCalledWith(self.test_user)
|
||||||
|
retirement_utils_mock.retire_dot_oauth2_models.assertCalledWith(self.test_user)
|
||||||
# make sure the user cannot log in
|
# make sure the user cannot log in
|
||||||
self.assertFalse(self.client.login(username=self.test_user.username, password=self.test_password))
|
self.assertFalse(self.client.login(username=self.test_user.username, password=self.test_password))
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ from openedx.core.djangoapps.course_groups.models import UnregisteredLearnerCoho
|
|||||||
from openedx.core.djangoapps.profile_images.images import remove_profile_images
|
from openedx.core.djangoapps.profile_images.images import remove_profile_images
|
||||||
from openedx.core.djangoapps.user_api.accounts.image_helpers import get_profile_image_names, set_has_profile_image
|
from openedx.core.djangoapps.user_api.accounts.image_helpers import get_profile_image_names, set_has_profile_image
|
||||||
from openedx.core.djangoapps.user_api.preferences.api import update_email_opt_in
|
from openedx.core.djangoapps.user_api.preferences.api import update_email_opt_in
|
||||||
|
from openedx.core.djangolib.oauth2_retirement_utils import retire_dop_oauth2_models, retire_dot_oauth2_models
|
||||||
from openedx.core.lib.api.authentication import (
|
from openedx.core.lib.api.authentication import (
|
||||||
OAuth2AuthenticationAllowInactiveUser,
|
OAuth2AuthenticationAllowInactiveUser,
|
||||||
SessionAuthenticationAllowInactiveUser
|
SessionAuthenticationAllowInactiveUser
|
||||||
@@ -417,6 +418,9 @@ class DeactivateLogoutView(APIView):
|
|||||||
# Remove the activation keys sent by email to the user for account activation.
|
# Remove the activation keys sent by email to the user for account activation.
|
||||||
Registration.objects.filter(user=request.user).delete()
|
Registration.objects.filter(user=request.user).delete()
|
||||||
# Add user to retirement queue.
|
# Add user to retirement queue.
|
||||||
|
# Delete OAuth tokens associated with the user.
|
||||||
|
retire_dop_oauth2_models(request.user)
|
||||||
|
retire_dot_oauth2_models(request.user)
|
||||||
# Log the user out.
|
# Log the user out.
|
||||||
logout(request)
|
logout(request)
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|||||||
Reference in New Issue
Block a user