Conditionalize track selection based on settings of course duration and content gating
This commit is contained in:
25
openedx/core/djangoapps/config_model_utils/utils.py
Normal file
25
openedx/core/djangoapps/config_model_utils/utils.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""utils for feature-based enrollments"""
|
||||
from experiments.models import ExperimentData
|
||||
from openedx.features.course_duration_limits.config import (
|
||||
EXPERIMENT_ID,
|
||||
EXPERIMENT_DATA_HOLDBACK_KEY
|
||||
)
|
||||
|
||||
|
||||
def is_in_holdback(user):
|
||||
"""
|
||||
Return true if given user is in holdback expermiment
|
||||
"""
|
||||
in_holdback = False
|
||||
if user and user.is_authenticated:
|
||||
try:
|
||||
holdback_value = ExperimentData.objects.get(
|
||||
user=user,
|
||||
experiment_id=EXPERIMENT_ID,
|
||||
key=EXPERIMENT_DATA_HOLDBACK_KEY,
|
||||
).value
|
||||
in_holdback = holdback_value == 'True'
|
||||
except ExperimentData.DoesNotExist:
|
||||
pass
|
||||
|
||||
return in_holdback
|
||||
@@ -12,14 +12,12 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils import timezone
|
||||
|
||||
from lms.djangoapps.courseware.masquerade import get_course_masquerade, is_masquerading_as_specific_student
|
||||
from experiments.models import ExperimentData
|
||||
from openedx.core.djangoapps.config_model_utils.models import StackedConfigurationModel
|
||||
from openedx.core.djangoapps.config_model_utils.utils import is_in_holdback
|
||||
from openedx.features.content_type_gating.helpers import has_staff_roles
|
||||
from openedx.features.course_duration_limits.config import (
|
||||
CONTENT_TYPE_GATING_FLAG,
|
||||
FEATURE_BASED_ENROLLMENT_GLOBAL_KILL_FLAG,
|
||||
EXPERIMENT_ID,
|
||||
EXPERIMENT_DATA_HOLDBACK_KEY
|
||||
)
|
||||
from student.models import CourseEnrollment
|
||||
|
||||
@@ -109,18 +107,7 @@ class ContentTypeGatingConfig(StackedConfigurationModel):
|
||||
return False
|
||||
|
||||
# check if user is in holdback
|
||||
is_in_holdback = False
|
||||
if user and user.is_authenticated and (user_variable_represents_correct_user):
|
||||
try:
|
||||
holdback_value = ExperimentData.objects.get(
|
||||
user=user,
|
||||
experiment_id=EXPERIMENT_ID,
|
||||
key=EXPERIMENT_DATA_HOLDBACK_KEY,
|
||||
).value
|
||||
is_in_holdback = holdback_value == 'True'
|
||||
except ExperimentData.DoesNotExist:
|
||||
pass
|
||||
if is_in_holdback:
|
||||
if user_variable_represents_correct_user and is_in_holdback(user):
|
||||
return False
|
||||
|
||||
# enrollment might be None if the user isn't enrolled. In that case,
|
||||
|
||||
@@ -13,20 +13,18 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils import timezone
|
||||
|
||||
from course_modes.models import CourseMode
|
||||
from experiments.models import ExperimentData
|
||||
from lms.djangoapps.courseware.masquerade import (
|
||||
get_course_masquerade,
|
||||
get_masquerade_role,
|
||||
is_masquerading_as_specific_student
|
||||
)
|
||||
from openedx.core.djangoapps.config_model_utils.models import StackedConfigurationModel
|
||||
from openedx.core.djangoapps.config_model_utils.utils import is_in_holdback
|
||||
from openedx.features.content_type_gating.helpers import has_staff_roles
|
||||
from openedx.features.content_type_gating.partitions import CONTENT_GATING_PARTITION_ID, CONTENT_TYPE_GATE_GROUP_IDS
|
||||
from openedx.features.course_duration_limits.config import (
|
||||
CONTENT_TYPE_GATING_FLAG,
|
||||
FEATURE_BASED_ENROLLMENT_GLOBAL_KILL_FLAG,
|
||||
EXPERIMENT_ID,
|
||||
EXPERIMENT_DATA_HOLDBACK_KEY
|
||||
)
|
||||
from student.models import CourseEnrollment
|
||||
from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID
|
||||
@@ -130,20 +128,10 @@ class CourseDurationLimitConfig(StackedConfigurationModel):
|
||||
return False
|
||||
|
||||
no_masquerade = get_course_masquerade(user, course_key) is None
|
||||
is_in_holdback = False
|
||||
student_masquerade = is_masquerading_as_specific_student(user, course_key)
|
||||
# TODO: clean up as part of REV-100
|
||||
if user and user.username and (no_masquerade or student_masquerade):
|
||||
try:
|
||||
holdback_value = ExperimentData.objects.get(
|
||||
user=user,
|
||||
experiment_id=EXPERIMENT_ID,
|
||||
key=EXPERIMENT_DATA_HOLDBACK_KEY,
|
||||
).value
|
||||
is_in_holdback = holdback_value == 'True'
|
||||
except ExperimentData.DoesNotExist:
|
||||
pass
|
||||
if is_in_holdback:
|
||||
|
||||
# check if user is in holdback
|
||||
if (no_masquerade or student_masquerade) and is_in_holdback(user):
|
||||
return False
|
||||
|
||||
# enrollment might be None if the user isn't enrolled. In that case,
|
||||
|
||||
@@ -80,9 +80,9 @@ class TestCourseDurationLimitConfig(CacheIsolationTestCase):
|
||||
user = self.user
|
||||
course_key = self.course_overview.id
|
||||
|
||||
query_count = 8
|
||||
if not pass_enrollment:
|
||||
query_count = 9
|
||||
query_count = 9
|
||||
if pass_enrollment and already_enrolled:
|
||||
query_count = 8
|
||||
|
||||
with self.assertNumQueries(query_count):
|
||||
enabled = CourseDurationLimitConfig.enabled_for_enrollment(
|
||||
|
||||
Reference in New Issue
Block a user