mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 21:13:36 +00:00
corporate: Import corporate.lib.stripe lazily.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
fcafcb24d7
commit
f0f048de69
@@ -48,9 +48,6 @@ from zerver.models.realms import (
|
||||
from zerver.models.users import get_system_bot
|
||||
from zproject.backends import all_default_backend_names
|
||||
|
||||
if settings.CORPORATE_ENABLED:
|
||||
from corporate.lib.support import get_realm_support_url
|
||||
|
||||
|
||||
def do_change_realm_subdomain(
|
||||
realm: Realm,
|
||||
@@ -372,6 +369,8 @@ def do_create_realm(
|
||||
|
||||
# Send a notification to the admin realm when a new organization registers.
|
||||
if settings.CORPORATE_ENABLED:
|
||||
from corporate.lib.support import get_realm_support_url
|
||||
|
||||
admin_realm = get_realm(settings.SYSTEM_BOT_REALM)
|
||||
sender = get_system_bot(settings.NOTIFICATION_BOT, admin_realm.id)
|
||||
|
||||
|
||||
@@ -62,10 +62,6 @@ from zerver.models.realm_audit_logs import AuditLogEventType
|
||||
from zerver.models.users import active_user_ids, bot_owner_user_ids, get_system_bot
|
||||
from zerver.tornado.django_api import send_event_on_commit
|
||||
|
||||
if settings.BILLING_ENABLED:
|
||||
from corporate.lib.stripe import RealmBillingSession
|
||||
|
||||
|
||||
MAX_NUM_RECENT_MESSAGES = 1000
|
||||
MAX_NUM_RECENT_UNREAD_MESSAGES = 20
|
||||
|
||||
@@ -512,6 +508,9 @@ def do_create_user(
|
||||
email_address_visibility: int | None = None,
|
||||
add_initial_stream_subscriptions: bool = True,
|
||||
) -> UserProfile:
|
||||
if settings.BILLING_ENABLED:
|
||||
from corporate.lib.stripe import RealmBillingSession
|
||||
|
||||
with transaction.atomic():
|
||||
user_profile = create_user(
|
||||
email=email,
|
||||
@@ -643,6 +642,9 @@ def do_activate_mirror_dummy_user(
|
||||
parallel code path to do_create_user; e.g. it likely does not
|
||||
handle preferences or default streams properly.
|
||||
"""
|
||||
if settings.BILLING_ENABLED:
|
||||
from corporate.lib.stripe import RealmBillingSession
|
||||
|
||||
with transaction.atomic():
|
||||
change_user_is_active(user_profile, True)
|
||||
user_profile.is_mirror_dummy = False
|
||||
@@ -714,6 +716,8 @@ def do_reactivate_user(user_profile: UserProfile, *, acting_user: UserProfile |
|
||||
bot_owner_changed = True
|
||||
|
||||
if settings.BILLING_ENABLED:
|
||||
from corporate.lib.stripe import RealmBillingSession
|
||||
|
||||
billing_session = RealmBillingSession(user=user_profile, realm=user_profile.realm)
|
||||
billing_session.update_license_ledger_if_needed(event_time)
|
||||
|
||||
|
||||
@@ -51,9 +51,6 @@ from zerver.models.realms import get_default_max_invites_for_realm_plan_type, ge
|
||||
from zerver.models.users import active_user_ids
|
||||
from zerver.tornado.django_api import send_event_on_commit
|
||||
|
||||
if settings.BILLING_ENABLED:
|
||||
from corporate.lib.stripe import RealmBillingSession
|
||||
|
||||
|
||||
@transaction.atomic(savepoint=False)
|
||||
def do_set_realm_property(
|
||||
@@ -516,6 +513,9 @@ def do_deactivate_realm(
|
||||
if realm.deactivated:
|
||||
return
|
||||
|
||||
if settings.BILLING_ENABLED:
|
||||
from corporate.lib.stripe import RealmBillingSession
|
||||
|
||||
with transaction.atomic():
|
||||
realm.deactivated = True
|
||||
realm.save(update_fields=["deactivated"])
|
||||
@@ -623,6 +623,8 @@ def do_delete_all_realm_attachments(realm: Realm, *, batch_size: int = 1000) ->
|
||||
|
||||
def do_scrub_realm(realm: Realm, *, acting_user: UserProfile | None) -> None:
|
||||
if settings.BILLING_ENABLED:
|
||||
from corporate.lib.stripe import RealmBillingSession
|
||||
|
||||
billing_session = RealmBillingSession(user=acting_user, realm=realm)
|
||||
billing_session.downgrade_now_without_creating_additional_invoices()
|
||||
|
||||
|
||||
@@ -53,9 +53,6 @@ from zerver.models.users import (
|
||||
)
|
||||
from zerver.tornado.django_api import send_event_on_commit
|
||||
|
||||
if settings.BILLING_ENABLED:
|
||||
from corporate.lib.stripe import RealmBillingSession
|
||||
|
||||
|
||||
def do_delete_user(user_profile: UserProfile, *, acting_user: UserProfile | None) -> None:
|
||||
if user_profile.realm.is_zephyr_mirror_realm:
|
||||
@@ -324,6 +321,9 @@ def do_deactivate_user(
|
||||
if not user_profile.is_active:
|
||||
return
|
||||
|
||||
if settings.BILLING_ENABLED:
|
||||
from corporate.lib.stripe import RealmBillingSession
|
||||
|
||||
if _cascade:
|
||||
# We need to deactivate bots before the target user, to ensure
|
||||
# that a failure partway through this function cannot result
|
||||
@@ -474,6 +474,8 @@ def do_change_user_role(
|
||||
)
|
||||
maybe_enqueue_audit_log_upload(user_profile.realm)
|
||||
if settings.BILLING_ENABLED and UserProfile.ROLE_GUEST in [old_value, value]:
|
||||
from corporate.lib.stripe import RealmBillingSession
|
||||
|
||||
billing_session = RealmBillingSession(user=user_profile, realm=user_profile.realm)
|
||||
billing_session.update_license_ledger_if_needed(timezone_now())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user