Re-send validation email, refactor to APIViews#840
Conversation
| class ResendValidation(PublicJsonPostView): | ||
| def handle_post(self, request, *args, **kwargs): | ||
| body = json.loads(request.body.decode('utf-8')) |
There was a problem hiding this comment.
We should avoid using PublicJsonPostView and instead try to use DRF for any API views.
Something like this
Lines 51 to 62 in c1e11c4
There was a problem hiding this comment.
All the other similar views use the same pattern, like ShowUsername or RecoverPassword. Should I also change those to use APIView?
There was a problem hiding this comment.
We would need to refactor so that all API views are using DRF views instead of the custom PublicJsonPostView.
It will be cool to follow this for any new addition to the go-api.
We planned to do this right? @batpad @GregoryHorvath
There was a problem hiding this comment.
@GregoryHorvath Yeah we don't need them. The best way will be to just define empty permissions_classses
permissions_classes = []Basically we should use request.user directly instead of get_authenticated_user, and for any custom logic, we should create a custom authentication class and add it to DRF DEFAULT_AUTHENTICATION_CLASSES. But yeah it isn't used anywhere so we don't need to worry about it.
| ) | ||
| from rest_framework.authtoken.models import Token | ||
|
|
||
| def create_draft(raw): |
There was a problem hiding this comment.
@batpad @thenav56 Removed most of these unnecessarily abstracted functions. Most of these can be found now inside the Views, ex. this one:
b8b8e9e#diff-8e4a20b18006b7a31a84250b0828251eR182
| from api.views import bad_request | ||
|
|
||
|
|
||
| def get_client_ip(request): |
| except Exception: | ||
| return bad_request('Could not change PER form record.') | ||
|
|
||
| if hasattr(form,'status_code') and form.status_code == 400: |
| # Update Form Data of the Form | ||
| if data: | ||
| try: | ||
| with transaction.atomic(): # all or nothing |
|
|
||
| class DraftSent(PublicJsonPostView): | ||
| def handle_post(self, request, *args, **kwargs): | ||
| u = None |
| return form_data | ||
|
|
||
| class FormSent(PublicJsonPostView): | ||
| def handle_post(self, request, *args, **kwargs): |
There was a problem hiding this comment.
@batpad @thenav56 This didn't need authentication before but I added it now: https://app.circleci.com/pipelines/github/IFRCGo/go-api/613/workflows/4c8458c8-22d6-491e-81e5-7f1e37800d85/jobs/2529
Should I remove the auth from this? It was weird to me why we allowed insertion without auth...
Ref.: #737
Changes
PublicJsonPostViews andPublicJsonRequestViews to beAPIViews insteadResendValidationView which requires ausernameand resends the registration validation email to the user (if it's within a day of the registration, the same as it is handled by the main registration process)Frontend PR: IFRCGo/go-frontend#1490