-
Notifications
You must be signed in to change notification settings - Fork 325
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
Feature/APIv2 Node Settings [PLAT-924] #8536
Feature/APIv2 Node Settings [PLAT-924] #8536
Conversation
- Url added, view and serializer started. - New permission class IsContributor added.
- Use this serializer for PUT or PATCH requests - Update the view to choose the right serializer
…erializer to get tests to run.
…isdr/osf.io into feature/node_settings_apiV2 * 'feature/node_settings_apiV2' of https://github.com/pattisdr/osf.io: Add test for view_only_links relationship Add tests for the NodeSettingsSerializer and GET requests # Conflicts: # api_tests/nodes/views/test_node_settings.py
… loaded multiple times. - Version 2.9 deprecates access_requests_enabled field from NodeSerializer and moves it to NodeSettings serializer. - Wiki and forward addons pushed to serializer context so they are not loaded multiple times in serializer method fields and in update method.
…ified, if desired. - Modify HideIfWikiDisabled so versions greater than 2.7 don't show wiki relationship on nodes if wiki is disabled. Formerly, this feature was just restricted to 2.8. - List settings field as field that doesn't appear on registration serializer. - Add test for deprecated access_requests_enabled field on NodeSerializer
type_ = 'node-settings' | ||
|
||
|
||
class NodeSettingsUpdateSerializer(NodeSettingsSerializer): |
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.
@erinspace pointed out writeable_method_fields
which allow writes to a SerializerMethodField. We explored this, but ended up opting for an UpdateSerializer for writes, so we could keep our individual field validation. The NodeSettings serializer is tricky because most of the fields do not actually reside on the node.
Local travis passed, this test failure seems unrelated. |
[#PLAT-824] - Keep old v1 route - Add model tests
… logs Update tests to check for node logs
3a63859
to
d74bf6a
Compare
api/nodes/serializers.py
Outdated
if not forward_addon: | ||
raise exceptions.ValidationError('You must first set redirect_link_enabled to True before specifying a redirect link URL.') | ||
forward_addon.url = redirect_link_url | ||
obj.add_log( |
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.
This log is added manually here, much like it is manually added elsewhere in the codebase like here where it's mentioned that logging should be consolidated to a more central place.
Decided to leave it as it was and add the log manually as moving those seemed a bit out of scope, but wanted to point out why this was done!
…ifferent serializer for the response versus the request.
6b9cb9c
to
ab17e69
Compare
redirect_link_url = ser.URLField(write_only=True, required=False) | ||
redirect_link_label = ser.CharField(max_length=50, write_only=True, required=False) | ||
|
||
def to_representation(self, instance): |
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.
Overrode to_representation
so a PATCH request could use the NodeSettingsUpdateSerializer, but the response would use the NodeSettingsSerializer
. This was one of the suggestions on this issue: Specifying different serializers for input and output
Other ideas I considered before going this route:
- Different field names for write versus read
- https://github.com/vintasoftware/drf-rw-serializers/ - separated serializers for read/write operations
- Overriding put method to instantiate different serializers depending on write versus read, and then return response(serialized_data)
""" | ||
context = self.context | ||
context['wiki_addon'] = instance.get_addon('wiki') | ||
context['forward_addon'] = instance.get_addon('forward') |
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.
Passing in the addons in the context, because the NodeSettingsSerializer currently expects it. This was placed on the context to speed up the request so we weren't repeatedly fetching the same addons.
Paired with @erinspace
Purpose
Implement a /v2/nodes/{nid}/settings/ endpoint that accepts GET and PATCH requests.
Changes
/nodes/<node_id>/settings/
settings
relationship on node serializer, hidden on registration serializeris_deprecated
to allow specifying just a min or max versionaccess_requests_enabled
on the NodeSerializerQA Notes
Documentation
CenterForOpenScience/developer.osf.io#22
Side Effects
Ticket
https://openscience.atlassian.net/browse/PLAT-924