snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
73
zerver/migrations/0439_fix_deleteduser_email.py
Normal file
73
zerver/migrations/0439_fix_deleteduser_email.py
Normal file
@@ -0,0 +1,73 @@
|
||||
# Generated by Django 4.2 on 2023-04-17 18:25
|
||||
|
||||
from email.headerregistry import Address
|
||||
from functools import lru_cache
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.validators import validate_email
|
||||
from django.db import migrations
|
||||
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
||||
from django.db.migrations.state import StateApps
|
||||
from django.db.models import Q
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_fake_email_domain(apps: StateApps, realm_id: int) -> str:
|
||||
Realm = apps.get_model("zerver", "Realm")
|
||||
realm = Realm.objects.get(id=realm_id)
|
||||
|
||||
# Build out realm.host
|
||||
subdomain = realm.string_id
|
||||
if subdomain == "":
|
||||
host = settings.EXTERNAL_HOST
|
||||
else:
|
||||
default_host = f"{subdomain}.{settings.EXTERNAL_HOST}"
|
||||
host = settings.REALM_HOSTS.get(subdomain, default_host)
|
||||
|
||||
# Implement get_fake_email_domain
|
||||
try:
|
||||
validate_email(Address(username="bot", domain=host).addr_spec)
|
||||
return host
|
||||
except ValidationError:
|
||||
pass
|
||||
|
||||
try:
|
||||
# Check that the fake email domain can be used to form valid email addresses.
|
||||
validate_email(Address(username="bot", domain=settings.FAKE_EMAIL_DOMAIN).addr_spec)
|
||||
return settings.FAKE_EMAIL_DOMAIN
|
||||
except ValidationError:
|
||||
raise Exception(
|
||||
settings.FAKE_EMAIL_DOMAIN + " is not a valid domain. "
|
||||
"Consider setting the FAKE_EMAIL_DOMAIN setting."
|
||||
)
|
||||
|
||||
|
||||
def fix_invalid_emails(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
|
||||
"""Find deleted users prior to the fix in 208c0c303405, which have
|
||||
invalid delivery_email values; fixing them allows them to survive
|
||||
an export/import.
|
||||
"""
|
||||
|
||||
UserProfile = apps.get_model("zerver", "UserProfile")
|
||||
invalid_users = UserProfile.objects.filter(is_active=False).filter(
|
||||
Q(delivery_email__icontains="@https://") | Q(delivery_email__icontains="@http://")
|
||||
)
|
||||
for invalid_user in invalid_users:
|
||||
local_part = invalid_user.delivery_email.split("@")[0]
|
||||
invalid_user.delivery_email = (
|
||||
local_part + "@" + get_fake_email_domain(apps, invalid_user.realm_id)
|
||||
)
|
||||
invalid_user.save(update_fields=["delivery_email"])
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("zerver", "0438_add_web_mark_read_on_scroll_policy_setting"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(
|
||||
fix_invalid_emails, reverse_code=migrations.RunPython.noop, elidable=True
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user