From 06dd7a3a680254cb61b55cb7d2f44991087ec5d0 Mon Sep 17 00:00:00 2001 From: Lauryn Menard Date: Mon, 1 May 2023 12:47:38 +0200 Subject: [PATCH] emails: Add corporate_enabled to context for emails. In commit fc58c35c0, we added a check in various emails for the settings.CORPORATE_ENABLED value, but that context is only always included for views/templates with a request. Here we add that to common_context, which is often used when there is not a request (like with emails). And we manually add it to the email context in various cases when there is not a user account to call with common_context: new user invitations, registration emails, and realm reactivation emails. --- zerver/actions/invites.py | 1 + zerver/actions/realm_settings.py | 7 ++++++- zerver/context_processors.py | 1 + zerver/views/registration.py | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/zerver/actions/invites.py b/zerver/actions/invites.py index 7a6066f81b..2e6e21e1a9 100644 --- a/zerver/actions/invites.py +++ b/zerver/actions/invites.py @@ -59,6 +59,7 @@ def do_send_confirmation_email( "referrer_email": referrer.delivery_email, "activate_url": activation_url, "referrer_realm_name": referrer.realm.name, + "corporate_enabled": settings.CORPORATE_ENABLED, } send_email( "zerver/emails/invitation", diff --git a/zerver/actions/realm_settings.py b/zerver/actions/realm_settings.py index 829b396318..1cb7108005 100644 --- a/zerver/actions/realm_settings.py +++ b/zerver/actions/realm_settings.py @@ -481,7 +481,12 @@ def do_send_realm_reactivation_email(realm: Realm, *, acting_user: Optional[User event_type=RealmAuditLog.REALM_REACTIVATION_EMAIL_SENT, event_time=timezone_now(), ) - context = {"confirmation_url": url, "realm_uri": realm.uri, "realm_name": realm.name} + context = { + "confirmation_url": url, + "realm_uri": realm.uri, + "realm_name": realm.name, + "corporate_enabled": settings.CORPORATE_ENABLED, + } language = realm.default_language send_email_to_admins( "zerver/emails/realm_reactivation", diff --git a/zerver/context_processors.py b/zerver/context_processors.py index 04c8b18dae..ef47311405 100644 --- a/zerver/context_processors.py +++ b/zerver/context_processors.py @@ -47,6 +47,7 @@ def common_context(user: UserProfile) -> Dict[str, Any]: "external_url_scheme": settings.EXTERNAL_URI_SCHEME, "external_host": settings.EXTERNAL_HOST, "user_name": user.full_name, + "corporate_enabled": settings.CORPORATE_ENABLED, } diff --git a/zerver/views/registration.py b/zerver/views/registration.py index 23d8ddd1f2..351d61b360 100644 --- a/zerver/views/registration.py +++ b/zerver/views/registration.py @@ -692,6 +692,7 @@ def send_confirm_registration_email( context={ "create_realm": (realm is None), "activate_url": activation_url, + "corporate_enabled": settings.CORPORATE_ENABLED, }, realm=realm, request=request,