send_custom_email: Support JSON extra context with remote servers.

This commit is contained in:
Alex Vandiver 2023-12-13 22:06:39 +00:00 committed by Tim Abbott
parent 2863b5954e
commit 612f2c73d6
1 changed files with 21 additions and 1 deletions

View File

@ -101,7 +101,27 @@ class Command(ZulipBaseCommand):
if options["remote_servers"]:
servers = RemoteZulipServer.objects.filter(deactivated=False)
send_custom_server_email(servers, dry_run=dry_run, options=options)
add_server_context = None
if options["json_file"]:
with open(options["json_file"]) as f:
server_data: Dict[str, Dict[str, object]] = orjson.loads(f.read())
servers = RemoteZulipServer.objects.filter(
id__in=[int(server_id) for server_id in server_data]
)
def add_server_context_from_dict(
context: Dict[str, object], server: RemoteZulipServer
) -> None:
context.update(server_data.get(str(server.id), {}))
add_server_context = add_server_context_from_dict
send_custom_server_email(
servers,
dry_run=dry_run,
options=options,
add_context=add_server_context,
)
if dry_run:
print("Would send the above email to:")
for server in servers: