diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 2653c0e382..8470b4f768 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -376,6 +376,10 @@ def do_deactivate_realm(realm): # notice when they try to log in. delete_user_sessions(user) +def do_reactivate_realm(realm): + realm.deactivated = False + realm.save(update_fields=["deactivated"]) + def do_deactivate_user(user_profile, log=True, _cascade=True): if not user_profile.is_active: return diff --git a/zerver/management/commands/reactivate_realm.py b/zerver/management/commands/reactivate_realm.py new file mode 100644 index 0000000000..f38035ec08 --- /dev/null +++ b/zerver/management/commands/reactivate_realm.py @@ -0,0 +1,25 @@ +from __future__ import absolute_import +from __future__ import print_function + +from django.core.management.base import BaseCommand + +import sys + +from zerver.lib.actions import do_reactivate_realm +from zerver.models import get_realm + +class Command(BaseCommand): + help = """Script to reactivate a deactivated realm.""" + + def add_arguments(self, parser): + parser.add_argument('domain', metavar='', type=str, + help='domain of realm to reactivate') + + def handle(self, *args, **options): + realm = get_realm(options["domain"]) + if realm is None: + print("Could not find realm %s" % (options["domain"],)) + sys.exit(1) + print("Reactivating", options["domain"]) + do_reactivate_realm(realm) + print("Done!")