Skip to content

Commit

Permalink
feat: Add domain to API flags blocked notification (#4574)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthew Elwell <[email protected]>
  • Loading branch information
zachaysan and matthewelwell authored Sep 27, 2024
1 parent b5c4615 commit dd1dd32
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
3 changes: 3 additions & 0 deletions api/organisations/task_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import timedelta

from app_analytics.influxdb_wrapper import get_current_api_usage
from core.helpers import get_current_site_url
from dateutil.relativedelta import relativedelta
from django.conf import settings
from django.core.mail import send_mail
Expand All @@ -26,9 +27,11 @@ def send_api_flags_blocked_notification(organisation: Organisation) -> None:
userorganisation__organisation=organisation,
)

url = get_current_site_url()
context = {
"organisation": organisation,
"grace_period": not hasattr(organisation, "breached_grace_period"),
"url": url,
}
message = "organisations/api_flags_blocked_notification.txt"
html_message = "organisations/api_flags_blocked_notification.html"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<tr>

<td>
This is a system generated notification related to your Flagsmith API Usage. As per previous warnings, we have had to block your company {{ organisation.name }}{% if grace_period %} after the 7 day grace period{% endif %}. Flags are not currently being served for your organization, and will continue to be blocked until your billing period resets or you upgrade your account. You can upgrade your account at <a href="app.flagsmith.com">app.flagsmith.com</a>.
This is a system generated notification related to your Flagsmith API Usage. As per previous warnings, we have had to block your company {{ organisation.name }}{% if grace_period %} after the 7 day grace period{% endif %}. Flags are not currently being served for your organization, and will continue to be blocked until your billing period resets or you upgrade your account. You can upgrade your account at <a href="{{url}}">{{url}}</a>.
</td>


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Hi there,

This is a system generated notification related to your Flagsmith API Usage. As per previous warnings, we have had to block your company {{ organisation.name }}{% if grace_period %} after the 7 day grace period{% endif %}. Flags are not currently being served for your organization, and will continue to be blocked until your billing period resets or you upgrade your account. You can upgrade your account at app.flagsmith.com.
This is a system generated notification related to your Flagsmith API Usage. As per previous warnings, we have had to block your company {{ organisation.name }}{% if grace_period %} after the 7 day grace period{% endif %}. Flags are not currently being served for your organization, and will continue to be blocked until your billing period resets or you upgrade your account. You can upgrade your account at {{ url }}.

Thank you!

Expand Down
17 changes: 13 additions & 4 deletions api/tests/unit/organisations/test_unit_organisations_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from unittest.mock import MagicMock, call

import pytest
from core.helpers import get_current_site_url
from django.core.mail.message import EmailMultiAlternatives
from django.template.loader import render_to_string
from django.utils import timezone
Expand Down Expand Up @@ -1646,13 +1647,13 @@ def test_restrict_use_due_to_api_limit_grace_period_over(
assert email1.subject == "Flagsmith API use has been blocked due to overuse"
assert email1.body == render_to_string(
"organisations/api_flags_blocked_notification.txt",
context={"organisation": organisation},
context={"organisation": organisation, "url": get_current_site_url()},
)
email2 = mailoutbox[1]
assert email2.subject == "Flagsmith API use has been blocked due to overuse"
assert email2.body == render_to_string(
"organisations/api_flags_blocked_notification.txt",
context={"organisation": organisation2},
context={"organisation": organisation2, "url": get_current_site_url()},
)

assert len(email2.alternatives) == 1
Expand All @@ -1661,7 +1662,11 @@ def test_restrict_use_due_to_api_limit_grace_period_over(

assert email2.alternatives[0][0] == render_to_string(
"organisations/api_flags_blocked_notification.html",
context={"organisation": organisation2, "grace_period": False},
context={
"organisation": organisation2,
"grace_period": False,
"url": get_current_site_url(),
},
)
assert email2.from_email == "[email protected]"
assert email2.to == ["[email protected]", "[email protected]"]
Expand All @@ -1674,7 +1679,11 @@ def test_restrict_use_due_to_api_limit_grace_period_over(

assert email3.alternatives[0][0] == render_to_string(
"organisations/api_flags_blocked_notification.html",
context={"organisation": organisation6, "grace_period": False},
context={
"organisation": organisation6,
"grace_period": False,
"url": get_current_site_url(),
},
)
assert email3.from_email == "[email protected]"
assert email3.to == ["[email protected]", "[email protected]"]
Expand Down

0 comments on commit dd1dd32

Please sign in to comment.