mirror of https://github.com/zulip/zulip.git
actions: Extract get_active_bots_owned_by_user function.
This commit is contained in:
parent
8261f7e801
commit
20f99f429d
|
@ -1137,6 +1137,10 @@ def change_user_is_active(user_profile: UserProfile, value: bool) -> None:
|
|||
Subscription.objects.filter(user_profile=user_profile).update(is_user_active=value)
|
||||
|
||||
|
||||
def get_active_bots_owned_by_user(user_profile: UserProfile) -> QuerySet:
|
||||
return UserProfile.objects.filter(is_bot=True, is_active=True, bot_owner=user_profile)
|
||||
|
||||
|
||||
def do_deactivate_user(
|
||||
user_profile: UserProfile, _cascade: bool = True, *, acting_user: Optional[UserProfile]
|
||||
) -> None:
|
||||
|
@ -1147,9 +1151,7 @@ def do_deactivate_user(
|
|||
# We need to deactivate bots before the target user, to ensure
|
||||
# that a failure partway through this function cannot result
|
||||
# in only the user being deactivated.
|
||||
bot_profiles = UserProfile.objects.filter(
|
||||
is_bot=True, is_active=True, bot_owner=user_profile
|
||||
)
|
||||
bot_profiles = get_active_bots_owned_by_user(user_profile)
|
||||
for profile in bot_profiles:
|
||||
do_deactivate_user(profile, _cascade=False, acting_user=acting_user)
|
||||
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
from argparse import ArgumentParser
|
||||
from typing import Any
|
||||
|
||||
from zerver.lib.actions import do_deactivate_user
|
||||
from zerver.lib.actions import do_deactivate_user, get_active_bots_owned_by_user
|
||||
from zerver.lib.management import CommandError, ZulipBaseCommand
|
||||
from zerver.lib.sessions import user_sessions
|
||||
from zerver.models import UserProfile
|
||||
|
||||
|
||||
class Command(ZulipBaseCommand):
|
||||
|
@ -34,11 +33,7 @@ class Command(ZulipBaseCommand):
|
|||
print(
|
||||
"{} has {} active bots that will also be deactivated.".format(
|
||||
user_profile.delivery_email,
|
||||
UserProfile.objects.filter(
|
||||
is_bot=True,
|
||||
is_active=True,
|
||||
bot_owner=user_profile,
|
||||
).count(),
|
||||
get_active_bots_owned_by_user(user_profile).count(),
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
from argparse import ArgumentParser
|
||||
from typing import Any
|
||||
|
||||
from zerver.lib.actions import do_delete_user
|
||||
from zerver.lib.actions import do_delete_user, get_active_bots_owned_by_user
|
||||
from zerver.lib.management import CommandError, ZulipBaseCommand
|
||||
from zerver.models import UserProfile
|
||||
|
||||
|
||||
class Command(ZulipBaseCommand):
|
||||
|
@ -54,11 +53,7 @@ This will:
|
|||
print(
|
||||
"{} has {} active bots that will be deactivated as a result of the user's deletion.".format(
|
||||
user_profile.delivery_email,
|
||||
UserProfile.objects.filter(
|
||||
is_bot=True,
|
||||
is_active=True,
|
||||
bot_owner=user_profile,
|
||||
).count(),
|
||||
get_active_bots_owned_by_user(user_profile).count(),
|
||||
)
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue