Skip to content

Conversation

@cmltaWt0
Copy link
Contributor

@cmltaWt0 cmltaWt0 commented Mar 17, 2025

@cmltaWt0 cmltaWt0 self-assigned this Mar 17, 2025
@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Mar 17, 2025
@openedx-webhooks
Copy link

openedx-webhooks commented Mar 17, 2025

Thanks for the pull request, @cmltaWt0!

This repository is currently maintained by @openedx/wg-maintenance-edx-platform.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.


Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

Copy link
Member

@kdmccormick kdmccormick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the prototype Max!

One high-level direction question for @ormsbee about whether to combine these models with my legacy library import models. If he thinks they should stay separate, then @cmltaWt0 I have some data model comments for this PR.

Comment on lines 26 to 30
status = models.CharField(
max_length=100,
choices=CourseToLibraryImportStatus.choices,
default=CourseToLibraryImportStatus.PENDING
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have django-user-tasks for situations where we need to track that status of a Celery task and associate it with a user. Example - CourseExport

Would you be able to leverage that library as the basis for this?

Comment on lines 31 to 35
course_ids = models.TextField(
blank=False,
help_text=_('Whitespace-separated list of course keys for which to compute grades.'),
validators=[validate_course_ids]
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have one course per model instance. That way, this could be a LearningContextKeyField, and we'd have simpler validation and querying of this table. It will also make it easier to manage these tasks in Django admin if each one is associated with a single course.

If it makes this PR easier, you can assume that we are importing one course at a time. If it becomes important, we can implement multi-course import later at the REST API layer, and have a separate task model to track it.

help_text=_('Whitespace-separated list of course keys for which to compute grades.'),
validators=[validate_course_ids]
)
library_key = models.CharField(max_length=100)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this a ForeignKey to ContentLibrary (or even LearningPackage). That gets us a few benefits:

  • We get more efficient JOINs when querying
  • We get database-level validation that we this model points at a valid learning package

validators=[validate_course_ids]
)
library_key = models.CharField(max_length=100)
source_type = models.CharField(max_length=30)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is source_type for?

)
library_key = models.CharField(max_length=100)
source_type = models.CharField(max_length=30)
metadata = models.JSONField(default=dict, blank=True, null=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is metadata for?

Represents a component version that has been imported into a content library.
This is a many-to-many relationship between a component version and a course to library import.
"""

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us also add an FK to Component. That way, we can declare that component and library_import are unique_together.

I believe source_usage_key and library_import can also be declared as unique_together.

In other words, we assert that for any given library import event, the source block is unique, and the destination block is unique.

return cls.objects.filter(id=import_id).first()


class ComponentVersionImport(TimeStampedModel):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Soon we will need to support container imports as well. When that time comes, were you thinking that we'd have a separate ContainerImport model? Or, should we generalize this model into PublishableEntityImport?

@@ -0,0 +1,74 @@
"""
Models for the course to library import app.
Copy link
Member

@kdmccormick kdmccormick Mar 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize that I was quite insistent earlier that this app should explicitly focus on course-to-library imports. As I've worked on the legacy library migration, though, I'm realizing I may have been wrong about that. I see a lot of parallels between these models, and the legacy-lib-to-library models in my PR.

@ormsbee , do you think it would be reasonable to consider this djangoapp as a general import_to_learning_package application? The models would be something like:

class LegacyContentImportStatus(UserTaskStatus): ...

class LegacyContentImportSource(Model):
    context_key = LearningContextKeyField(...)  # course or legacy lib
    authoritative_import = FK(LegacyContentToLearningPackageImport, null=True)  # where to forward content to, if applicable

class LegacyContentToLearningPackageImport(Model):
    source = FK(LegacyContentImportSource)
    import = OneToOneField(LearningPackageImport)

class LearningPackageImport(Model):
       target = FK(LearningPackage)  # destination lib (or, in the future, learning-core course?)
    target_collection = FK(Collection, null=True)  # if applicable

class LegacyContentToPublishableEntityImport(Model):
    package_migration = FK(LegacyContentToLearningPackageMigration)
    source = UsageKeyField()
    target = FK(PublishableEntity)
    class Meta:
        unique_together = [("package_migration", "source"), ("package_migration", "target")]

@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Mar 19, 2025
@kdmccormick kdmccormick self-requested a review March 26, 2025 19:11
@NiedielnitsevIvan NiedielnitsevIvan force-pushed the axm-course-to-library-import branch from b9e7dab to 7f9ae62 Compare April 4, 2025 14:46
@ormsbee ormsbee marked this pull request as ready for review April 4, 2025 16:14
@ormsbee
Copy link
Contributor

ormsbee commented Apr 4, 2025

Per today's meeting, marking this as ready for review. Testing is happening now, bug fixes may be added in the coming days.

@NiedielnitsevIvan NiedielnitsevIvan force-pushed the axm-course-to-library-import branch from 7f9ae62 to 270b825 Compare April 7, 2025 08:40
@kdmccormick kdmccormick added the create-sandbox open-craft-grove should create a sandbox environment from this PR label Apr 7, 2025
@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@NiedielnitsevIvan NiedielnitsevIvan force-pushed the axm-course-to-library-import branch from 4c2caef to 6ad5283 Compare April 8, 2025 07:22
@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@kdmccormick
Copy link
Member

@cmltaWt0 @NiedielnitsevIvan I am currently reviewing this. Please rebase when you get a chance.

andrii-hantkovskyi and others added 9 commits April 10, 2025 11:39
* feat: [AXM-1607] create initial DB layer

* refactor: [AXM-1607] resolve lint errors, clean up code & add migrations

* refactor: [AXM-1607] simplify raw user_id in admin & improve validation by checking for duplicate keys

* refactor: [AXM-1607] lint fixes #2

---------

Co-authored-by: Andrii <andrii.hantkovskyi@raccoongang.com>
* feat: [AXM-1621] add staged content creation

* refactor: [AXM-1621] revert unnecessary changes & functions refactor

* feat: [AXM-1621] add CourseToLibraryImport creation & update + refactor to process multiple course ids

---------

Co-authored-by: Andrii <andrii.hantkovskyi@raccoongang.com>
* feat: [AXM-1614] add course to library import feature
* feat: [AXM-1726] add container feature for import

* refactor: [AXM-1726] post-review changes

---------

Co-authored-by: Andrii <andrii.hantkovskyi@raccoongang.com>
* feat: [AXM-1635] create block importing route
* feat: [AXM-1780] add static tabs importing

* refactor: [AXM-1780] rename  to

---------

Co-authored-by: Andrii <andrii.hantkovskyi@raccoongang.com>
* feat: REST API to get and create imports

* test: add tests for new APIs
NiedielnitsevIvan and others added 11 commits April 10, 2025 11:42
* refactor: refactor import creation api and task

* test: refactor and improve tests

* style: fix code style

* refactor: refactor relation between CourseToLibraryImport and StagedContent

* refactor: fix tests after refactoring

* refactor: add CourseToLibraryImport relation to ContentLibrary

* feat: add ContentLibraryFactory

* test: refactor tests after change relations

* feat: add CANCELED status

* refactor: rename app, refactor models and Python APIs

* fix: fix REST APIs after refactoring

* fix: fix tests after refactoring

* test: add LearningPackageFactory

* style: remove extra import

* chore: update migration
Co-authored-by: Andrii <andrii.hantkovskyi@raccoongang.com>
* feat: add admin action to import course to library

* refactor: [AXM-1807] finish actions, refactor validation & purpose uniq

---------

Co-authored-by: Andrii <andrii.hantkovskyi@raccoongang.com>
Co-authored-by: Andrii <andrii.hantkovskyi@raccoongang.com>
* fix: fix deadlock when import created from admin panel

* refactor: rename celery task
…2631)

