Merge pull request #11787 from mitocw/enhancement/aq/add_master_course_staff_in_ccx_fix_migration_issue

Adds staff and instructor users of the master course to CCX
This commit is contained in:
Brian Beggs
2016-03-28 18:49:46 -04:00
11 changed files with 691 additions and 20 deletions

View File

@@ -9,6 +9,7 @@ from mock import patch, Mock
import ddt
from django.conf import settings
from ccx_keys.locator import CCXLocator
from django.test import RequestFactory
from django.test.client import Client
@@ -26,6 +27,7 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, check_mongo_calls
from xmodule.modulestore import ModuleStoreEnum
from opaque_keys.edx.locations import CourseLocator
from opaque_keys.edx.keys import CourseKey
from xmodule.error_module import ErrorDescriptor
from course_action_state.models import CourseRerunState
@@ -131,6 +133,39 @@ class TestCourseListing(ModuleStoreTestCase, XssTestMixin):
# check both course lists have same courses
self.assertEqual(courses_list, courses_list_by_groups)
def test_get_course_list_when_ccx(self):
"""
Assert that courses with CCXLocator are filter in course listing.
"""
course_location = self.store.make_course_key('Org1', 'Course1', 'Run1')
self._create_course_with_access_groups(course_location, self.user)
# get courses through iterating all courses
courses_list, __ = _accessible_courses_list(self.request)
self.assertEqual(len(courses_list), 1)
# get courses by reversing group name formats
courses_list_by_groups, __ = _accessible_courses_list_from_groups(self.request)
self.assertEqual(len(courses_list_by_groups), 1)
# assert no course in listing with ccx id
ccx_course = Mock()
course_key = CourseKey.from_string('course-v1:FakeOrg+CN1+CR-FALLNEVER1')
ccx_course.id = CCXLocator.from_course_locator(course_key, u"1")
with patch(
'xmodule.modulestore.mixed.MixedModuleStore.get_course',
return_value=ccx_course
), patch(
'xmodule.modulestore.mixed.MixedModuleStore.get_courses',
Mock(return_value=[ccx_course])
):
courses_list, __ = _accessible_courses_list_from_groups(self.request)
self.assertEqual(len(courses_list), 0)
courses_list, __ = _accessible_courses_list(self.request)
self.assertEqual(len(courses_list), 0)
@ddt.data(
(ModuleStoreEnum.Type.split, 'xmodule.modulestore.split_mongo.split_mongo_kvs.SplitMongoKVS'),
(ModuleStoreEnum.Type.mongo, 'xmodule.modulestore.mongo.base.MongoKeyValueStore')

View File

@@ -27,6 +27,7 @@ from .component import (
)
from .item import create_xblock_info
from .library import LIBRARIES_ENABLED
from ccx_keys.locator import CCXLocator
from contentstore import utils
from contentstore.course_group_config import (
COHORT_SCHEME,
@@ -390,6 +391,11 @@ def _accessible_courses_list(request):
if isinstance(course, ErrorDescriptor):
return False
# Custom Courses for edX (CCX) is an edX feature for re-using course content.
# CCXs cannot be edited in Studio (aka cms) and should not be shown in this dashboard.
if isinstance(course.id, CCXLocator):
return False
# pylint: disable=fixme
# TODO remove this condition when templates purged from db
if course.location.course == 'templates':
@@ -434,8 +440,11 @@ def _accessible_courses_list_from_groups(request):
except ItemNotFoundError:
# If a user has access to a course that doesn't exist, don't do anything with that course
pass
if course is not None and not isinstance(course, ErrorDescriptor):
# ignore deleted or errored courses
# Custom Courses for edX (CCX) is an edX feature for re-using course content.
# CCXs cannot be edited in Studio (aka cms) and should not be shown in this dashboard.
if course is not None and not isinstance(course, ErrorDescriptor) and not isinstance(course.id, CCXLocator):
# ignore deleted, errored or ccx courses
courses_list[course_key] = course
return courses_list.values(), in_process_course_actions