Skip to content

Commit

Permalink
chore: update org cancelled alert to only send to customersuccess@fla…
Browse files Browse the repository at this point in the history
…gsmith.com (#4522)
  • Loading branch information
matthewelwell authored Aug 21, 2024
1 parent af0369c commit 18ed5d2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
4 changes: 4 additions & 0 deletions api/app/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,3 +1238,7 @@
"EDGE_V2_MIGRATION_READ_CAPACITY_BUDGET",
default=0,
)

ORG_SUBSCRIPTION_CANCELLED_ALERT_RECIPIENT_LIST = env.list(
"ORG_SUBSCRIPTION_CANCELLED_ALERT_RECIPIENT_LIST", default=[]
)
14 changes: 10 additions & 4 deletions api/organisations/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from app_analytics.influxdb_wrapper import get_current_api_usage
from django.conf import settings
from django.core.mail import send_mail
from django.db.models import F, Max, Q
from django.utils import timezone
from task_processor.decorators import (
Expand Down Expand Up @@ -73,10 +74,15 @@ def send_org_subscription_cancelled_alert(
organisation_name: str,
formatted_cancellation_date: str,
) -> None:
FFAdminUser.send_alert_to_admin_users(
subject=f"Organisation {organisation_name} has cancelled their subscription",
message=f"Organisation {organisation_name} has cancelled their subscription on {formatted_cancellation_date}",
)
if recipient_list := settings.ORG_SUBSCRIPTION_CANCELLED_ALERT_RECIPIENT_LIST:
send_mail(
subject=f"Organisation {organisation_name} has cancelled their subscription",
message=f"Organisation {organisation_name} has cancelled their subscription "
f"on {formatted_cancellation_date}",
from_email=settings.DEFAULT_FROM_EMAIL,
recipient_list=recipient_list,
fail_silently=True,
)


@register_recurring_task(
Expand Down
11 changes: 8 additions & 3 deletions api/tests/unit/organisations/test_unit_organisations_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,14 @@ def test_finish_subscription_cancellation(db: None, mocker: MockerFixture) -> No
assert organisation4.num_seats == organisation_user_count


def test_send_org_subscription_cancelled_alert(db: None, mocker: MockerFixture) -> None:
def test_send_org_subscription_cancelled_alert(
mocker: MockerFixture, settings: SettingsWrapper
) -> None:
# Given
send_mail_mock = mocker.patch("users.models.send_mail")
send_mail_mock = mocker.patch("organisations.tasks.send_mail")

recipient = "[email protected]"
settings.ORG_SUBSCRIPTION_CANCELLED_ALERT_RECIPIENT_LIST = [recipient]

# When
send_org_subscription_cancelled_alert(
Expand All @@ -268,7 +273,7 @@ def test_send_org_subscription_cancelled_alert(db: None, mocker: MockerFixture)
subject="Organisation TestCorp has cancelled their subscription",
message="Organisation TestCorp has cancelled their subscription on 2023-02-08 09:12:34",
from_email="[email protected]",
recipient_list=[],
recipient_list=[recipient],
fail_silently=True,
)

Expand Down
6 changes: 6 additions & 0 deletions api/tests/unit/organisations/test_unit_organisations_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ def test_when_subscription_is_set_to_non_renewing_then_cancellation_date_set_and
subscription: Subscription,
staff_user: FFAdminUser,
staff_client: APIClient,
settings: SettingsWrapper,
) -> None:
# Given
cancellation_date = datetime.now(tz=UTC) + timedelta(days=1)
Expand All @@ -640,6 +641,8 @@ def test_when_subscription_is_set_to_non_renewing_then_cancellation_date_set_and
}
url = reverse("api-v1:chargebee-webhook")

settings.ORG_SUBSCRIPTION_CANCELLED_ALERT_RECIPIENT_LIST = ["[email protected]"]

# When
staff_client.post(url, data=json.dumps(data), content_type="application/json")

Expand All @@ -658,6 +661,7 @@ def test_when_subscription_is_cancelled_then_cancellation_date_set_and_alert_sen
subscription: Subscription,
staff_user: FFAdminUser,
staff_client: APIClient,
settings: SettingsWrapper,
) -> None:
# Given
cancellation_date = datetime.now(tz=UTC) + timedelta(days=1)
Expand All @@ -676,6 +680,8 @@ def test_when_subscription_is_cancelled_then_cancellation_date_set_and_alert_sen
}
url = reverse("api-v1:chargebee-webhook")

settings.ORG_SUBSCRIPTION_CANCELLED_ALERT_RECIPIENT_LIST = ["[email protected]"]

# When
staff_client.post(url, data=json.dumps(data), content_type="application/json")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@
{
"name": "ENABLE_API_USAGE_ALERTING",
"value": "True"
},
{
"name": "ORG_SUBSCRIPTION_CANCELLED_ALERT_RECIPIENT_LIST",
"value": "[email protected]"
}
],
"secrets": [
Expand Down

0 comments on commit 18ed5d2

Please sign in to comment.