chore: replace integrity signature flag with django setting
This commit is contained in:
@@ -3,11 +3,12 @@ Tests for agreements views
|
||||
"""
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.conf import settings
|
||||
from django.urls import reverse
|
||||
from rest_framework.test import APITestCase
|
||||
from rest_framework import status
|
||||
from edx_toggles.toggles.testutils import override_waffle_flag
|
||||
from freezegun import freeze_time
|
||||
|
||||
from common.djangoapps.student.tests.factories import UserFactory, AdminFactory
|
||||
@@ -16,14 +17,13 @@ from openedx.core.djangoapps.agreements.api import (
|
||||
create_integrity_signature,
|
||||
get_integrity_signatures_for_course,
|
||||
)
|
||||
from openedx.core.djangoapps.agreements.toggles import ENABLE_INTEGRITY_SIGNATURE
|
||||
from openedx.core.djangolib.testing.utils import skip_unless_lms
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order
|
||||
from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order
|
||||
|
||||
|
||||
@skip_unless_lms
|
||||
@override_waffle_flag(ENABLE_INTEGRITY_SIGNATURE, active=True)
|
||||
@patch.dict(settings.FEATURES, {'ENABLE_INTEGRITY_SIGNATURE': True})
|
||||
class IntegritySignatureViewTests(APITestCase, ModuleStoreTestCase):
|
||||
"""
|
||||
Tests for the Integrity Signature View
|
||||
@@ -157,7 +157,7 @@ class IntegritySignatureViewTests(APITestCase, ModuleStoreTestCase):
|
||||
)
|
||||
self._assert_response(response, status.HTTP_200_OK, self.user, self.course_id)
|
||||
|
||||
@override_waffle_flag(ENABLE_INTEGRITY_SIGNATURE, active=False)
|
||||
@patch.dict(settings.FEATURES, {'ENABLE_INTEGRITY_SIGNATURE': False})
|
||||
def test_404_for_no_waffle_flag(self):
|
||||
self._create_signature(self.user.username, self.course_id)
|
||||
response = self.client.get(
|
||||
@@ -209,7 +209,7 @@ class IntegritySignatureViewTests(APITestCase, ModuleStoreTestCase):
|
||||
self.assertEqual(len(signatures), 1)
|
||||
self.assertEqual(signatures[0].user.username, self.USERNAME)
|
||||
|
||||
@override_waffle_flag(ENABLE_INTEGRITY_SIGNATURE, active=False)
|
||||
@patch.dict(settings.FEATURES, {'ENABLE_INTEGRITY_SIGNATURE': False})
|
||||
def test_post_integrity_signature_no_waffle_flag(self):
|
||||
response = self.client.post(
|
||||
reverse(
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
"""
|
||||
Toggles for the Agreements app
|
||||
"""
|
||||
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
|
||||
from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag
|
||||
|
||||
|
||||
# .. toggle_name: agreements.enable_integrity_signature
|
||||
# .. toggle_implementation: CourseWaffleFlag
|
||||
# .. toggle_default: False
|
||||
# .. toggle_description: Supports rollout of the integrity signature feature
|
||||
# .. toggle_use_cases: temporary, open_edx
|
||||
# .. toggle_creation_date: 2021-05-07
|
||||
# .. toggle_target_removal_date: None
|
||||
# .. toggle_warnings: None
|
||||
# .. toggle_tickets: MST-786
|
||||
|
||||
ENABLE_INTEGRITY_SIGNATURE = CourseWaffleFlag( # lint-amnesty, pylint: disable=toggle-missing-annotation
|
||||
'agreements', 'enable_integrity_signature', __name__,
|
||||
)
|
||||
|
||||
|
||||
def is_integrity_signature_enabled(course_key):
|
||||
if isinstance(course_key, str):
|
||||
course_key = CourseKey.from_string(course_key)
|
||||
return ENABLE_INTEGRITY_SIGNATURE.is_enabled(course_key)
|
||||
@@ -2,6 +2,7 @@
|
||||
Views served by the Agreements app
|
||||
"""
|
||||
|
||||
from django.conf import settings
|
||||
from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication
|
||||
from rest_framework import status
|
||||
from rest_framework.views import APIView
|
||||
@@ -17,7 +18,6 @@ from openedx.core.djangoapps.agreements.api import (
|
||||
get_integrity_signature,
|
||||
)
|
||||
from openedx.core.djangoapps.agreements.serializers import IntegritySignatureSerializer
|
||||
from openedx.core.djangoapps.agreements.toggles import is_integrity_signature_enabled
|
||||
|
||||
|
||||
def is_user_course_or_global_staff(user, course_id):
|
||||
@@ -67,8 +67,7 @@ class IntegritySignatureView(AuthenticatedAPIView):
|
||||
If a username is not given, it should default to the requesting user (or masqueraded user).
|
||||
Only staff should be able to access this endpoint for other users.
|
||||
"""
|
||||
# check that waffle flag is enabled
|
||||
if not is_integrity_signature_enabled(CourseKey.from_string(course_id)):
|
||||
if not settings.FEATURES.get('ENABLE_INTEGRITY_SIGNATURE'):
|
||||
return Response(
|
||||
status=status.HTTP_404_NOT_FOUND,
|
||||
)
|
||||
@@ -111,8 +110,7 @@ class IntegritySignatureView(AuthenticatedAPIView):
|
||||
created_at: "2021-04-23T18:25:43.511Z"
|
||||
}
|
||||
"""
|
||||
# check that waffle flag is enabled
|
||||
if not is_integrity_signature_enabled(CourseKey.from_string(course_id)):
|
||||
if not settings.FEATURES.get('ENABLE_INTEGRITY_SIGNATURE'):
|
||||
return Response(
|
||||
status=status.HTTP_404_NOT_FOUND,
|
||||
)
|
||||
|
||||
@@ -43,7 +43,6 @@ from common.djangoapps.student.models import (
|
||||
from common.djangoapps.student.roles import CourseInstructorRole
|
||||
from common.djangoapps.student.tests.factories import CourseEnrollmentCelebrationFactory, UserFactory
|
||||
from openedx.core.djangoapps.agreements.api import create_integrity_signature
|
||||
from openedx.core.djangoapps.agreements.toggles import ENABLE_INTEGRITY_SIGNATURE
|
||||
|
||||
|
||||
User = get_user_model()
|
||||
@@ -362,7 +361,7 @@ class CourseApiTestViews(BaseCoursewareTests, MasqueradeMixin):
|
||||
('audit', True, False, False),
|
||||
)
|
||||
@ddt.unpack
|
||||
@override_waffle_flag(ENABLE_INTEGRITY_SIGNATURE, True)
|
||||
@mock.patch.dict(settings.FEATURES, {'ENABLE_INTEGRITY_SIGNATURE': True})
|
||||
def test_user_needs_integrity_signature(
|
||||
self, enrollment_mode, is_staff, has_integrity_signature, needs_integrity_signature,
|
||||
):
|
||||
@@ -398,7 +397,7 @@ class CourseApiTestViews(BaseCoursewareTests, MasqueradeMixin):
|
||||
(3, True),
|
||||
)
|
||||
@ddt.unpack
|
||||
@override_waffle_flag(ENABLE_INTEGRITY_SIGNATURE, True)
|
||||
@mock.patch.dict(settings.FEATURES, {'ENABLE_INTEGRITY_SIGNATURE': True})
|
||||
def test_course_staff_masquerade(self, masquerade_group_id, needs_signature):
|
||||
self.user.is_staff = True
|
||||
self.user.save()
|
||||
|
||||
@@ -3,6 +3,7 @@ Course API Views
|
||||
"""
|
||||
from completion.exceptions import UnavailableCompletionData
|
||||
from completion.utilities import get_key_to_last_completed_block
|
||||
from django.conf import settings
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext as _
|
||||
from edx_django_utils.cache import TieredCache
|
||||
@@ -48,7 +49,6 @@ from lms.djangoapps.courseware.views.views import get_cert_data
|
||||
from lms.djangoapps.grades.api import CourseGradeFactory
|
||||
from lms.djangoapps.verify_student.services import IDVerificationService
|
||||
from openedx.core.djangoapps.agreements.api import get_integrity_signature
|
||||
from openedx.core.djangoapps.agreements.toggles import is_integrity_signature_enabled as integrity_signature_toggle
|
||||
from openedx.core.djangoapps.courseware_api.utils import get_celebrations_dict
|
||||
from openedx.core.djangoapps.programs.utils import ProgramProgressMeter
|
||||
from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser
|
||||
@@ -319,15 +319,18 @@ class CoursewareMeta:
|
||||
@property
|
||||
def is_integrity_signature_enabled(self):
|
||||
"""
|
||||
Course waffle flag for the integrity signature feature.
|
||||
Django setting for the integrity signature feature.
|
||||
"""
|
||||
return integrity_signature_toggle(self.course_key)
|
||||
return settings.FEATURES.get('ENABLE_INTEGRITY_SIGNATURE', False)
|
||||
|
||||
@property
|
||||
def user_needs_integrity_signature(self):
|
||||
"""
|
||||
Boolean describing whether the user needs to sign the integrity agreement for a course.
|
||||
"""
|
||||
if not settings.FEATURES.get('ENABLE_INTEGRITY_SIGNATURE'):
|
||||
return False
|
||||
|
||||
integrity_signature_required = (
|
||||
self.enrollment_object
|
||||
# Master's enrollments are excluded here as honor code is handled separately
|
||||
@@ -342,13 +345,11 @@ class CoursewareMeta:
|
||||
self.course_masquerade
|
||||
)
|
||||
|
||||
if (
|
||||
integrity_signature_toggle(self.course_key)
|
||||
and integrity_signature_required
|
||||
):
|
||||
if integrity_signature_required:
|
||||
signature = get_integrity_signature(self.effective_user.username, str(self.course_key))
|
||||
if not signature:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
@property
|
||||
|
||||
Reference in New Issue
Block a user