Co-authored-by: Andrii <andrii.hantkovskyi@raccoongang.com>
Co-authored-by: Andrii <andrii.hantkovskyi@raccoongang.com>
@NiedielnitsevIvan NiedielnitsevIvan force-pushed the axm-course-to-library-import branch from 41f1d89 to aa35955 Compare April 10, 2025 08:45
@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

andrii-hantkovskyi and others added 2 commits April 10, 2025 15:03
Co-authored-by: Andrii <andrii.hantkovskyi@raccoongang.com>
@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@kdmccormick
Copy link
Member

@NiedielnitsevIvan to help me review this, could you add details to the PR description on:

  1. the REST API endpoints that you added or updated, with an example of how to use each of them
  2. how to use the django admin workflow

@NiedielnitsevIvan
Copy link
Contributor

@kdmccormick Of course, here are Postman collections for these new APIs, just add the bearer token and everything should work.
AXIM_import_APIs.postman_collection.json

@cmltaWt0 is the author of this PR, so I can't update the description right now, so I'll describe it here for now.

Instructions for testing the django admin workflow:

  • create a course and add several different blocks for it
  • create a Content Library
  • Go to the admin panel <cms_url>/admin/import_from_modulestore/import/ and click "Add Import from modulestore"
  • Fill out the form with your user ID, course ID that you plan to import and Content Library ID to which the import will take place
  • save the form and wait until the status of the import you created is "Ready"
  • Select your import and select the action "Import selected courses to library"
  • In the form that appears, select the desired Composition Level (currently only 2 are functional: XBlock and Unit) and specify the block usage IDs you plan to import.
    • To get the block usage ID, go to /admin/content_staging/stagedcontent/ in the admin panel and select the record that refers to your course and copy them.
  • After submitting the form, a celery task is launched that performs the import, so if you are importing a large number of blocks, you will have to wait a little.

