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 (temp) #674

Conversation

pomegranited
Copy link
Member

@pomegranited pomegranited commented Aug 28, 2024

This PR adds REST endpoints (patch, delete) for updating a Library Collection's Components.

This PR is for code review only; see openedx#35384 for testing instructions.


Private-ref: FAL-3784

@pomegranited pomegranited changed the title feat: Add REST endpoints to add/remove Components to/from Collections [FC-0062] feat: Add REST endpoints to add/remove Components to/from Collections (temp) Aug 28, 2024
@pomegranited pomegranited changed the title feat: Add REST endpoints to add/remove Components to/from Collections (temp) feat: Add REST endpoints to update Components in a Collections (temp) Aug 28, 2024
@pomegranited pomegranited force-pushed the jill/collection-components-rest branch from a13005b to 704bb11 Compare August 28, 2024 05:18
@pomegranited pomegranited marked this pull request as draft August 28, 2024 05:56
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
@bradenmacdonald
Copy link
Member

@pomegranited Let's mark this API as unstable with a clear comment that the API interface may change once we implement the ability to store units/sections/subsections in the library (which may not be "Components"/XBlocks, but which still need to be associated with collections).

Comment on lines 1123 to 1129
# Emit a CONTENT_OBJECT_TAGS_CHANGED event for each of the objects added/removed
object_keys = contents_qset.values_list("key", flat=True)
for object_key in object_keys:
CONTENT_OBJECT_TAGS_CHANGED.send_event(
content_object=ContentObjectData(object_id=object_key),
)

Copy link
Member

@rpenido rpenido Aug 28, 2024

Choose a reason for hiding this comment

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

I don't think I get why we are dispatching CONTENT_OBJECT_TAGS_CHANGED here. Maybe you mean LIBRARY_COLLECTION_UPDATED?

Note: There is a discussion about this event here.

Edit: Now I saw that this came from the issue description. But I don't see any benefit from using this event. Currently, it updates only the tag data (ref), not the metadata of the document (that we would need here)

Copy link
Member Author

@pomegranited pomegranited Aug 28, 2024

Choose a reason for hiding this comment

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

@rpenido Yep, that's the current behaviour, but we're planning to update it with openedx/modular-learning#230. I've made a start at that here: jill/collection-components-rest...open-craft:edx-platform:jill/collection-components-search

But will see how that discussion shakes out.

Copy link
Member Author

Choose a reason for hiding this comment

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

@rpenido I will rename CONTENT_OBJECT_TAGS_CHANGED to CONTENT_OBJECT_ASSOCIATIONS_CHANGED, and add a field indicating whether it was the tag or collection that changed when I do openedx/modular-learning#230.

Copy link
Member

@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, @pomegranited!

The code is really clear and well-documented! It was a pleasure to review!
I think we will need to check the EVENT from the content update. See the comment in the PR.

@@ -179,3 +182,38 @@ def destroy(self, request, *args, **kwargs):
# TODO: Implement the deletion logic and emit event signal

return Response(None, status=HTTP_405_METHOD_NOT_ALLOWED)

@action(detail=True, methods=['delete', 'patch'], url_path='contents', url_name='contents:update')
Copy link
Member

Choose a reason for hiding this comment

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

I would expect DELETE collection/contents to clear all content, so I am bit more inclined to use the PATCH with a additional remove parameter here. Or even:

{
  "add": ["component1"],
  "remove": ["compoinent2"]
}

The later would add need more work for a feature that we don't need now (replace a component), so please fell free to ignore this whole comment for now.

I'm fine with the way it is working.

Copy link
Member

Choose a reason for hiding this comment

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

The url name here is giving this warning:

WARNINGS:
cms-1               | ?: (urls.W003) Your URL pattern '^collections/(?P<pk>[^/.]+)/contents/$' [name='library-collections-contents:update'] has a name including a ':'. Remove the colon, to avoid ambiguous namespace references.
cms-1               | ?: (urls.W003) Your URL pattern '^collections/(?P<pk>[^/.]+)/contents\.(?P<format>[a-z0-9]+)/?$' [name='library-collections-contents:update'] has a name including a ':'. Remove the colon, to avoid ambiguous namespace references.
``

Copy link
Member Author

Choose a reason for hiding this comment

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

@rpenido Thanks for raising this.. I agree it's ambiguous, but given that we're flagging this API as UNSTABLE, I think it's ok to leave it as-is, and change it if/when we need to.

Will fix the url name though!

@yusuf-musleh yusuf-musleh force-pushed the yusuf-musleh/collections-crud-rest-api branch from 59514cc to 5bf9422 Compare August 29, 2024 05:50
…-rest-api' into jill/collection-components-rest
@pomegranited
Copy link
Member Author

Ugh.. my commits have gone all wonky here, but I don't want to rebase while it's under review. @rpenido let me know if you need any clarity on what's being changed here?

so we can use the updated oel_collections.get_collections method.
Copy link
Member

@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.

Ugh.. my commits have gone all wonky here,

It's fine, @pomegranited! Thank you for the changes.

Looks like we have a (not related) flaky test. Could you try to re-run the CI?

@yusuf-musleh yusuf-musleh force-pushed the yusuf-musleh/collections-crud-rest-api branch 2 times, most recently from 95de012 to 366a7e9 Compare August 30, 2024 06:28
@pomegranited pomegranited marked this pull request as ready for review September 3, 2024 00:15
@pomegranited pomegranited merged commit 504aa4f into yusuf-musleh/collections-crud-rest-api Sep 3, 2024
47 checks passed
rpenido added a commit that referenced this pull request Sep 11, 2024
* feat: Add Library Collections REST endpoints

* test: Add tests for Collections REST APIs

* chore: Add missing __init__ files

* feat: Add events emitting for Collections

* feat: Add REST endpoints to update Components in a Collections (temp) (#674)

* feat: add/remove components to/from a collection

* docs: Add warning about unstable REST APIs

* chore: updates openedx-events==9.14.0

* chore: updates openedx-learning==0.11.4

* fix: assert collection doc have unique id

---------

Co-authored-by: Jillian <[email protected]>
Co-authored-by: Chris Chávez <[email protected]>
Co-authored-by: Rômulo Penido <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants