diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index af2faecfb5..2c5c6c82f0 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -15,6 +15,7 @@ from six import text_type from django_comment_common.models import assign_default_role from django_comment_common.utils import seed_permissions_roles from openedx.core.djangoapps.site_configuration.models import SiteConfiguration +from openedx.features.course_duration_limits.config import CONTENT_TYPE_GATING_STUDIO_UI_FLAG from student import auth from student.models import CourseEnrollment from student.roles import CourseInstructorRole, CourseStaffRole @@ -457,6 +458,9 @@ def get_visibility_partition_info(xblock, course=None): if len(partition["groups"]) > 1 or any(group["selected"] for group in partition["groups"]): selectable_partitions.append(partition) + if CONTENT_TYPE_GATING_STUDIO_UI_FLAG.is_enabled(): + selectable_partitions += get_user_partition_info(xblock, schemes=["content_type_gate"], course=course) + # Now add the cohort user partitions. selectable_partitions = selectable_partitions + get_user_partition_info(xblock, schemes=["cohort"], course=course) diff --git a/common/lib/xmodule/xmodule/partitions/tests/test_partitions.py b/common/lib/xmodule/xmodule/partitions/tests/test_partitions.py index 601799a0a5..6db47039d8 100644 --- a/common/lib/xmodule/xmodule/partitions/tests/test_partitions.py +++ b/common/lib/xmodule/xmodule/partitions/tests/test_partitions.py @@ -4,7 +4,7 @@ Test the partitions and partitions service """ from unittest import TestCase -from mock import Mock +from mock import Mock, patch from opaque_keys.edx.locator import CourseLocator from stevedore.extension import Extension, ExtensionManager @@ -434,6 +434,18 @@ class PartitionServiceBaseClass(PartitionTestCase): def setUp(self): super(PartitionServiceBaseClass, self).setUp() + + content_gating_flag_patcher = patch( + 'openedx.features.content_type_gating.partitions.CONTENT_TYPE_GATING_FLAG.is_enabled', + return_value=True, + ).start() + self.addCleanup(content_gating_flag_patcher.stop) + content_gating_ui_flag_patcher = patch( + 'openedx.features.content_type_gating.partitions.CONTENT_TYPE_GATING_STUDIO_UI_FLAG.is_enabled', + return_value=True, + ).start() + self.addCleanup(content_gating_ui_flag_patcher.stop) + self.course = Mock(id=CourseLocator('org_0', 'course_0', 'run_0')) self.partition_service = self._create_service("ma") diff --git a/lms/djangoapps/grades/tests/test_course_grade_factory.py b/lms/djangoapps/grades/tests/test_course_grade_factory.py index 1df89359f7..6aa15af834 100644 --- a/lms/djangoapps/grades/tests/test_course_grade_factory.py +++ b/lms/djangoapps/grades/tests/test_course_grade_factory.py @@ -311,7 +311,7 @@ class TestGradeIteration(SharedModuleStoreTestCase): else mock_course_grade.return_value for student in self.students ] - with self.assertNumQueries(4): + with self.assertNumQueries(6): all_course_grades, all_errors = self._course_grades_and_errors_for(self.course, self.students) self.assertEqual( {student: text_type(all_errors[student]) for student in all_errors}, diff --git a/lms/djangoapps/instructor_task/tests/test_tasks_helper.py b/lms/djangoapps/instructor_task/tests/test_tasks_helper.py index 654d97dd28..de07b194e4 100644 --- a/lms/djangoapps/instructor_task/tests/test_tasks_helper.py +++ b/lms/djangoapps/instructor_task/tests/test_tasks_helper.py @@ -413,7 +413,7 @@ class TestInstructorGradeReport(InstructorGradeReportTestCase): RequestCache.clear_all_namespaces() - expected_query_count = 43 + expected_query_count = 45 with patch('lms.djangoapps.instructor_task.tasks_helper.runner._get_current_task'): with check_mongo_calls(mongo_count): with self.assertNumQueries(expected_query_count): diff --git a/openedx/features/content_type_gating/partitions.py b/openedx/features/content_type_gating/partitions.py index b19b60dd76..0f82e0500a 100644 --- a/openedx/features/content_type_gating/partitions.py +++ b/openedx/features/content_type_gating/partitions.py @@ -15,6 +15,10 @@ from lms.djangoapps.courseware.masquerade import ( get_masquerading_user_group, ) from xmodule.partitions.partitions import Group, UserPartition, UserPartitionError +from openedx.features.course_duration_limits.config import ( + CONTENT_TYPE_GATING_FLAG, + CONTENT_TYPE_GATING_STUDIO_UI_FLAG, +) LOG = logging.getLogger(__name__) @@ -34,6 +38,9 @@ def create_content_gating_partition(course): Create and return the Content Gating user partition. """ + if not (CONTENT_TYPE_GATING_FLAG.is_enabled() or CONTENT_TYPE_GATING_STUDIO_UI_FLAG.is_enabled()): + return None + try: content_gate_scheme = UserPartition.get_scheme("content_type_gate") except UserPartitionError: @@ -56,7 +63,7 @@ def create_content_gating_partition(course): partition = content_gate_scheme.create_user_partition( id=CONTENT_GATING_PARTITION_ID, - name=_(u"Content Type Gating"), + name=_(u"Feature-based Enrollments"), description=_(u"Partition for segmenting users by access to gated content types"), parameters={"course_id": unicode(course.id)} ) diff --git a/openedx/features/course_duration_limits/config.py b/openedx/features/course_duration_limits/config.py index eff4f675e7..23836c1133 100644 --- a/openedx/features/course_duration_limits/config.py +++ b/openedx/features/course_duration_limits/config.py @@ -11,3 +11,9 @@ CONTENT_TYPE_GATING_FLAG = WaffleFlag( flag_name=u'debug', flag_undefined_default=False ) + +CONTENT_TYPE_GATING_STUDIO_UI_FLAG = WaffleFlag( + waffle_namespace=WAFFLE_FLAG_NAMESPACE, + flag_name=u'studio_ui', + flag_undefined_default=False +)