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

Account deletion must be confirmed #95

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

uxairibrar
Copy link
Collaborator

Closes #25

  • Added UserSerializer to ensure deleted users are excluded from API responses.
  • Implemented CustomUser model to handle soft deletion properly.
  • Added three views (request_delete, confirm_account_deletion, finalize_account_deletion) to manage account deletion flow.
  • Integrated a new modal in the User Settings page for final deletion confirmation.
  • Fixed UI alignment issues in the delete account section to prevent overflow.

Copy link
Member

@nuest nuest left a comment

Choose a reason for hiding this comment

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

I added a few comments, please take a look.

Also, the tests are still missing. Since you're working against API endpoints, I'm fine with tests directly talking to the API, but UI-based tests (or both) would be even better.


send_mail(
'Confirm Your Account Deletion',
f'Click the link to confirm deletion: {confirm_url}',
Copy link
Member

Choose a reason for hiding this comment

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

Please add a note to the email how long the token is valid.

user = User.objects.filter(email=email).first()

if user:
if user.deleted:
Copy link
Member

Choose a reason for hiding this comment

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

Is this the case when a user is deleted and then logs in again?

Comment on lines +32 to +34
path("request_delete/", views.request_delete, name="request_delete"),
path("confirm-delete/<str:token>/", views.confirm_account_deletion, name="confirm_delete"),
path("finalize-delete/", views.finalize_account_deletion, name="finalize_delete"),
Copy link
Member

Choose a reason for hiding this comment

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

Please stick to one style of URLs - I suggest to stick with hyphens only.

Comment on lines +229 to +233
cache.set(f"delete_token_{token}", user.id, timeout=3600)

confirm_url = request.build_absolute_uri(reverse('optimap:confirm_delete', args=[token]))

send_mail(
Copy link
Member

Choose a reason for hiding this comment

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

Suggest to define the pre-string only in one location and then import that string here, and elsewhere. If you search the code for "delete_token", you'll find multiple spots.

Also, we might have other tokens in the future, so user_delete_token would be more explicit.

def confirm_account_deletion(request, token):
user_id = cache.get(f"delete_token_{token}")

if user_id is None:
Copy link
Member

Choose a reason for hiding this comment

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

What about checking that the currently logged in user actually is the to be deleted user?

Comment on lines +278 to +280
user.deleted = True
user.deleted_at = now()
user.save()
Copy link
Member

Choose a reason for hiding this comment

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

Can you put these lines in a try catch block?

If something goes wrong during the save, the cache.delete(.. and the removal of the token from the session might not be properly called.

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.

Account deletion must be confirmed
2 participants