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