diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index efaea42be6..eb241b1eab 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -3295,9 +3295,6 @@ def do_create_realm(string_id: str, name: str, kwargs = {} # type: Dict[str, Any] if emails_restricted_to_domains is not None: kwargs['emails_restricted_to_domains'] = emails_restricted_to_domains - if settings.BILLING_ENABLED: - kwargs['plan_type'] = Realm.LIMITED - kwargs['message_visibility_limit'] = Realm.MESSAGE_VISIBILITY_LIMITED realm = Realm(string_id=string_id, name=name, **kwargs) realm.save() @@ -3312,6 +3309,9 @@ def do_create_realm(string_id: str, name: str, realm.save(update_fields=['notifications_stream', 'signup_notifications_stream']) + if settings.BILLING_ENABLED: + do_change_plan_type(realm, Realm.LIMITED) + # Log the event log_event({"type": "realm_created", "string_id": string_id, diff --git a/zerver/lib/import_realm.py b/zerver/lib/import_realm.py index b345c3a0c1..df753a3c7d 100644 --- a/zerver/lib/import_realm.py +++ b/zerver/lib/import_realm.py @@ -13,7 +13,8 @@ from django.utils.timezone import utc as timezone_utc, now as timezone_now from typing import Any, Dict, List, Optional, Set, Tuple, \ Iterable, cast -from zerver.lib.actions import UserMessageLite, bulk_insert_ums +from zerver.lib.actions import UserMessageLite, bulk_insert_ums, \ + do_change_plan_type from zerver.lib.avatar_hash import user_avatar_path_from_ids from zerver.lib.bulk_create import bulk_create_users from zerver.lib.timestamp import datetime_to_timestamp @@ -683,10 +684,6 @@ def do_import_realm(import_dir: Path, subdomain: str) -> Realm: update_model_ids(Realm, data, 'realm') realm = Realm(**data['zerver_realm'][0]) - if settings.BILLING_ENABLED: - realm.plan_type = Realm.LIMITED - else: - realm.plan_type = Realm.SELF_HOSTED if realm.notifications_stream_id is not None: notifications_stream_id = int(realm.notifications_stream_id) # type: Optional[int] @@ -909,6 +906,9 @@ def do_import_realm(import_dir: Path, subdomain: str) -> Realm: data = ujson.load(f) import_attachments(data) + + if settings.BILLING_ENABLED: + do_change_plan_type(realm, Realm.LIMITED) return realm # create_users and do_import_system_bots differ from their equivalent in diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.py index 004fe5ecb8..2f825ef61b 100644 --- a/zerver/tests/test_import_export.py +++ b/zerver/tests/test_import_export.py @@ -537,7 +537,8 @@ class ImportExportTest(ZulipTestCase): self._export_realm(original_realm) with patch('logging.info'): - do_import_realm('var/test-export', 'test-zulip') + with self.settings(BILLING_ENABLED=False): + do_import_realm('var/test-export', 'test-zulip') # sanity checks diff --git a/zerver/tests/test_slack_importer.py b/zerver/tests/test_slack_importer.py index 05a2bfb00c..484b5c07d0 100644 --- a/zerver/tests/test_slack_importer.py +++ b/zerver/tests/test_slack_importer.py @@ -561,7 +561,8 @@ class SlackImporter(ZulipTestCase): self.assertTrue(os.path.exists(output_dir + '/realm.json')) # test import of the converted slack data into an existing database - do_import_realm(output_dir, test_realm_subdomain) + with self.settings(BILLING_ENABLED=False): + do_import_realm(output_dir, test_realm_subdomain) realm = get_realm(test_realm_subdomain) self.assertTrue(realm.name, test_realm_subdomain)