Skip to content

Commit

Permalink
feat: Verify key uniques in creating collection view
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChV committed Sep 7, 2024
1 parent 590fc0e commit 10f3e49
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion openedx/core/djangoapps/content_libraries/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class LibraryCollectionCreationSerializer(serializers.Serializer):
"""

title = serializers.CharField()
description = serializers.CharField()
description = serializers.CharField(allow_blank=True)

class LibraryCollectionMetadataSerializer(serializers.Serializer):
"""
Expand Down
20 changes: 11 additions & 9 deletions openedx/core/djangoapps/content_libraries/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
from django.contrib.auth import authenticate, get_user_model, login
from django.contrib.auth.models import Group
from django.db.transaction import atomic, non_atomic_requests
from django.db.utils import IntegrityError
from django.http import Http404, HttpResponseBadRequest, JsonResponse
from django.shortcuts import get_object_or_404
from django.urls import reverse
Expand Down Expand Up @@ -863,15 +864,16 @@ def post(self, request, lib_key_str):

key = slugify(title)

# TODO verify if key is unique

result = authoring_api.create_collection(
learning_package_id=library.learning_package_id,
key=key,
title=title,
description=serializer.validated_data['description'],
created_by=request.user.id,
)
try:
result = authoring_api.create_collection(
learning_package_id=library.learning_package_id,
key=key,
title=title,
description=serializer.validated_data['description'],
created_by=request.user.id,
)
except IntegrityError:
return Response(status=status.HTTP_409_CONFLICT)

return Response(LibraryCollectionMetadataSerializer(result).data)

Expand Down

0 comments on commit 10f3e49

Please sign in to comment.