mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
send_email: Distinct emails means distinct, case-insensitively.
This commit is contained in:
committed by
Tim Abbott
parent
8d9ead0f6d
commit
bd38e6cb69
@@ -21,6 +21,7 @@ from django.core.mail.message import sanitize_address
|
|||||||
from django.core.management import CommandError
|
from django.core.management import CommandError
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.db.models import QuerySet
|
from django.db.models import QuerySet
|
||||||
|
from django.db.models.functions import Lower
|
||||||
from django.http import HttpRequest
|
from django.http import HttpRequest
|
||||||
from django.template import loader
|
from django.template import loader
|
||||||
from django.utils.timezone import now as timezone_now
|
from django.utils.timezone import now as timezone_now
|
||||||
@@ -583,7 +584,7 @@ def send_custom_email(
|
|||||||
options: Dict[str, str],
|
options: Dict[str, str],
|
||||||
add_context: Optional[Callable[[Dict[str, object], UserProfile], None]] = None,
|
add_context: Optional[Callable[[Dict[str, object], UserProfile], None]] = None,
|
||||||
distinct_email: bool = False,
|
distinct_email: bool = False,
|
||||||
) -> None:
|
) -> QuerySet[UserProfile]:
|
||||||
"""
|
"""
|
||||||
Helper for `manage.py send_custom_email`.
|
Helper for `manage.py send_custom_email`.
|
||||||
|
|
||||||
@@ -598,7 +599,11 @@ def send_custom_email(
|
|||||||
|
|
||||||
users = users.select_related("realm")
|
users = users.select_related("realm")
|
||||||
if distinct_email:
|
if distinct_email:
|
||||||
users = users.distinct("delivery_email").order_by("delivery_email", "id")
|
users = (
|
||||||
|
users.annotate(lower_email=Lower("delivery_email"))
|
||||||
|
.distinct("lower_email")
|
||||||
|
.order_by("lower_email", "id")
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
users = users.order_by("id")
|
users = users.order_by("id")
|
||||||
for user_profile in users:
|
for user_profile in users:
|
||||||
@@ -617,6 +622,7 @@ def send_custom_email(
|
|||||||
|
|
||||||
if dry_run:
|
if dry_run:
|
||||||
break
|
break
|
||||||
|
return users
|
||||||
|
|
||||||
|
|
||||||
def send_custom_server_email(
|
def send_custom_server_email(
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ class Command(ZulipBaseCommand):
|
|||||||
users = users.exclude(
|
users = users.exclude(
|
||||||
Q(tos_version=None) | Q(tos_version=UserProfile.TOS_VERSION_BEFORE_FIRST_LOGIN)
|
Q(tos_version=None) | Q(tos_version=UserProfile.TOS_VERSION_BEFORE_FIRST_LOGIN)
|
||||||
)
|
)
|
||||||
send_custom_email(
|
users = send_custom_email(
|
||||||
users,
|
users,
|
||||||
dry_run=dry_run,
|
dry_run=dry_run,
|
||||||
options=options,
|
options=options,
|
||||||
|
|||||||
Reference in New Issue
Block a user