Skip to content

Commit 454a0c7

Browse files
committed
fix: Add permission to migration info view
1 parent 951ab38 commit 454a0c7

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

  • cms/djangoapps/modulestore_migrator/rest_api/v1
  • openedx/core/djangoapps/content_libraries

cms/djangoapps/modulestore_migrator/rest_api/v1/views.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
from rest_framework import status
1212
from rest_framework.exceptions import ParseError
1313
from rest_framework.mixins import ListModelMixin
14-
from rest_framework.permissions import IsAdminUser
14+
from rest_framework.permissions import IsAdminUser, IsAuthenticated
1515
from rest_framework.response import Response
1616
from rest_framework.views import APIView
1717
from rest_framework.viewsets import GenericViewSet
1818
from user_tasks.models import UserTaskStatus
1919
from user_tasks.views import StatusViewSet
20+
from opaque_keys.edx.keys import CourseKey
2021

2122
from cms.djangoapps.modulestore_migrator.api import (
2223
start_migration_to_library,
@@ -26,6 +27,7 @@
2627
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
2728
from openedx.core.djangoapps.content_libraries import api as lib_api
2829
from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser
30+
from common.djangoapps.student.auth import has_studio_write_access
2931

3032
from ...models import ModulestoreMigration
3133
from .serializers import (
@@ -392,7 +394,7 @@ class MigrationInfoViewSet(APIView):
392394
}
393395
"""
394396

395-
permission_classes = (IsAdminUser,)
397+
permission_classes = (IsAuthenticated,)
396398
authentication_classes = (
397399
BearerAuthenticationAllowInactiveUser,
398400
JwtAuthentication,
@@ -425,7 +427,18 @@ def get(self, request):
425427
status=status.HTTP_400_BAD_REQUEST
426428
)
427429

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)
429442
serializer = MigrationInfoResponseSerializer(data)
430443
return Response(serializer.data)
431444

openedx/core/djangoapps/content_libraries/tasks.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ def send_events_after_publish(publish_log_pk: int, library_key_str: str) -> None
127127
elif hasattr(record.entity, "container"):
128128
container_key = api.library_container_locator(library_key, record.entity.container)
129129
affected_containers.add(container_key)
130+
131+
try:
132+
# We do need to notify listeners that the parent container(s) have changed,
133+
# e.g. so the search index can update the "has_unpublished_changes"
134+
for parent_container in api.get_containers_contains_item(container_key):
135+
affected_containers.add(parent_container.container_key)
136+
# TODO: should this be a CONTAINER_CHILD_PUBLISHED event instead of CONTAINER_PUBLISHED ?
137+
except api.ContentLibraryContainerNotFound:
138+
# The deleted children remains in the entity, so, in this case, the container may not be found.
139+
pass
130140
else:
131141
log.warning(
132142
f"PublishableEntity {record.entity.pk} / {record.entity.key} was modified during publish operation "

0 commit comments

Comments
 (0)