Merge pull request #19272 from edx/reve-37/prevent-studio-edits

REVE-37: prevent studio edits to feature based enrollments
This commit is contained in:
Gabe Mulley
2018-11-26 09:57:23 -05:00
committed by GitHub
11 changed files with 94 additions and 27 deletions

View File

@@ -673,7 +673,7 @@ class LoginSessionViewTest(UserAPITestCase):
# Verify that the session expiration was set correctly
cookie = self.client.cookies[settings.SESSION_COOKIE_NAME]
expected_expiry = datetime.datetime.now() + datetime.timedelta(weeks=4)
expected_expiry = datetime.datetime.utcnow() + datetime.timedelta(weeks=4)
self.assertIn(expected_expiry.strftime('%d-%b-%Y'), cookie.get('expires'))
def test_invalid_credentials(self):

View File

@@ -49,22 +49,14 @@ class EnrollmentTrackUserPartition(UserPartition):
for mode in CourseMode.modes_for_course(course_key, include_expired=True)
]
def from_json(self):
"""
Because this partition is dynamic, `from_json` is not supported.
`to_json` is supported, but shouldn't be used to persist this partition
within the course itself (used by Studio for sending data to front-end code)
Calling this method will raise a TypeError.
"""
raise TypeError("Because EnrollmentTrackUserPartition is a dynamic partition, 'from_json' is not supported.")
class EnrollmentTrackPartitionScheme(object):
"""
This scheme uses learner enrollment tracks to map learners into partition groups.
"""
read_only = True
@classmethod
def get_group_for_user(cls, course_key, user, user_partition, **kwargs): # pylint: disable=unused-argument
"""

View File

@@ -2,17 +2,18 @@
Tests for verified_track_content/partition_scheme.py.
"""
from datetime import datetime, timedelta
import pytz
from ..partition_scheme import EnrollmentTrackPartitionScheme, EnrollmentTrackUserPartition, ENROLLMENT_GROUP_IDS
from ..models import VerifiedTrackCohortedCourse
from course_modes.models import CourseMode
from student.models import CourseEnrollment
from student.tests.factories import UserFactory
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.partitions.partitions import UserPartition, MINIMUM_STATIC_PARTITION_ID
from xmodule.partitions.partitions import MINIMUM_STATIC_PARTITION_ID, UserPartition, ReadOnlyUserPartitionError
from ..models import VerifiedTrackCohortedCourse
from ..partition_scheme import ENROLLMENT_GROUP_IDS, EnrollmentTrackPartitionScheme, EnrollmentTrackUserPartition
class EnrollmentTrackUserPartitionTest(SharedModuleStoreTestCase):
@@ -60,8 +61,9 @@ class EnrollmentTrackUserPartitionTest(SharedModuleStoreTestCase):
self.assertEqual('Test partition for segmenting users by enrollment track', user_partition_json['description'])
def test_from_json_not_supported(self):
with self.assertRaises(TypeError):
EnrollmentTrackUserPartition.from_json()
user_partition_json = create_enrollment_track_partition(self.course).to_json()
with self.assertRaises(ReadOnlyUserPartitionError):
UserPartition.from_json(user_partition_json)
def test_group_ids(self):
"""