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!")
def realm_reactivation(request: HttpRequest, confirmation_key: str) -> HttpResponse: try: realm = get_object_from_key(confirmation_key, Confirmation.REALM_REACTIVATION) except ConfirmationKeyException: return render(request, 'zerver/realm_reactivation_link_error.html') do_reactivate_realm(realm) context = {"realm": realm} return render(request, 'zerver/realm_reactivation.html', context)
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!")
def handle(self, *args, **options): # type: (*Any, **str) -> None realm = get_realm(options["string_id"]) if realm is None: print("Could not find realm %s" % (options["string_id"],)) sys.exit(1) print("Reactivating", options["string_id"]) do_reactivate_realm(realm) print("Done!")
def handle(self, *args: Any, **options: str) -> None: realm = self.get_realm(options) assert realm is not None # Should be ensured by parser if not realm.deactivated: print("Realm", options["realm_id"], "is already active.") exit(0) print("Reactivating", options["realm_id"]) do_reactivate_realm(realm) print("Done!")
def test_authenticated_json_post_view_if_user_realm_is_deactivated(self): user_email = '*****@*****.**' user_profile = get_user_profile_by_email(user_email) self._login(user_email) # we deactivate user's realm manually because do_deactivate_user removes user session user_profile.realm.deactivated = True user_profile.realm.save() self.assert_json_error_contains(self._do_test(user_email), "Realm for account has been deactivated") do_reactivate_realm(user_profile.realm)
def handle(self, *args, **options): # type: (*Any, **str) -> None realm = self.get_realm(options) if not realm.deactivated: print("Realm", options["realm_id"], "is already active.") exit(0) print("Reactivating", options["realm_id"]) do_reactivate_realm(realm) print("Done!")
def handle(self, *args, **options): # type: (*Any, **str) -> None realm = get_realm_by_string_id(options["string_id"]) if realm is None: print("Could not find realm %s" % (options["string_id"], )) sys.exit(1) print("Reactivating", options["string_id"]) do_reactivate_realm(realm) print("Done!")
def test_realm_activation(self) -> None: realm = get_realm('zulip') do_deactivate_realm(realm) log_entry = RealmAuditLog.objects.get(realm=realm, event_type=RealmAuditLog.REALM_DEACTIVATED) extra_data = ujson.loads(log_entry.extra_data) self.check_role_count_schema(extra_data[RealmAuditLog.ROLE_COUNT]) do_reactivate_realm(realm) log_entry = RealmAuditLog.objects.get(realm=realm, event_type=RealmAuditLog.REALM_REACTIVATED) extra_data = ujson.loads(log_entry.extra_data) self.check_role_count_schema(extra_data[RealmAuditLog.ROLE_COUNT])
def test_authenticated_json_post_view_if_user_realm_is_deactivated(self): # type: () -> None user_email = self.example_email('hamlet') user_realm = get_realm('zulip') user_profile = get_user(user_email, user_realm) self._login(user_email, user_realm) # we deactivate user's realm manually because do_deactivate_user removes user session user_profile.realm.deactivated = True user_profile.realm.save() self.assert_json_error_contains(self._do_test(user_email), "Realm for account has been deactivated") do_reactivate_realm(user_profile.realm)
def test_realm_activation(self) -> None: realm = get_realm("zulip") user = self.example_user("desdemona") do_deactivate_realm(realm, acting_user=user) log_entry = RealmAuditLog.objects.get( realm=realm, event_type=RealmAuditLog.REALM_DEACTIVATED, acting_user=user ) extra_data = orjson.loads(log_entry.extra_data) self.check_role_count_schema(extra_data[RealmAuditLog.ROLE_COUNT]) do_reactivate_realm(realm) log_entry = RealmAuditLog.objects.get( realm=realm, event_type=RealmAuditLog.REALM_REACTIVATED ) extra_data = orjson.loads(log_entry.extra_data) self.check_role_count_schema(extra_data[RealmAuditLog.ROLE_COUNT])
def verify_backend(self, backend, good_args=None, good_kwargs=None, bad_kwargs=None, email_to_username=None): # type: (Any, List[Any], Dict[str, Any], Dict[str, Any], Callable[[text_type], text_type]) -> None if good_args is None: good_args = [] if good_kwargs is None: good_kwargs = {} email = u"*****@*****.**" user_profile = get_user_profile_by_email(email) username = email if email_to_username is not None: username = email_to_username(email) # If bad_kwargs was specified, verify auth fails in that case if bad_kwargs is not None: self.assertIsNone(backend.authenticate(username, **bad_kwargs)) # Verify auth works result = backend.authenticate(username, *good_args, **good_kwargs) self.assertEqual(user_profile, result) # Verify auth fails with a deactivated user do_deactivate_user(user_profile) self.assertIsNone(backend.authenticate(username, *good_args, **good_kwargs)) # Reactivate the user and verify auth works again do_reactivate_user(user_profile) result = backend.authenticate(username, *good_args, **good_kwargs) self.assertEqual(user_profile, result) # Verify auth fails with a deactivated realm do_deactivate_realm(user_profile.realm) self.assertIsNone(backend.authenticate(username, *good_args, **good_kwargs)) # Verify auth works again after reactivating the realm do_reactivate_realm(user_profile.realm) result = backend.authenticate(username, *good_args, **good_kwargs) self.assertEqual(user_profile, result)