@@ -508,6 +508,7 @@ class LearningPackageUnzipper:
508508 def __init__ (self , zipf : zipfile .ZipFile , key : str | None = None , user : UserType | None = None ):
509509 self .zipf = zipf
510510 self .user = user
511+ self .user_id = getattr (self .user , "id" , None )
511512 self .lp_key = key # If provided, use this key for the restored learning package
512513 self .learning_package_id : int | None = None # Will be set upon restoration
513514 self .utc_now : datetime = datetime .now (timezone .utc )
@@ -771,7 +772,9 @@ def _save_collections(self, learning_package, collections):
771772 """Save collections and their entities."""
772773 for valid_collection in collections .get ("collections" , []):
773774 entities = valid_collection .pop ("entities" , [])
774- collection = collections_api .create_collection (learning_package .id , ** valid_collection )
775+ collection = collections_api .create_collection (
776+ learning_package .id , created_by = self .user_id , ** valid_collection
777+ )
775778 collection = collections_api .add_to_collection (
776779 learning_package_id = learning_package .id ,
777780 key = collection .key ,
@@ -782,7 +785,7 @@ def _save_components(self, learning_package, components, component_static_files)
782785 """Save components and published component versions."""
783786 for valid_component in components .get ("components" , []):
784787 entity_key = valid_component .pop ("key" )
785- component = components_api .create_component (learning_package .id , ** valid_component )
788+ component = components_api .create_component (learning_package .id , created_by = self . user_id , ** valid_component )
786789 self .components_map_by_key [entity_key ] = component
787790
788791 for valid_published in components .get ("components_published" , []):
@@ -796,14 +799,15 @@ def _save_components(self, learning_package, components, component_static_files)
796799 self .components_map_by_key [entity_key ].publishable_entity .id ,
797800 content_to_replace = content_to_replace ,
798801 force_version_num = valid_published .pop ("version_num" , None ),
802+ created_by = self .user_id ,
799803 ** valid_published
800804 )
801805
802806 def _save_units (self , learning_package , containers ):
803807 """Save units and published unit versions."""
804808 for valid_unit in containers .get ("unit" , []):
805809 entity_key = valid_unit .get ("key" )
806- unit = units_api .create_unit (learning_package .id , ** valid_unit )
810+ unit = units_api .create_unit (learning_package .id , created_by = self . user_id , ** valid_unit )
807811 self .units_map_by_key [entity_key ] = unit
808812
809813 for valid_published in containers .get ("unit_published" , []):
@@ -816,14 +820,17 @@ def _save_units(self, learning_package, containers):
816820 self .units_map_by_key [entity_key ],
817821 force_version_num = valid_published .pop ("version_num" , None ),
818822 components = children ,
823+ created_by = self .user_id ,
819824 ** valid_published
820825 )
821826
822827 def _save_subsections (self , learning_package , containers ):
823828 """Save subsections and published subsection versions."""
824829 for valid_subsection in containers .get ("subsection" , []):
825830 entity_key = valid_subsection .get ("key" )
826- subsection = subsections_api .create_subsection (learning_package .id , ** valid_subsection )
831+ subsection = subsections_api .create_subsection (
832+ learning_package .id , created_by = self .user_id , ** valid_subsection
833+ )
827834 self .subsections_map_by_key [entity_key ] = subsection
828835
829836 for valid_published in containers .get ("subsection_published" , []):
@@ -836,14 +843,15 @@ def _save_subsections(self, learning_package, containers):
836843 self .subsections_map_by_key [entity_key ],
837844 units = children ,
838845 force_version_num = valid_published .pop ("version_num" , None ),
846+ created_by = self .user_id ,
839847 ** valid_published
840848 )
841849
842850 def _save_sections (self , learning_package , containers ):
843851 """Save sections and published section versions."""
844852 for valid_section in containers .get ("section" , []):
845853 entity_key = valid_section .get ("key" )
846- section = sections_api .create_section (learning_package .id , ** valid_section )
854+ section = sections_api .create_section (learning_package .id , created_by = self . user_id , ** valid_section )
847855 self .sections_map_by_key [entity_key ] = section
848856
849857 for valid_published in containers .get ("section_published" , []):
@@ -856,6 +864,7 @@ def _save_sections(self, learning_package, containers):
856864 self .sections_map_by_key [entity_key ],
857865 subsections = children ,
858866 force_version_num = valid_published .pop ("version_num" , None ),
867+ created_by = self .user_id ,
859868 ** valid_published
860869 )
861870
@@ -874,6 +883,7 @@ def _save_draft_versions(self, components, containers, component_static_files):
874883 # Drafts can diverge from published, so we allow ignoring previous content
875884 # Use case: published v1 had files A, B; draft v2 only has file A
876885 ignore_previous_content = True ,
886+ created_by = self .user_id ,
877887 ** valid_draft
878888 )
879889
@@ -887,6 +897,7 @@ def _save_draft_versions(self, components, containers, component_static_files):
887897 self .units_map_by_key [entity_key ],
888898 components = children ,
889899 force_version_num = valid_draft .pop ("version_num" , None ),
900+ created_by = self .user_id ,
890901 ** valid_draft
891902 )
892903
@@ -900,6 +911,7 @@ def _save_draft_versions(self, components, containers, component_static_files):
900911 self .subsections_map_by_key [entity_key ],
901912 units = children ,
902913 force_version_num = valid_draft .pop ("version_num" , None ),
914+ created_by = self .user_id ,
903915 ** valid_draft
904916 )
905917
@@ -913,6 +925,7 @@ def _save_draft_versions(self, components, containers, component_static_files):
913925 self .sections_map_by_key [entity_key ],
914926 subsections = children ,
915927 force_version_num = valid_draft .pop ("version_num" , None ),
928+ created_by = self .user_id ,
916929 ** valid_draft
917930 )
918931
0 commit comments