Commit 955e54c2 by Chris Dodge

refactor some code out of the django-admin entry point into a help function in…

refactor some code out of the django-admin entry point into a help function in CMS. Update tests to use new method
parent 2ac6d78a
......@@ -2,14 +2,8 @@
### Script for cloning a course
###
from django.core.management.base import BaseCommand, CommandError
from xmodule.modulestore.store_utilities import delete_course
from xmodule.modulestore.django import modulestore
from xmodule.contentstore.django import contentstore
from xmodule.course_module import CourseDescriptor
from .prompt import query_yes_no
from django_comment_common.utils import unseed_permissions_roles
from auth.authz import _delete_course_group
from contentstore.utils import delete_course_and_groups
#
......@@ -31,23 +25,6 @@ class Command(BaseCommand):
if commit:
print 'Actually going to delete the course from DB....'
ms = modulestore('direct')
cs = contentstore()
org, course_num, run = course_id.split("/")
ms.ignore_write_events_on_courses.append('{0}/{1}'.format(org, course_num))
if query_yes_no("Deleting course {0}. Confirm?".format(course_id), default="no"):
if query_yes_no("Are you sure. This action cannot be undone!", default="no"):
loc = CourseDescriptor.id_to_location(course_id)
if delete_course(ms, cs, loc, commit):
print 'removing forums permissions and roles...'
unseed_permissions_roles(course_id)
print 'removing User permissions from course....'
# in the django layer, we need to remove all the user permissions groups associated with this course
if commit:
try:
_delete_course_group(loc)
except Exception as err:
print("Error in deleting course groups for {0}: {1}".format(loc, err))
delete_course_and_groups(course_id, commit)
......@@ -55,7 +55,7 @@ from uuid import uuid4
from pymongo import MongoClient
from student.models import CourseEnrollment
from django_comment_common.utils import unseed_permissions_roles
from contentstore.utils import delete_course_and_groups
TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE)
TEST_DATA_CONTENTSTORE['OPTIONS']['db'] = 'test_xcontent_%s' % uuid4().hex
......@@ -1294,24 +1294,14 @@ class ContentStoreTest(ModuleStoreTestCase):
test_course_data = self.assert_created_course(number_suffix=uuid4().hex)
self.assertTrue(are_permissions_roles_seeded(self._get_course_id(test_course_data)))
def test_forum_unseeding(self):
def test_forum_unseeding_on_delete(self):
"""Test new course creation and verify forum unseeding """
test_course_data = self.assert_created_course(number_suffix=uuid4().hex)
self.assertTrue(are_permissions_roles_seeded(self._get_course_id(test_course_data)))
course_id = self._get_course_id(test_course_data)
unseed_permissions_roles(course_id)
delete_course_and_groups(course_id, commit=True)
self.assertFalse(are_permissions_roles_seeded(course_id))
def test_forum_unseeding_with_different_casing(self):
"""Make sure that we honor case sensitivity when unseeding forums"""
test_course_data = self.assert_created_course(number_suffix=uuid4().hex)
# make sure we don't delete a forum permissions set with different casing
# than the passed in course_id. This is because Mongo and MySQL are using different collations
course_id = self._get_course_id(test_course_data)
unseed_permissions_roles(course_id.upper())
# permissions should still be there!
self.assertTrue(are_permissions_roles_seeded(course_id))
def test_forum_unseeding_with_multiple_courses(self):
"""Test new course creation and verify forum unseeding when there are multiple courses"""
test_course_data = self.assert_created_course(number_suffix=uuid4().hex)
......@@ -1319,7 +1309,7 @@ class ContentStoreTest(ModuleStoreTestCase):
# unseed the forums for the first course
course_id = self._get_course_id(test_course_data)
unseed_permissions_roles(course_id)
delete_course_and_groups(course_id, commit=True)
self.assertFalse(are_permissions_roles_seeded(course_id))
second_course_id = self._get_course_id(second_course_data)
......
......@@ -5,12 +5,16 @@ from xmodule.modulestore import Location
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.exceptions import ItemNotFoundError
from xmodule.contentstore.content import StaticContent
from django.core.urlresolvers import reverse
from xmodule.contentstore.django import contentstore
import copy
import logging
import re
from xmodule.modulestore.draft import DIRECT_ONLY_CATEGORIES
from django.utils.translation import ugettext as _
from django_comment_common.utils import unseed_permissions_roles
from auth.authz import _delete_course_group
from xmodule.modulestore.store_utilities import delete_course
from xmodule.course_module import CourseDescriptor
log = logging.getLogger(__name__)
......@@ -20,6 +24,31 @@ NOTES_PANEL = {"name": _("My Notes"), "type": "notes"}
EXTRA_TAB_PANELS = dict([(p['type'], p) for p in [OPEN_ENDED_PANEL, NOTES_PANEL]])
def delete_course_and_groups(course_id, commit=False):
"""
This deletes the courseware associated with a course_id as well as cleaning update_item
the various user table stuff (groups, permissions, etc.)
"""
module_store = modulestore('direct')
content_store = contentstore()
org, course_num, run = course_id.split("/")
module_store.ignore_write_events_on_courses.append('{0}/{1}'.format(org, course_num))
loc = CourseDescriptor.id_to_location(course_id)
if delete_course(module_store, content_store, loc, commit):
print 'removing forums permissions and roles...'
unseed_permissions_roles(course_id)
print 'removing User permissions from course....'
# in the django layer, we need to remove all the user permissions groups associated with this course
if commit:
try:
_delete_course_group(loc)
except Exception as err:
log.error("Error in deleting course groups for {0}: {1}".format(loc, err))
def get_modulestore(category_or_location):
"""
Returns the correct modulestore to use for modifying the specified location
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment