Skip to content

Commit

Permalink
Merge pull request #456 from ucsd-ets/release-candidate
Browse files Browse the repository at this point in the history
release-2021-24-03
  • Loading branch information
sheralim012 authored Mar 24, 2021
2 parents 876d19e + dcfdcc7 commit b6357d3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
6 changes: 5 additions & 1 deletion common/djangoapps/student/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,11 @@ def get_next_url_for_login_page(request):
If THIRD_PARTY_AUTH_HINT is set, then `tpa_hint=<hint>` is added as a query parameter.
"""
redirect_to = _get_redirect_to(request)
if not redirect_to:
# [UCSD_CUSTOM] stop user from going to /courses after login/registration/third_party_auth
if not redirect_to or (configuration_helpers.get_value(
'ALWAYS_REDIRECT_HOMEPAGE_TO_COURSES_FOR_ANONYMOUS_USER',
settings.FEATURES.get('ALWAYS_REDIRECT_HOMEPAGE_TO_COURSES_FOR_ANONYMOUS_USER', False)) and
redirect_to == '/courses'):
try:
redirect_to = reverse('dashboard')
except NoReverseMatch:
Expand Down
16 changes: 13 additions & 3 deletions openedx/features/ucsd_features/signals.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from logging import getLogger

from django.conf import settings
from django.dispatch import receiver
from django.db.models.signals import post_save, pre_save
from django.dispatch import receiver
from opaque_keys.edx.keys import CourseKey

from lms.djangoapps.verify_student.models import ManualVerification
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from student.models import UserProfile

from student.models import CourseEnrollment, UserProfile
from xmodule.modulestore.django import SignalHandler

logger = getLogger(__name__)

Expand All @@ -31,3 +32,12 @@ def generate_manual_verification_for_user(sender, instance, created, **kwargs):
except Exception: # pylint: disable=broad-except
logger.error('Error while generating ManualVerification for user: %s', instance.user.email, exc_info=True)


@receiver(SignalHandler.course_deleted)
def _listen_for_course_delete(sender, course_key, **kwargs): # pylint: disable=unused-argument
"""
Catches the signal that a course has been deleted from Studio and
invalidates the corresponding CourseEnrollments if any exists.
"""
logger.info('Deactivate course enrollment for course_id: {}'.format(course_key))
CourseEnrollment.objects.filter(course_id=course_key).update(is_active=False)
22 changes: 20 additions & 2 deletions openedx/features/ucsd_features/tests/test_signals.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import pytz
from datetime import datetime

import pytz
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.test import TestCase
from django.test.utils import override_settings

from lms.djangoapps.verify_student.models import ManualVerification
from student.models import CourseEnrollment
from student.tests.factories import UserFactory
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory


class UCSDFeaturesSignalsTests(ModuleStoreTestCase):
ENABLED_SIGNALS = ['course_deleted']

class UCSDFeaturesSignalsTests(TestCase):
def test_user_is_verified_after_creation_when_flag_is_set(self):
features = settings.FEATURES.copy()
features['AUTOMATIC_PERMANENT_ACCOUNT_VERIFICATION'] = True
Expand All @@ -36,3 +42,15 @@ def test_verification_attempt_expiration_datetime(self):
verification_attempt = ManualVerification.objects.get(user=user)
expected_expiration_datetime = datetime.max.replace(tzinfo=pytz.UTC)
self.assertEqual(verification_attempt.expiration_datetime, expected_expiration_datetime)

def test_deactivate_course_enrollment_on_course_delete(self):
user = UserFactory()
course = CourseFactory()
course_enrollment = CourseEnrollment.enroll(user, course.id)
module_store = modulestore()

with module_store.bulk_operations(course.id):
module_store.delete_course(course.id, user.id)

course_enrollment.refresh_from_db()
self.assertFalse(course_enrollment.is_active)

0 comments on commit b6357d3

Please sign in to comment.