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

Soft delete collections #35496

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

pomegranited
Copy link
Contributor

@pomegranited pomegranited commented Sep 18, 2024

Description

Adds support for soft-deleting and restoring Collections.

As part of this change, we're refactoring the way the Collections-related events are triggered to use Django model signals, so that changes made in Django Admin will be reflected in the Studio search index.

  • Which edX user roles will this change impact? Library Authors; not enabled in production by default.

Supporting information

Related to: openedx/modular-learning#231
Depends on: openedx/openedx-learning#229
Private-ref: FAL-3809

Testing instructions

  1. Reindex your studio content to update any existing Collection documents: tutor dev run cms ./manage.py cms reindex_studio --experimental
  2. In the Authoring frontend, create a Collection and add some components to it.
  3. Open http://meilisearch.local.edly.io:7700/
    Your api key can be found with tutor config printvalue MEILISEARCH_API_KEY
    Search for your collection key and verify that the collection document and its components are returned.
  4. Hit the "soft delete" REST API: DELETE http://studio.local.edly.io:8001/api/libraries/v2/<library_key>/collections/<collection_key>/
    Note that the collection no longer appears in the Authoring MFE list of collections.
    Search for your collection key in Meilisearch and verify that no results are found.
  5. Hit the "restore" REST API: POST http://studio.local.edly.io:8001/api/libraries/v2/<library_key>/collections/<collection_key>/restore/
    Verify that the collection again appears in the Authoring MFE list of collections.
    Search for your collection key in Meilisearch and verify that the collection document and its components are returned again.
  6. Open Django Admin http://local.edly.io:8000/admin/oel_collections/collection/
    Disabling a collection should have the same effect as the "soft delete" REST API (step 4).
    Re-enabling a collection should have the same effect as the "restore" REST API (step 5)
  7. Delete a Collection via Django Admin.
    This will permanently delete the Collection.
  8. Try to hit the "restore" REST API with the deleted collection key: POST http://studio.local.edly.io:8001/api/libraries/v2/<library_key>/collections/<collection_key>/restore/
    This should return a 404.

Deadline

ASAP

Author Notes & Concerns

  • f760c2b changes the Meilisearch ID used for Collections from the int Collection.pk to a string generated from the Collection's usage key.
    We needed to do this so that the Collection document could be identified by the information in the CONTENT_LIBRARY_DELETED event (library_key + collection_key), so this document can be removed after the Collection itself is removed.
    Users will need to reindex their studio search content.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Sep 18, 2024
@openedx-webhooks
Copy link

openedx-webhooks commented Sep 18, 2024

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.

This change standardises the search document "id" to be a meilisearch ID
generated from the usage key, for all types of indexed objects.

This is important for collections so we can locate the collection
document in the search index solely from the data provided by the
LIBRARY_COLLECTION_DELETED event (library_key + collection_key), even if
the collection has been deleted from the database.
* get_library_collection_usage_key and
  searchable_doc_tags_for_collection do not need a Collection object;
  the usage key can be created from the library_key and collection_key.

* updated searchable_doc_for_collection to require the parts of the
  collection usage key + an optional collection. This allows us to
  identify the collection's search document from its usage key without
  requiring an existing Collection object (in case it's been deleted).
  Also removes the edge case for indexing Collections not associated
  with a ContentLibrary -- this won't ever really happen.
so that added/removed collections are removed/re-added to component documents.

Special case: When a collection is soft-deleted/restored, we detect this
in the search index and update the collection's component documents
directly, without a CONTENT_OBJECT_ASSOCIATON_CHANGED signal.
@@ -1103,8 +1100,7 @@ def create_library_collection(
content_library: ContentLibrary | None = None,
) -> Collection:
"""
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we even need create_library_collection and update_library_collection API methods now? They're just wrappers for the authoring_api methods now that we're not sending events anymore.

@@ -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.5
openedx-learning @ git+https://github.com/open-craft/openedx-learning.git@jill/collection-delete
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To do: fix this when PR merges.

@pomegranited pomegranited marked this pull request as ready for review September 20, 2024 16:03
@ChrisChV
Copy link
Contributor

@pomegranited The code looks good.

When testing the "soft delete" and "hard delete" with the admin panel, it don't update the index:

https://www.loom.com/share/115ac6dcc9504200b6c58cf3ed97a358?sid=2280dbda-8be2-4bb2-a630-714e5a2cf5ab

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: Needs Triage
Development

Successfully merging this pull request may close these issues.

3 participants