|
11 | 11 | import re |
12 | 12 | import shutil |
13 | 13 | from wsgiref.util import FileWrapper |
| 14 | +from openedx_authz.constants.permissions import COURSES_EXPORT_COURSE, COURSES_IMPORT_COURSE |
14 | 15 |
|
15 | 16 | from django.conf import settings |
16 | 17 | from django.contrib.auth.decorators import login_required |
|
32 | 33 | from user_tasks.conf import settings as user_tasks_settings |
33 | 34 | from user_tasks.models import UserTaskArtifact, UserTaskStatus |
34 | 35 |
|
| 36 | +from openedx.core.djangoapps.authz.constants import LegacyAuthoringPermission |
| 37 | +from openedx.core.djangoapps.authz.decorators import user_has_course_permission |
35 | 38 | from common.djangoapps.edxmako.shortcuts import render_to_response |
36 | | -from common.djangoapps.student.auth import has_course_author_access |
37 | 39 | from common.djangoapps.util.json_request import JsonResponse |
38 | 40 | from common.djangoapps.util.monitoring import monitor_import_failure |
39 | 41 | from common.djangoapps.util.views import ensure_valid_course_key |
@@ -87,7 +89,12 @@ def import_handler(request, course_key_string): |
87 | 89 | successful_url = reverse_course_url('course_handler', courselike_key) |
88 | 90 | context_name = 'context_course' |
89 | 91 | courselike_block = modulestore().get_course(courselike_key) |
90 | | - if not has_course_author_access(request.user, courselike_key): |
| 92 | + if not user_has_course_permission( |
| 93 | + user=request.user, |
| 94 | + authz_permission=COURSES_IMPORT_COURSE.identifier, |
| 95 | + course_key=courselike_key, |
| 96 | + legacy_permission=LegacyAuthoringPermission.WRITE |
| 97 | + ): |
91 | 98 | raise PermissionDenied() |
92 | 99 |
|
93 | 100 | if 'application/json' in request.META.get('HTTP_ACCEPT', 'application/json'): |
@@ -257,7 +264,12 @@ def import_status_handler(request, course_key_string, filename=None): |
257 | 264 |
|
258 | 265 | """ |
259 | 266 | course_key = CourseKey.from_string(course_key_string) |
260 | | - if not has_course_author_access(request.user, course_key): |
| 267 | + if not user_has_course_permission( |
| 268 | + user=request.user, |
| 269 | + authz_permission=COURSES_IMPORT_COURSE.identifier, |
| 270 | + course_key=course_key, |
| 271 | + legacy_permission=LegacyAuthoringPermission.WRITE |
| 272 | + ): |
261 | 273 | raise PermissionDenied() |
262 | 274 |
|
263 | 275 | # The task status record is authoritative once it's been created |
@@ -318,7 +330,12 @@ def export_handler(request, course_key_string): |
318 | 330 | a link appearing on the page once it's ready. |
319 | 331 | """ |
320 | 332 | course_key = CourseKey.from_string(course_key_string) |
321 | | - if not has_course_author_access(request.user, course_key): |
| 333 | + if not user_has_course_permission( |
| 334 | + user=request.user, |
| 335 | + authz_permission=COURSES_EXPORT_COURSE.identifier, |
| 336 | + course_key=course_key, |
| 337 | + legacy_permission=LegacyAuthoringPermission.WRITE |
| 338 | + ): |
322 | 339 | raise PermissionDenied() |
323 | 340 | library = isinstance(course_key, LibraryLocator) |
324 | 341 | if library: |
@@ -373,7 +390,12 @@ def export_status_handler(request, course_key_string): |
373 | 390 | returned. |
374 | 391 | """ |
375 | 392 | course_key = CourseKey.from_string(course_key_string) |
376 | | - if not has_course_author_access(request.user, course_key): |
| 393 | + if not user_has_course_permission( |
| 394 | + user=request.user, |
| 395 | + authz_permission=COURSES_EXPORT_COURSE.identifier, |
| 396 | + course_key=course_key, |
| 397 | + legacy_permission=LegacyAuthoringPermission.WRITE |
| 398 | + ): |
377 | 399 | raise PermissionDenied() |
378 | 400 |
|
379 | 401 | # The task status record is authoritative once it's been created |
@@ -435,7 +457,12 @@ def export_output_handler(request, course_key_string): |
435 | 457 | filesystem instead of an external service like S3. |
436 | 458 | """ |
437 | 459 | course_key = CourseKey.from_string(course_key_string) |
438 | | - if not has_course_author_access(request.user, course_key): |
| 460 | + if not user_has_course_permission( |
| 461 | + user=request.user, |
| 462 | + authz_permission=COURSES_EXPORT_COURSE.identifier, |
| 463 | + course_key=course_key, |
| 464 | + legacy_permission=LegacyAuthoringPermission.WRITE |
| 465 | + ): |
439 | 466 | raise PermissionDenied() |
440 | 467 |
|
441 | 468 | task_status = _latest_task_status(request, course_key_string, export_output_handler) |
|
0 commit comments