Skip to content

Commit

Permalink
feat: make downstream copied tags editable when upstream block is del…
Browse files Browse the repository at this point in the history
…eted
  • Loading branch information
pomegranited committed Feb 6, 2025
1 parent a42de38 commit 7e57960
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cms/djangoapps/contentstore/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import openedx.core.djangoapps.content_staging.api as content_staging_api
import openedx.core.djangoapps.content_tagging.api as content_tagging_api

from .models import PublishableEntityLink
from .utils import reverse_course_url, reverse_library_url, reverse_usage_url

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -324,6 +325,18 @@ def import_staged_content_from_user_clipboard(parent_key: UsageKey, request) ->
return new_xblock, notices


def make_downstream_tags_editable(upstream_usage_key: UsageKey) -> None:
"""
Update the tags copied to the downstream objects to make them editable.
This should be called when the upstream link to the downstream object is severed.
"""
for link in PublishableEntityLink.objects.filter(
upstream_usage_key=upstream_usage_key,
):
content_tagging_api.make_copied_tags_editable(str(link.downstream_usage_key))


def _fetch_and_set_upstream_link(
copied_from_block: str,
copied_from_version_num: int,
Expand Down
10 changes: 10 additions & 0 deletions cms/djangoapps/contentstore/views/tests/test_clipboard_paste.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,16 @@ def test_paste_from_library_read_only_tags(self):
assert object_tag.value in self.lib_block_tags
assert object_tag.is_copied

# If we delete the upstream library block...
library_api.delete_library_block(self.lib_block_key)

# ...the copied tags remain, but should no longer be marked as "copied"
object_tags = tagging_api.get_object_tags(new_block_key)
assert len(object_tags) == len(self.lib_block_tags)
for object_tag in object_tags:
assert object_tag.value in self.lib_block_tags
assert not object_tag.is_copied

def test_paste_from_library_copies_asset(self):
"""
Assets from a library component copied into a subdir of Files & Uploads.
Expand Down
4 changes: 4 additions & 0 deletions openedx/core/djangoapps/content_libraries/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,10 @@ def delete_library_block(usage_key, remove_from_parent=True):

authoring_api.soft_delete_draft(component.pk)

# Import here to avoid breaking the LMS
from cms.djangoapps.contentstore import helpers as studio_helpers
studio_helpers.make_downstream_tags_editable(usage_key)

LIBRARY_BLOCK_DELETED.send_event(
library_block=LibraryBlockData(
library_key=library_key,
Expand Down
1 change: 1 addition & 0 deletions openedx/core/djangoapps/content_tagging/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,4 @@ def tag_object(
get_object_tags = oel_tagging.get_object_tags
add_tag_to_taxonomy = oel_tagging.add_tag_to_taxonomy
copy_tags_as_read_only = oel_tagging.copy_tags
make_copied_tags_editable = oel_tagging.unmark_copied_tags

0 comments on commit 7e57960

Please sign in to comment.