-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix: allows deleted users to signup with same email #5924
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
Merged
iamareebjamal
merged 3 commits into
fossasia:development
from
shreyanshdwivedi:deletedUser
Jun 3, 2019
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| from sqlalchemy.orm.exc import NoResultFound | ||
| from app.api.helpers.exceptions import ForbiddenException | ||
| from app.models import db | ||
| from app.api.helpers.db import save_to_db | ||
| from app.models.user import User | ||
|
|
||
|
|
||
| def modify_email_for_user_to_be_deleted(user): | ||
| """ | ||
| Update the email ID of user which is to be deleted. | ||
| Adds '.deleted' substring to email of a user to be deleted. | ||
| :param order: User to be deleted. | ||
| :return: | ||
| """ | ||
| not_unique_email = True | ||
| user_email = user.email | ||
| while not_unique_email: | ||
| try: | ||
| db.session.query(User).filter_by(email=user_email).one() | ||
| except NoResultFound: | ||
| user.email = user_email | ||
| save_to_db(user) | ||
| not_unique_email = False | ||
| else: | ||
| user_email = user_email + '.deleted' | ||
| return user | ||
|
|
||
|
|
||
| def modify_email_for_user_to_be_restored(user): | ||
| """ | ||
| Update the email ID of user which is to be restored. | ||
| Removes '.deleted' substring from a user to be restored. | ||
| :param order: User to be restored. | ||
| :return: | ||
| """ | ||
| user_email = user.email | ||
| remove_str = '.deleted' | ||
| if user_email.endswith(remove_str): | ||
| user_email = user_email[:-len(remove_str)] | ||
| try: | ||
| db.session.query(User).filter_by(email=user_email).one() | ||
| except NoResultFound: | ||
| user.email = user_email | ||
| save_to_db(user) | ||
| else: | ||
| raise ForbiddenException({'pointer': '/data/attributes/email'}, | ||
| "This email is already registered! Manually edit and then try restoring") | ||
| return user | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
migrations/versions/6f7b6fad3f56_refactor_deleted_users_email.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| """Refactor deleted users email | ||
| Revision ID: 6f7b6fad3f56 | ||
| Revises: 0e80c49a6e28 | ||
| Create Date: 2019-05-24 03:26:25 | ||
| """ | ||
|
|
||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = '6f7b6fad3f56' | ||
| down_revision = '0e80c49a6e28' | ||
|
|
||
|
|
||
| def upgrade(): | ||
| op.execute("UPDATE users SET _email = concat(_email, '.deleted') where deleted_at IS NOT NULL;", | ||
| execution_options=None) | ||
|
|
||
| def downgrade(): | ||
| op.execute("UPDATE users SET _email = left(_email, length(_email)-8) where right(_email, 8) = '.deleted' and deleted_at IS NOT NULL;", | ||
| execution_options=None) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.