mirror of https://github.com/zulip/zulip.git
Add a management command to deactivate old realms.
(imported from commit f6b1d0cb5b10f91683afcffea88b23b1a75a9ad2)
This commit is contained in:
parent
a06b5bd720
commit
511e1a12e3
|
@ -3,6 +3,7 @@ from __future__ import absolute_import
|
|||
from django.conf import settings
|
||||
from django.core import validators
|
||||
from django.contrib.sessions.models import Session
|
||||
from zerver.lib.cache import update_user_profile_cache
|
||||
from zerver.lib.context_managers import lockfile
|
||||
from zerver.models import Realm, RealmEmoji, Stream, UserProfile, UserActivity, \
|
||||
Subscription, Recipient, Message, UserMessage, valid_stream_name, \
|
||||
|
@ -138,6 +139,29 @@ def delete_all_user_sessions():
|
|||
for session in Session.objects.all():
|
||||
delete_session(session)
|
||||
|
||||
def active_humans_in_realm(realm):
|
||||
return UserProfile.objects.filter(realm=realm, is_active=True, is_bot=False)
|
||||
|
||||
def do_deactivate_realm(realm):
|
||||
"""
|
||||
Deactivate this realm. Do NOT deactivate the users -- we need to be able to
|
||||
tell the difference between users that were intentionally deactivated,
|
||||
e.g. by a realm admin, and users who can't currently use Zulip because their
|
||||
realm has been deactivated.
|
||||
"""
|
||||
if realm.deactivated:
|
||||
return
|
||||
|
||||
realm.deactivated = True
|
||||
realm.save(update_fields=["deactivated"])
|
||||
|
||||
for user in active_humans_in_realm(realm):
|
||||
# Don't deactivate the users, but do delete their sessions so they get
|
||||
# bumped to the login screen, where they'll get a realm deactivation
|
||||
# notice when they try to log in.
|
||||
delete_user_sessions(user)
|
||||
update_user_profile_cache(None, instance=user, update_fields=None)
|
||||
|
||||
def do_deactivate_user(user_profile, log=True, _cascade=True):
|
||||
if not user_profile.is_active:
|
||||
return
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from zerver.lib.actions import do_deactivate_realm
|
||||
from zerver.models import get_realm
|
||||
|
||||
domains_to_deactivate = """"""
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = """One-off script to deactivate our old realms."""
|
||||
|
||||
def handle(self, *args, **options):
|
||||
for domain in [elt.strip() for elt in domains_to_deactivate.split("\n")]:
|
||||
print "Deactivating", domain
|
||||
do_deactivate_realm(get_realm(domain))
|
||||
print "Done!"
|
Loading…
Reference in New Issue