|
11 | 11 | from rest_framework import status |
12 | 12 | from rest_framework.exceptions import ParseError |
13 | 13 | from rest_framework.mixins import ListModelMixin |
14 | | -from rest_framework.permissions import IsAdminUser |
| 14 | +from rest_framework.permissions import IsAdminUser, IsAuthenticated |
15 | 15 | from rest_framework.response import Response |
16 | 16 | from rest_framework.views import APIView |
17 | 17 | from rest_framework.viewsets import GenericViewSet |
18 | 18 | from user_tasks.models import UserTaskStatus |
19 | 19 | from user_tasks.views import StatusViewSet |
| 20 | +from opaque_keys.edx.keys import CourseKey |
20 | 21 |
|
21 | 22 | from cms.djangoapps.modulestore_migrator.api import ( |
22 | 23 | start_migration_to_library, |
|
26 | 27 | from openedx.core.djangoapps.content.course_overviews.models import CourseOverview |
27 | 28 | from openedx.core.djangoapps.content_libraries import api as lib_api |
28 | 29 | from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser |
| 30 | +from common.djangoapps.student.auth import has_studio_write_access |
29 | 31 |
|
30 | 32 | from ...models import ModulestoreMigration |
31 | 33 | from .serializers import ( |
@@ -392,7 +394,7 @@ class MigrationInfoViewSet(APIView): |
392 | 394 | } |
393 | 395 | """ |
394 | 396 |
|
395 | | - permission_classes = (IsAdminUser,) |
| 397 | + permission_classes = (IsAuthenticated,) |
396 | 398 | authentication_classes = ( |
397 | 399 | BearerAuthenticationAllowInactiveUser, |
398 | 400 | JwtAuthentication, |
@@ -425,7 +427,18 @@ def get(self, request): |
425 | 427 | status=status.HTTP_400_BAD_REQUEST |
426 | 428 | ) |
427 | 429 |
|
428 | | - data = get_all_migrations_info(source_keys) |
| 430 | + # Check permissions for each source_key: |
| 431 | + # Skip the source if the key is invalid or if the user doesn't have permissions |
| 432 | + source_keys_validated = [] |
| 433 | + for source_key in source_keys: |
| 434 | + try: |
| 435 | + key = CourseKey.from_string(source_key) |
| 436 | + if has_studio_write_access(request.user, key): |
| 437 | + source_keys_validated.append(key) |
| 438 | + except InvalidKeyError: |
| 439 | + continue |
| 440 | + |
| 441 | + data = get_all_migrations_info(source_keys_validated) |
429 | 442 | serializer = MigrationInfoResponseSerializer(data) |
430 | 443 | return Response(serializer.data) |
431 | 444 |
|
|
0 commit comments