@kdmccormick
Copy link
Member

@NiedielnitsevIvan I would like to review the schema of the REST API, but that is hard to do just by reverse engineering the python code and the postman collection. Could you list out the new URLs and their methods? For example: https://github.com/openedx/edx-platform/blob/master/cms/djangoapps/contentstore/rest_api/v2/views/downstreams.py#L4

Just put them in a PR comment for now, and once we are in agreement, you can move them into a code comment.

Co-authored-by: Andrii <andrii.hantkovskyi@raccoongang.com>
@open-craft-grove
Copy link

Sandbox deployment successful 🚀
🎓 LMS
📝 Studio
ℹ️ Grove Config, Tutor Config, Tutor Requirements

@NiedielnitsevIvan NiedielnitsevIvan force-pushed the axm-course-to-library-import branch from d578dd3 to ffe6598 Compare April 11, 2025 09:22
@NiedielnitsevIvan
Copy link
Contributor

@kdmccormick Oh, sorry, I misunderstood you a bit, here are the schemas of the new REST APIs:

  1. CreateCourseToLibraryImportView
    Create course to library import.
    
    **Example Request**
        POST /api/import_from_modulestore/v0/create_import/<content_library_id>/
    
    **Example request data**
        ```
        {
            "course_ids": ["course-v1:edX+DemoX+Demo_Course", "course-v1:edX+M12+2025"],
        }
        ```
    
    **POST Parameters**
        - course_ids (list): A list of course IDs for which imports will be created
            and content will be saved to the Staged Content.
    
    **Responses**
        - 200: Imports created successfully and saving content to Staged Content started.
        - 400: Invalid request data.
        - 401: Unauthorized.
        - 403: Forbidden.
        - 404: ContentLibrary not found.
    
    **Example Response**:
        ```
        [
            {
              "course_id": "course-v1:edX+DemoX+Demo_Course",
              "status": "pending",
              "library_key": "lib:edX:1",
              "uuid": "89b71d29-2135-4cf2-991d-e4e13b5a959a"
            },
            {
              "course_id": "course-v1:edX+M12+2025",
              "status": "pending",
              "library_key": "lib:edX:1",
              "uuid": "0782921a-4b56-4972-aa3a-edd1c99de85f"
            },
        ]
        ```
  1. GetCourseStructureToLibraryImportView
    Get the course structure saved when creating the import.

    **Example Request**
        GET /api/import_from_modulestore/v0/get_import/{course-to-library-uuid}/

    **Responses**
        - 200: Course structure retrieved successfully.
        - 400: Invalid request data.
        - 401: Unauthorized.
        - 403: Forbidden.
        - 404: Import not found.

    **GET Response Values**
        The query returns a list of hierarchical structures of
        courses that are related to the import in the format:
          [
            {
              chapter_id1: chapter_display_name,
              children: [
                {
                  sequential_id1: chapter_display_name
                  children: [...]
                }
                ...
              ]
            },
            {
              chapter_id2: chapter_display_name,
              children: [
                {
                  sequential_id2: chapter_display_name
                  children: [...]
                }
                ...
              ]
            },
            ...
         ]
    **Example GET Response**
        [
          {
            "block-v1:edX+DemoX+Demo_Course+type@chapter+block@3f8c073c6bf74096b9a4033227de01d3": "Section 1",
            "children": [
              {
                "block-v1:edX+DemoX+Demo_Course+type@sequential+block@194836ad915645d684828d4e48dbc09e": "Subsection",
                "children": [
                  {
                    "block-v1:edX+DemoX+Demo_Course+type@vertical+block@07a5b2fb186f4a47ac2d1afe3ef91850": "Unit 1",
                    "children": [
                      {
                        "block-v1:edX+DemoX+Demo_Course+type@problem+block@a9c78c9ad3a148c2939091f5fbdd0eeb": "Block"
                      },
                      {
                        "block-v1:edX+DemoX+Demo_Course+type@video+block@195f37e99f1b4fedb607c621f239debb": "Video"
                      },
                      {
                        "block-v1:edX+DemoX+Demo_Course+type@lti+block@1700d68eae7d438aacf66fc8203efcda": "lti"
                      }
                    ]
                  },
                  {
                    "block-v1:edX+DemoX+Demo_Course+type@vertical+block@c6b19a1c7136483f9dd037a14641c289": "Unit 2",
                    "children": [
                      {
                        "block-v1:edX+DemoX+Demo_Course+type@html+block@330fcd9b9fa6476b8d39629dbc5cf20b": "HTML"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
  1. ImportBlocksView
    Import blocks from a course to a library.
    
    **Example Request**
        POST /api/import_from_modulestore/v0/import_blocks/
        
    **Example request data**
        ```
        {
            "usage_ids": ["block-v1:org+course+run+type@problem+block@12345"],
            "import_uuid": "78df3b2c-4e5a-4d6b-8c7e-1f2a3b4c5d6e",
            "composition_level": "xblock",
            "override": false
        }
        ```
        
    **POST Parameters**
        - usage_ids (list): A list of usage IDs of the blocks to be imported.
        - import_uuid (str): The UUID of the import task.
        - composition_level (str): The composition level of the blocks to be imported.
        - override (bool): Whether to override existing blocks in the library.
        
    **Responses**
        - 200: Import blocks from a course to a library task successfully started.
        - 400: Invalid request data.
        - 401: Unauthorized.
        - 403: Forbidden, request user is not the author of the received import.
        - 404: Import not found.
        
    **Example Response**:
        ```
        {
            "status": "success"
        }
        ```

@kdmccormick
Copy link
Member

Oh, you already have these docstrings in the code @NiedielnitsevIvan , sorry, not sure how I missed that. I'll comment on them there.

@kdmccormick
Copy link
Member

Closed in favor of #36725

@openedx-webhooks openedx-webhooks added the core contributor PR author is a Core Contributor (who may or may not have write access to this repo). label May 16, 2025
@github-project-automation github-project-automation bot moved this from Waiting on Author to Done in Contributions May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). create-sandbox open-craft-grove should create a sandbox environment from this PR open-source-contribution PR author is not from Axim or 2U

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

7 participants