From 23036a9f404915ce42b6452908467cba7f44ce78 Mon Sep 17 00:00:00 2001 From: Vishnu KS Date: Tue, 17 Sep 2019 17:34:48 +0530 Subject: [PATCH] confirmation: Set confirmation object realm attribute in realm reactivation. The value of realm attribute in confirmation object used to be empty before. We are not currently using the realm attribute of reactivation links anywhere. The value of realm stored in content_object is currently used. --- confirmation/models.py | 3 +++ zerver/tests/test_realm.py | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/confirmation/models.py b/confirmation/models.py index 4cc1b5a2fe..66c0af92e7 100644 --- a/confirmation/models.py +++ b/confirmation/models.py @@ -72,6 +72,9 @@ def create_confirmation_link(obj: ContentType, host: str, realm = None if hasattr(obj, 'realm'): realm = obj.realm + elif isinstance(obj, Realm): + realm = obj + Confirmation.objects.create(content_object=obj, date_sent=timezone_now(), confirmation_key=key, realm=realm, type=confirmation_type) return confirmation_url(key, host, confirmation_type, url_args) diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.py index fca71673ff..df29209e3d 100644 --- a/zerver/tests/test_realm.py +++ b/zerver/tests/test_realm.py @@ -223,6 +223,15 @@ class RealmTest(ZulipTestCase): realm = get_realm('zulip') self.assertFalse(realm.deactivated) + def test_realm_reactivation_confirmation_object(self) -> None: + realm = get_realm('zulip') + do_deactivate_realm(realm) + self.assertTrue(realm.deactivated) + create_confirmation_link(realm, realm.host, Confirmation.REALM_REACTIVATION) + confirmation = Confirmation.objects.last() + self.assertEqual(confirmation.content_object, realm) + self.assertEqual(confirmation.realm, realm) + def test_do_send_realm_reactivation_email(self) -> None: realm = get_realm('zulip') do_send_realm_reactivation_email(realm)