This commit adds OAuth2 support to the problem response report endpoints and moves them to a better location following EdX API standards while keeping compatibility to the old
endpoint locations.
This was done to enable the use of reports functionality by external agents and provide a better separation between backend and frontend.
The following endpoints have been moved:
* List instructor tasks:
New URL: POST /api/instructor/v1/course/{}/tasks
Old URL: POST /courses/{}/instructor/api/list_instructor_tasks
* Download instructor reports:
New URL: POST /api/instructor/v1/course/{}/reports
Old URL: POST /courses/course-v1:edX+DemoX+Demo_Course/instructor/api/list_report_downloads
* Generate problem response reports:
New URL: POST /api/instructor/v1/course/{}/reports/problem_responses
Old URL: POST /courses/course-v1:edX+DemoX+Demo_Course/instructor/api/get_problem_responses
Note: The behaviour of the URLs was not modified.
26 lines
724 B
Python
26 lines
724 B
Python
"""
|
|
Instructor permissions for class based views
|
|
"""
|
|
|
|
from django.http import Http404
|
|
from opaque_keys.edx.keys import CourseKey
|
|
from opaque_keys import InvalidKeyError
|
|
from rest_framework import permissions
|
|
|
|
from courseware.access import has_access
|
|
from courseware.courses import get_course_by_id
|
|
|
|
|
|
class IsCourseStaff(permissions.BasePermission):
|
|
"""
|
|
Check if the requesting user is a course's staff member
|
|
"""
|
|
def has_permission(self, request, view):
|
|
try:
|
|
course_key = CourseKey.from_string(view.kwargs.get('course_id'))
|
|
except InvalidKeyError:
|
|
raise Http404()
|
|
|
|
course = get_course_by_id(course_key)
|
|
return has_access(request.user, 'staff', course)
|