Commit 387521a4 by muzaffaryousaf

Updating the require_course_staff decorator to work with json handler.

TNL-900
parent 1b6ea97c
......@@ -4,9 +4,11 @@ determine the flow of the problem.
"""
import copy
from functools import wraps
import json
import logging
from xblock.core import XBlock
import sys
from openassessment.assessment.errors import (
PeerAssessmentInternalError, PeerAssessmentWorkflowError,
)
......@@ -74,7 +76,10 @@ def require_course_staff(error_key, with_json_handler=False):
"STUDENT_INFO": xblock._(u"You do not have permission to access student information."),
}
if (not xblock.is_course_staff and with_json_handler) or xblock.in_studio_preview:
if not xblock.is_course_staff and with_json_handler:
return {"success": False, "msg": permission_errors[error_key]}
elif not xblock.is_course_staff or xblock.in_studio_preview:
return xblock.render_error(permission_errors[error_key])
else:
return func(xblock, *args, **kwargs)
......
......@@ -520,8 +520,9 @@ class TestCourseStaff(XBlockHandlerTestCase):
def test_cancel_submission_without_reason(self, xblock):
# If we're not course staff, we shouldn't be able to see the
# cancel submission option
xblock.xmodule_runtime = Mock(user_is_staff=False)
self.assertFalse(xblock.is_course_staff)
xblock.xmodule_runtime = self._create_mock_runtime(
xblock.scope_ids.usage_id, False, False, "Bob"
)
resp = self.request(xblock, 'cancel_submission', json.dumps({}))
self.assertIn("you do not have permission", resp.decode('utf-8').lower())
......
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