-
Notifications
You must be signed in to change notification settings - Fork 3
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
#260 add check password when delete profile #261
Conversation
@@ -174,6 +176,16 @@ def get_serializer_class(self): | |||
else: | |||
return ProfileOwnerDetailEditSerializer | |||
|
|||
def destroy(self, request, *args, **kwargs): | |||
instance = self.get_object() |
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.
Maybe it's better to use get_object_or_404
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.
No. get_object_or_404()
may be used in get_object()
(if needed), but not here.
user = self.request.user | ||
password = self.request.data.get("password") | ||
if not password or not check_password(password, user.password): | ||
return Response(status=status.HTTP_400_BAD_REQUEST) |
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.
400 BAD REQUEST
must have a body, with explanation what exactly is wrong with the request. So, I guess this logic (together with password check) should be in serializer validator.- Don't, don't do
return Response()
.
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 wanted to do it in serializer, but there is no delete method in serializers, so I don't know how to implement it. I remember that it's not okay to return Response. But I just override original destroy method and it contains Response.
Functionality of checking password when delete profile added (destroy method overridden). Tests (delete profile) updated due to changes.