2016-06-04 16:52:18 +02:00
|
|
|
from argparse import ArgumentParser
|
2017-05-25 00:29:59 +02:00
|
|
|
from typing import Any
|
|
|
|
|
2023-10-12 19:43:45 +02:00
|
|
|
from typing_extensions import override
|
|
|
|
|
2022-04-14 23:49:26 +02:00
|
|
|
from zerver.actions.user_settings import do_change_user_delivery_email
|
2017-07-07 20:35:31 +02:00
|
|
|
from zerver.lib.management import ZulipBaseCommand
|
2013-02-10 22:45:25 +01:00
|
|
|
|
2020-01-14 21:59:46 +01:00
|
|
|
|
2017-07-07 20:35:31 +02:00
|
|
|
class Command(ZulipBaseCommand):
|
2015-08-21 02:10:41 +02:00
|
|
|
help = """Change the email address for a user."""
|
2013-02-10 22:45:25 +01:00
|
|
|
|
2023-10-12 19:43:45 +02:00
|
|
|
@override
|
2017-10-26 11:35:57 +02:00
|
|
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
2017-07-07 20:35:31 +02:00
|
|
|
self.add_realm_args(parser)
|
2021-02-12 08:20:45 +01:00
|
|
|
parser.add_argument("old_email", metavar="<old email>", help="email address to change")
|
|
|
|
parser.add_argument("new_email", metavar="<new email>", help="new email address")
|
2013-02-10 22:45:25 +01:00
|
|
|
|
2023-10-12 19:43:45 +02:00
|
|
|
@override
|
2017-10-26 11:35:57 +02:00
|
|
|
def handle(self, *args: Any, **options: str) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
old_email = options["old_email"]
|
|
|
|
new_email = options["new_email"]
|
2017-07-07 20:35:31 +02:00
|
|
|
|
|
|
|
realm = self.get_realm(options)
|
|
|
|
user_profile = self.get_user(old_email, realm)
|
2013-02-10 22:45:25 +01:00
|
|
|
|
2024-08-11 22:38:04 +02:00
|
|
|
do_change_user_delivery_email(user_profile, new_email, acting_user=None)
|