Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add domain to API flags blocked notification #4574

Merged
merged 9 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1648,13 +1649,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 @@ -1663,7 +1664,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 @@ -1676,7 +1681,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
Loading