Skip to content

Commit

Permalink
Merge pull request #515 from open-craft/keith/backport-jwt-oc-maple
Browse files Browse the repository at this point in the history
fix: Fix retiring user auth models on disable event (maple backport)
  • Loading branch information
mtyaka authored Dec 6, 2022
2 parents 1b00879 + 37796c5 commit 2212934
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions lms/djangoapps/support/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from django.http import HttpResponse
from django.urls import reverse
from django.test.utils import override_settings
from oauth2_provider.models import AccessToken, RefreshToken
from organizations.tests.factories import OrganizationFactory
from pytz import UTC
from rest_framework import status
Expand All @@ -41,6 +42,7 @@
from lms.djangoapps.verify_student.services import IDVerificationService
from lms.djangoapps.verify_student.tests.factories import SSOVerificationFactory
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from openedx.core.djangoapps.oauth_dispatch.tests import factories
from openedx.features.content_type_gating.models import ContentTypeGatingConfig
from openedx.features.course_duration_limits.models import CourseDurationLimitConfig
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase
Expand Down Expand Up @@ -130,6 +132,15 @@ def test_disable_user_account(self):
test_user = UserFactory(
username='foobar', email='[email protected]', password='foobar'
)

application = factories.ApplicationFactory(user=test_user)
access_token = factories.AccessTokenFactory(user=test_user, application=application)
factories.RefreshTokenFactory(
user=test_user, application=application, access_token=access_token
)
assert 0 != AccessToken.objects.filter(user=test_user).count()
assert 0 != RefreshToken.objects.filter(user=test_user).count()

url = reverse('support:manage_user_detail') + test_user.username
response = self.client.post(url, data={
'username_or_email': test_user.username,
Expand All @@ -139,6 +150,8 @@ def test_disable_user_account(self):
assert data['success_msg'] == 'User Disabled Successfully'
test_user = User.objects.get(username=test_user.username, email=test_user.email)
assert test_user.has_usable_password() is False
assert 0 == AccessToken.objects.filter(user=test_user).count()
assert 0 == RefreshToken.objects.filter(user=test_user).count()


@ddt.ddt
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/support/views/manage_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def post(self, request, username_or_email):
UserPasswordToggleHistory.objects.create(
user=user, comment=comment, created_by=request.user, disabled=True
)
retire_dot_oauth2_models(request.user)
retire_dot_oauth2_models(user)
else:
user.set_password(generate_password(length=25))
UserPasswordToggleHistory.objects.create(
Expand Down

0 comments on commit 2212934

Please sign in to comment.