mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 09:27:43 +00:00
This is a preparatory commit for using isort for sorting all of our imports, merging changes to files where we can easily review the changes as something we're happy with. These are also files with relatively little active development, which means we don't expect much merge conflict risk from these changes.
39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
from argparse import ArgumentParser
|
|
from typing import Any
|
|
|
|
from django.core.management.base import CommandError
|
|
|
|
from zerver.lib.actions import do_mark_all_as_read
|
|
from zerver.lib.management import ZulipBaseCommand
|
|
from zerver.models import Message
|
|
|
|
|
|
class Command(ZulipBaseCommand):
|
|
help = """Bankrupt one or many users."""
|
|
|
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
|
parser.add_argument('emails', metavar='<email>', type=str, nargs='+',
|
|
help='email address to bankrupt')
|
|
self.add_realm_args(parser, True)
|
|
|
|
def handle(self, *args: Any, **options: str) -> None:
|
|
realm = self.get_realm(options)
|
|
for email in options['emails']:
|
|
try:
|
|
user_profile = self.get_user(email, realm)
|
|
except CommandError:
|
|
print("e-mail %s doesn't exist in the realm %s, skipping" % (email, realm))
|
|
continue
|
|
do_mark_all_as_read(user_profile, self.get_client())
|
|
|
|
messages = Message.objects.filter(
|
|
usermessage__user_profile=user_profile).order_by('-id')[:1]
|
|
if messages:
|
|
old_pointer = user_profile.pointer
|
|
new_pointer = messages[0].id
|
|
user_profile.pointer = new_pointer
|
|
user_profile.save(update_fields=["pointer"])
|
|
print("%s: %d => %d" % (email, old_pointer, new_pointer))
|
|
else:
|
|
print("%s has no messages, can't bankrupt!" % (email,))
|