-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: Add REST endpoints to update Components in a Collections (temp) #674
Conversation
a13005b
to
704bb11
Compare
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.
eb91d5d
to
f4521b5
Compare
@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). |
# 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), | ||
) | ||
|
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
openedx/core/djangoapps/content_libraries/collections/rest_api/v1/views.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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.
- I tested this using the instructions from feat: Add REST endpoints to update Components in a Collections [FC-0062] openedx/edx-platform#35384
Nit: I had to change the PATCH/DELETE param fromcomponent_keys
tousage_keys
. - I read through the code
-
I checked for accessibility issues - Includes documentation
@@ -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') |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
``
There was a problem hiding this comment.
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!
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
as oel_collections.get_learning_package_collections has been removed.
59514cc
to
5bf9422
Compare
…-rest-api' into jill/collection-components-rest
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.
There was a problem hiding this 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?
95de012
to
366a7e9
Compare
…ction-components-rest.pre-rebase
504aa4f
into
yusuf-musleh/collections-crud-rest-api
* 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]>
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