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

Add and apply custom ViewSet classes #14

Closed
wants to merge 1 commit into from
Closed

Add and apply custom ViewSet classes #14

wants to merge 1 commit into from

Conversation

jwalz
Copy link
Contributor

@jwalz jwalz commented Feb 13, 2024

What:

Adding custom ViewSet classes to better control the methods generated/exposed by the routers. The two new view set classes are:

RetrieveOnlyViewSet:
Supports GET requests to urls like addons.osf.io/v1/{resource-type}/{pk}

RetrieveWriteViewSet:
Supports GET/PATCH/DELETE requests to urls like addons.osf.io/v1/{resource-type}/{pk}
Supports POST requests to urls like addons.osf.io/v1/{resource-type}/

Notably, neither class supports GET requests to urls like addons.osf.io/v1/{resource-type}/

Why:

Of our top-level entities, only ExternalStorageService supports a List View (all of our other supported List Views are relationship views). Meanwhile, existing, out-of-the-box ViewSets from DRF and DRF-JSON API all provide both retrieve AND list functionality.

How:

  • Create custom ViewSets mimicking the DRF-JSON API definitions here using only the appropriate mixins from DRF.
  • Update the base classes for our ViewSets to inherit the correct new ViewSets.

Future Steps

  • Determine the best path for allowing the OSF to disable users (either by adapting a new ViewSet that allows GET+PATCH behavior, a custom action on the UserReferenceModelViewSet, or via shared task queue)
  • Implement selection of appropriate permission by action as per the DRF Docs

Copy link
Collaborator

@brianjgeiger brianjgeiger left a comment

Choose a reason for hiding this comment

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

Very nice.

@jwalz jwalz closed this Mar 5, 2024
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.

2 participants