Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add REST endpoints to update Components in a Collections [FC-0062] #35384

Closed

Conversation

pomegranited
Copy link
Contributor

@pomegranited pomegranited commented Aug 28, 2024

Description

Adds a REST endpoint (patch, delete) for updating the Components in a v2 Content Library's Collection.
Adding/removing components raises a CONTENT_OBJECT_TAGS_CHANGED event, because we will index the ContentObject's collections as a type of "tag".

Note: We'll be renaming CONTENT_OBJECT_TAGS_CHANGED to CONTENT_OBJECT_ASSOCIATIONS_CHANGED as part of openedx/modular-learning#230

This PR adds to the features available to Course Authors of v2 Libraries, which aren't recommended for production use yet.

Supporting information

Part of : openedx/modular-learning#227
Based on: #35321
Depends on:

Private-ref: FAL-3784

Testing instructions

Please check that the unit tests added here cover most cases.

Manual testing:

  1. Checkout this branch in your local dev environment
  2. Make sure you have feat: Add Content Library Collections signals [FC-0062] openedx-events#386 and Associate PublishableEntities with Collections [FC-0062] openedx-learning#216 installed and running locally
  3. Create a V2 library, e.g lib:SampleTaxonomyOrg1:AL1
  4. Add some blocks to that library.
  5. In an external HTTP client (like curl/postman or similar) make the following requests (make sure you have the correct headers for authentication, you can copy them from the network tab in your browser), replace the library key in the URL with your actual library key:
    1. POST http://studio.local.edly.io:8001/api/libraries/v2/lib:SampleTaxonomyOrg1:AL1/collections/
      1. Payload: {"title":"Collection 1", "description": "First Collection"}
      2. This should return the newly created collection; note the ID and modified dates.
    2. GET http://studio.local.edly.io:8001/api/libraries/v2/lib:SampleTaxonomyOrg1:AL1/blocks/
      1. Should return the list of blocks added to this library
      2. Note their usage key values for the steps below.
    3. PATCH http://studio.local.edly.io:8001/api/libraries/v2/lib:SampleTaxonomyOrg1:AL1/collections/1/contents/
      1. Payload: {"usage_keys": [ <list of usage keys from the library blocks> ]
      2. Should return {"count": <number of components in list>}
      3. Check the logs and confirm that the event was emitted for each component, triggering an "upsert" into Meilisearch.
    4. GET http://studio.local.edly.io:8001/api/libraries/v2/lib:SampleTaxonomyOrg1:AL1/collections/1/
      1. The modified timestamp should be updated.
    5. DELETE http://studio.local.edly.io:8001/api/libraries/v2/lib:SampleTaxonomyOrg1:AL1/collections/1/contents/
      1. Payload: {"usage_keys": [ <list of usage keys from the library blocks> ]
      2. Should return {"count": <number of components in list>}
      3. Check the logs and confirm that the event was emitted for each component, triggering an "upsert" into Meilisearch.
    6. GET http://studio.local.edly.io:8001/api/libraries/v2/lib:SampleTaxonomyOrg1:AL1/collections/1/
      1. The modified timestamp should be updated.
    7. GET http://studio.local.edly.io:8001/api/libraries/v2/lib:SampleTaxonomyOrg1:AL1/collections/1/contents/ - will raise a 405, as an object's collections will be fetched from Meilisearch.

@openedx-webhooks
Copy link

Thanks for the pull request, @pomegranited!

What's next?

Please work through the following steps to get your changes 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.

🔘 Let us know that your PR is ready for review:

Who will review my changes?

This repository is currently maintained by @openedx/wg-maintenance-edx-platform. Tag them in a comment and let them know that your changes are ready for review.

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.

@@ -93,7 +93,7 @@ libsass==0.10.0
click==8.1.6

# pinning this version to avoid updates while the library is being developed
openedx-learning==0.11.1
openedx-learning @ git+https://github.com/openedx/openedx-learning/@jill/collection-components
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FIXME: update when openedx/openedx-learning#216 merged & tagged.

Python API:
* Converts UsageKeyV2 object keys into component keys for use with the oel_collections api.
* Sends a CONTENT_OBJECT_TAGS_CHANGED for each component added/removed.

REST API:
* Calls the python API
* Receives a collection PK + a list of UsageKeys to add to the collection.
@pomegranited pomegranited force-pushed the jill/collection-components-rest branch from eb91d5d to f4521b5 Compare August 28, 2024 10:50
@mphilbrick211 mphilbrick211 added the FC Relates to an Axim Funded Contribution project label Aug 28, 2024
Addresses PR reviews.

* Collection contents -> Collection components
* Add warning about unstable REST APIs
* Wrap update_components view in convert_exceptions
* Raise api exceptions in api.update_collection_components
* Use usage_key in CONTENT_OBJECT_TAGS_CHANGED event
@pomegranited
Copy link
Contributor Author

Merged into #35321 for CC review.

@openedx-webhooks
Copy link

@pomegranited Even though your pull request wasn’t merged, please take a moment to answer a two question survey so we can improve your experience in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FC Relates to an Axim Funded Contribution project open-source-contribution PR author is not from Axim or 2U
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants