@@ -591,7 +591,7 @@ def _import_staged_block(
591591 olx_str : str ,
592592 library_key : LibraryLocatorV2 ,
593593 source_context_key : LearningContextKey ,
594- user ,
594+ user : UserType ,
595595 staged_content_id : StagedContentID ,
596596 staged_content_files : list [StagedContentFileData ],
597597 now : datetime ,
@@ -697,7 +697,7 @@ def _import_staged_block(
697697 # This will create the first component version and set the OLX/title
698698 # appropriately. It will not publish. Once we get the newly created
699699 # ComponentVersion back from this, we can attach all our files to it.
700- set_library_block_olx (usage_key , olx_str , paths_to_media )
700+ set_library_block_olx (usage_key , olx_str , paths_to_media , created_by = user . id )
701701
702702 # Now return the metadata about the new block
703703 return get_library_block (usage_key )
@@ -713,7 +713,7 @@ def _is_container(block_type: str) -> bool:
713713def _import_staged_block_as_container (
714714 library_key : LibraryLocatorV2 ,
715715 source_context_key : LearningContextKey ,
716- user ,
716+ user : UserType ,
717717 staged_content_id : StagedContentID ,
718718 staged_content_files : list [StagedContentFileData ],
719719 now : datetime ,
@@ -829,7 +829,7 @@ def _import_staged_block_as_container(
829829 return container
830830
831831
832- def import_staged_content_from_user_clipboard (library_key : LibraryLocatorV2 , user ) -> PublishableItem :
832+ def import_staged_content_from_user_clipboard (library_key : LibraryLocatorV2 , user : UserType ) -> PublishableItem :
833833 """
834834 Create a new library item from the staged content from clipboard.
835835 Can create containers (e.g. units) or XBlocks.
@@ -852,11 +852,11 @@ def import_staged_content_from_user_clipboard(library_key: LibraryLocatorV2, use
852852 raise RuntimeError ("olx_str missing" ) # Shouldn't happen - mostly here for type checker
853853
854854 now = datetime .now (tz = timezone .utc ) # noqa: UP017
855+ lp_id = ContentLibrary .objects .get_by_key (library_key ).learning_package_id
855856
856- if _is_container (user_clipboard .content .block_type ):
857- # This is a container and we can import it as such.
858- # Start an atomic section so the whole paste succeeds or fails together:
859- with transaction .atomic ():
857+ # Start an atomic section so the whole paste succeeds or fails together and creates a single change log entry:
858+ with transaction .atomic (), content_api .bulk_draft_changes_for (lp_id , changed_by = user .id , changed_at = now ):
859+ if _is_container (user_clipboard .content .block_type ):
860860 return _import_staged_block_as_container (
861861 library_key ,
862862 source_context_key ,
@@ -866,17 +866,17 @@ def import_staged_content_from_user_clipboard(library_key: LibraryLocatorV2, use
866866 now ,
867867 olx_str = olx_str ,
868868 )
869- else :
870- return _import_staged_block (
871- user_clipboard .content .block_type ,
872- olx_str ,
873- library_key ,
874- source_context_key ,
875- user ,
876- staged_content_id ,
877- staged_content_files ,
878- now ,
879- )
869+ else :
870+ return _import_staged_block (
871+ user_clipboard .content .block_type ,
872+ olx_str ,
873+ library_key ,
874+ source_context_key ,
875+ user ,
876+ staged_content_id ,
877+ staged_content_files ,
878+ now ,
879+ )
880880
881881def get_or_create_olx_media_type (block_type : str ) -> MediaType :
882882 """
0 commit comments