Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions openedx/core/djangoapps/content_libraries/api/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.core.validators import validate_unicode_slug
from django.core.validators import RegexValidator
from django.db import transaction
from django.db.models import F, QuerySet
from django.urls import reverse
Expand Down Expand Up @@ -101,6 +101,14 @@
]


validate_block_id = RegexValidator(
r"^[\w.-]+\Z",
_(
"Block ID slugs can only have letters, numbers, underscores, hyphens, and periods."
)
)


def get_library_components(
library_key: LibraryLocatorV2,
text_search: str | None = None,
Expand Down Expand Up @@ -523,7 +531,8 @@ def validate_can_add_block_to_library(
)

# Make sure the proposed ID will be valid:
validate_unicode_slug(block_id)
validate_block_id(block_id)

# Ensure the XBlock type is valid and installed:
block_class = XBlock.load_class(block_type) # Will raise an exception if invalid
if block_class.has_children:
Expand Down
Loading