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

Remove event number in slug to fix HttpError migrating emails #954

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions core/gmail_accounts.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

from django.conf import settings
from django.utils import timezone
from django.utils.crypto import get_random_string
Expand Down Expand Up @@ -86,15 +88,18 @@ def migrate_gmail_account(new_event, slug):
if not service:
return None

service.users().patch(
userKey=old_email,
body={
"primaryEmail": new_email,
},
).execute()
try:
service.users().patch(
userKey=old_email,
body={
"primaryEmail": new_email,
},
).execute()

# The old email address is kept as an alias to the new one, but we don't want this.
service.users().aliases().delete(userKey=new_email, alias=old_email).execute()
# The old email address is kept as an alias to the new one, but we don't want this.
service.users().aliases().delete(userKey=new_email, alias=old_email).execute()
except HttpError:
pass

if old_event:
old_event.email = new_email
Expand Down Expand Up @@ -123,12 +128,14 @@ def get_or_create_gmail(event_application, event):
"""
if get_gmail_account(event_application.website_slug) or get_gmail_account(event.page_url):
# account exists, do we need to migrate?
p = re.compile(r"\W\d+")
slug = p.sub(event_application.website_slug)
if event_application.has_past_team_members(event):
# has old organizers, so no need to do anything
return make_email(event_application.website_slug), None
return make_email(slug), None
else:
# migrate old email
migrate_gmail_account(event, event_application.website_slug)
migrate_gmail_account(event, slug)
# create new account
return create_gmail_account(event)
else:
Expand Down
Loading