Commit e9c70633 by Don Mitchell

Add delete if staff member

parent 6b979752
......@@ -56,3 +56,17 @@ class TestOrphan(CourseTestCase):
self.assertIn(location.url(), orphans)
location = self.course.location.replace(category='html', name='OrphanHtml')
self.assertIn(location.url(), orphans)
def test_mongo_orphan_delete(self):
"""
Test that old mongo deletes the orphans
"""
url = reverse(
'orphan',
kwargs={'course_id': '{}.{}'.format(self.course.location.org, self.course.location.course)}
)
self.client.delete(url)
orphans = json.loads(
self.client.get(url, HTTP_ACCEPT='application/json').content
)
self.assertEqual(len(orphans), 0, "Orphans not deleted {}".format(orphans))
......@@ -20,6 +20,7 @@ from ..utils import get_modulestore
from .access import has_access
from .helpers import _xmodule_recurse
from xmodule.x_module import XModuleDescriptor
from django.views.decorators.http import require_http_methods
__all__ = ['save_item', 'create_item', 'delete_item', 'orphan']
......@@ -203,6 +204,7 @@ def delete_item(request):
@login_required
@require_http_methods(("GET", "DELETE"))
def orphan(request, course_id):
"""
View for handling orphan related requests. A get gets all of the current orphans.
......@@ -214,6 +216,10 @@ def orphan(request, course_id):
:param request:
:param course_id: Locator syntax course_id
"""
# dhm: I'd add DELETE but I'm not sure what type of authentication/authorization we'd need
if request.method == 'GET':
return JsonResponse(modulestore().get_orphans(course_id, DETACHED_CATEGORIES, 'draft'))
if request.method == 'DELETE' and request.user.is_staff:
items = modulestore().get_orphans(course_id, DETACHED_CATEGORIES, 'draft')
for item in items:
modulestore('draft').delete_item(item, True)
return JsonResponse({'deleted': items})
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