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: api for adding, removing and updating components in container #36434

Merged

Conversation

navinkarkera
Copy link
Contributor

@navinkarkera navinkarkera commented Mar 24, 2025

Description

Rest API to add, remove and update components under containers in content libraries.

Useful information to include:

  • Which edX user roles will this change impact?: "Developer".

Supporting information

Testing instructions

  • Read code
  • Verify the tests and make sure they are passing.

Deadline

"None" if there's no rush, or provide a specific date or event (and reason) if there is one.

Concerns

Enforce restrictions on which block types are allowed.: Not sure about this one. Do we have a fixed list of allowed blocks that we want to restrict via rest api or is this configurable per unit/library etc.?

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

openedx-webhooks commented Mar 24, 2025

Thanks for the pull request, @navinkarkera!

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.

@navinkarkera navinkarkera marked this pull request as draft March 24, 2025 10:53
@navinkarkera navinkarkera force-pushed the navin/fal-4109/container-components branch from f82a882 to 6f298a5 Compare March 25, 2025 04:44
@navinkarkera navinkarkera marked this pull request as ready for review March 25, 2025 05:12
Copy link
Contributor

@rpenido rpenido left a comment

Choose a reason for hiding this comment

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

LGTM 👍
Thank you for your work, @navinkarkera!

  • I tested this using the instructions from the PR, and manually calling the endpoint
  • I read through the code
  • I checked for accessibility issues
  • Includes documentation

"""
Creates, updates, or deletes the document for the given Library Container in the search index.

TODO: add support for indexing a container's components, like upsert_library_collection_index_doc does.
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be part of another task?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if we need this right now as search is not planned yet for units. If we add containers to each component index document similar to collections, we'll need to update this function to reindex each child component.

@navinkarkera navinkarkera force-pushed the navin/fal-4109/container-components branch from 6f298a5 to 2cfdbad Compare March 27, 2025 05:33
Copy link
Contributor

@pomegranited pomegranited left a comment

Choose a reason for hiding this comment

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

Hi @navinkarkera -- this is looking really good for the "add existing components to a container" use case, but we're missing a view that lets us "add new component to a container".

Have a couple more concerns inline, please feel free to push back.

Note to self: code review done by comparing to braden/units-api

)


def get_container(container_key: LibraryContainerLocator) -> authoring_models.Container:
Copy link
Contributor

Choose a reason for hiding this comment

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

@navinkarkera I think our API should still only return ContainerMetadata as originally designed.
But see https://github.com/open-craft/edx-platform/pull/757/files#diff-5a248b18ae17c86d454776cb48e0372a8cbdc9610b3886f175a116f9b280e681R118 -- I did end up adding an internal method to get the Container object to save some code duplication. Feel free to pull in that code?

Open for discussion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice! I had initially used it outside of the file, but changed it later on. I'll pull changes from 757.

return container


def get_container_metadata(container_key: LibraryContainerLocator) -> ContainerMetadata:
Copy link
Contributor

Choose a reason for hiding this comment

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

See above -- get_container should return ContainerMetadata, so no need for this added method.

published_by: str = ""
last_draft_created: datetime | None = None
# The username of the user who created the last draft.
last_draft_created_by: str = ""
has_unpublished_changes: bool = False
collections: list[CollectionMetadata] = field(default_factory=list)
can_stand_alone: bool = True
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should expose can_stand_alone on the dataclasses -- it's for internal use only.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See below: #36434 (comment), we need the frontend to set this flag to False whenever a new component is created under a container like unit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok -- I missed that subtlety, that's fine :)

But could you add some documentation about the parameters to create_library_block to explain what this flag is for to users of the API?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -298,7 +342,7 @@ def to_internal_value(self, value: str) -> UsageKeyV2:
raise ValidationError from err


class ContentLibraryCollectionComponentsUpdateSerializer(serializers.Serializer):
class ContentLibraryComponentKeysSerializer(serializers.Serializer):
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, that's better, thank you. :)

Copy link
Contributor

@pomegranited pomegranited left a comment

Choose a reason for hiding this comment

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

👍 Thank you for answering my questions @navinkarkera !

Just one nit re documentation for create_library_block, since we're exposing that can_stand_alone flag, but this looks and works great.

  • I tested this -- I checked that the functionality is covered by unit tests
  • I read through the code by comparing against braden/units-api
  • I checked for accessibility issues by using my keyboard to navigate N/A
  • Includes documentation
  • User-facing strings are extracted for translation

@navinkarkera navinkarkera force-pushed the navin/fal-4109/container-components branch from 8e004fa to d1d5b8e Compare March 31, 2025 11:49
@navinkarkera navinkarkera merged commit bcaa79c into openedx:master Mar 31, 2025
49 checks passed
@navinkarkera navinkarkera deleted the navin/fal-4109/container-components branch March 31, 2025 12:10
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

1 similar comment
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

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

Successfully merging this pull request may close these issues.

5 participants