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 boundary views and serializers #113

Merged
merged 6 commits into from
Oct 13, 2022

Conversation

mstone121
Copy link
Contributor

@mstone121 mstone121 commented Oct 7, 2022

Overview

This PR adds serializers for submissions and a few related objects and views for submissions.

Closes #107

Notes

I added a venv folder to the .gitignore so I could install requirements locally.

TODO: Create activity log

Testing Instructions

Checklist

  • fixup! commits have been squashed
  • CHANGELOG.md updated with summary of features or fixes, following Keep a Changelog guidelines
  • README.md updated if necessary to reflect the changes
  • CI passes after rebase

Copy link
Contributor

@rajadain rajadain left a comment

Choose a reason for hiding this comment

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

Left some comments.

My tendency has been to used function-based views in the past rather than class-based ones. ViewSets add standardization and offer good built-in support, but can make custom / non-standard work a little difficult. DRF has a brief write-up on this: https://www.django-rest-framework.org/tutorial/6-viewsets-and-routers/#trade-offs-between-views-vs-viewsets

For now, I think ViewSets are fine. If we need to refactor to function-based views down the line, we can do it then.

.gitignore Outdated Show resolved Hide resolved
src/django/api/serializers/submission.py Outdated Show resolved Hide resolved
src/django/api/views/submission.py Outdated Show resolved Hide resolved
src/django/api/views/submission.py Outdated Show resolved Hide resolved
Copy link
Contributor

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

Sorry for the piecemeal review. Other things I noticed while working on the ReferenceImage serializer.

src/django/api/filters/submission.py Outdated Show resolved Hide resolved
src/django/api/filters/submission.py Outdated Show resolved Hide resolved
src/django/api/filters/submission.py Outdated Show resolved Hide resolved
@mstone121 mstone121 force-pushed the ms/add-submission-serializers-views branch 6 times, most recently from 4407843 to 41173e9 Compare October 10, 2022 22:14
@mstone121 mstone121 changed the title Add submission views and serializers Add boundary views and serializers Oct 10, 2022
Copy link
Contributor

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

I know this is still WIP, but was hoping this would still be helpful.

src/django/api/models/user.py Outdated Show resolved Hide resolved
src/django/api/models/user.py Outdated Show resolved Hide resolved
src/django/api/models/boundary.py Outdated Show resolved Hide resolved
src/django/api/views/boundary.py Show resolved Hide resolved
src/django/api/views/boundary.py Outdated Show resolved Hide resolved
src/django/api/management/commands/resetdb.py Outdated Show resolved Hide resolved
if not request.user.has_access_to_utility(
Utility.objects.get(pk=utility_id)
):
raise APIException('Cannot access this utility', 401)
Copy link
Contributor

@jacobtylerwalls jacobtylerwalls Oct 11, 2022

Choose a reason for hiding this comment

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

This could merit updating the ADR, but if we just raise PermissionDenied, DRF will convert this into a 403, which I think is more accurate than 401 given that this is an insufficient permission issue rather than incorrect creds issue.

Sample response from what I was just working on in 97ef19b (and 61615c9, updated to use the DRF import of PermissionDenied to get the accurate detail message):

GET /api/boundaries/1/reference-images/
HTTP 403 Forbidden
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "detail": "Validators cannot view image details."
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm okay with that. Looping in @rajadain

@mstone121 mstone121 marked this pull request as ready for review October 11, 2022 15:39
src/django/api/views/boundary.py Outdated Show resolved Hide resolved
src/django/api/management/commands/resetdb.py Show resolved Hide resolved
src/django/api/views/boundary.py Outdated Show resolved Hide resolved
Copy link
Contributor

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

Looks great. We can also finalize the 403 vs. 401 thing later on.

@rajadain
Copy link
Contributor

Taking a look now

@rajadain
Copy link
Contributor

This needs the migrations to be updated:

Running migrations:
  No migrations to apply.
  Your models in app(s): 'api' have changes that are not yet reflected in a migration, and so won't be applied.
  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.

Copy link
Contributor

@rajadain rajadain left a comment

Choose a reason for hiding this comment

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

This looks great!

Minor comments on utility filtering, but overall this looks great. We should defer the Activity Log to a later card.


return BOUNDARY_STATUS.SUBMITTED

@cached_property
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice work caching this 👍


@property
def resolved(self):
return self.resolved_at is not None
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice shortcut

src/django/api/views/boundary.py Outdated Show resolved Hide resolved
Copy link
Contributor

@rajadain rajadain left a comment

Choose a reason for hiding this comment

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

+1 great job! Nice, clean implementation. Sets up a solid foundation for us to build upon. This looks good to merge!

rajadain added a commit that referenced this pull request Oct 13, 2022
The endpoint is /boundaries/ as of #113, so the
RTK query is updated accordingly.
@rajadain rajadain mentioned this pull request Oct 13, 2022
6 tasks
Matt Stone added 2 commits October 13, 2022 09:01
This allows developers to create a virtual env for this project. One
might want to do this so the IDE will know about required packages.
This allows for testing each submission in the same submission list.
@mstone121 mstone121 force-pushed the ms/add-submission-serializers-views branch from 8ce625e to 5ccc0be Compare October 13, 2022 14:07
Matt Stone added 4 commits October 13, 2022 09:14
@mstone121 mstone121 force-pushed the ms/add-submission-serializers-views branch from 5ccc0be to 94b93c5 Compare October 13, 2022 14:20
@mstone121 mstone121 merged commit 929ebb0 into develop Oct 13, 2022
@mstone121 mstone121 deleted the ms/add-submission-serializers-views branch October 13, 2022 14:32
rajadain added a commit that referenced this pull request Oct 13, 2022
The endpoint is /boundaries/ as of #113, so the
RTK query is updated accordingly.
mstone121 pushed a commit that referenced this pull request Oct 13, 2022
The endpoint is /boundaries/ as of #113, so the
RTK query is updated accordingly.
rajadain added a commit that referenced this pull request Oct 13, 2022
The endpoint is /boundaries/ as of #113, so the
RTK query is updated accordingly.
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.

Add Serializers, Views for Submissions
3 participants