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 logic to API usage notification templates #4206

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
The API usage for {{ organisation.name }} has reached
{{ matched_threshold }}% within the current subscription period.
Please consider upgrading your organisation's account limits.
{% if organisation.is_paid %}
Please note that once the 100% use has been breached automated charges for your account may apply.
{% else %}
Please note that once the 100% use has been breached the serving of feature flags and admin access may be disabled after a grace period.
{% endif %}

</td>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ Hi there,

The API usage for {{ organisation.name }} has reached {{ matched_threshold }}% within the current subscription period. Please consider upgrading your organisation's account limits.

{% if organisation.is_paid %}
Please note that once the 100% use has been breached automated charges for your account may apply.
{% else %}
Please note that once the 100% use has been breached the serving of feature flags and admin access may be disabled after a grace period.
{% endif %}
Thank you!

The Flagsmith Team
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
<td>
The API usage for {{ organisation.name }} has breached
{{ matched_threshold }}% within the current subscription period.
Please upgrade your organisation's account to ensure continued service.
{% if organisation.is_paid %}
Please note that automated charges for your account may apply.
{% else %}
Please note that the serving of feature flags and admin access may be disabled after a grace period, so please upgrade your organisation's account to ensure continued service.
{% endif %}
</td>


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

The API usage for {{ organisation.name }} has breached {{ matched_threshold }}% within the current subscription period. Please upgrade your organisation's account to ensure continued service.
The API usage for {{ organisation.name }} has breached {{ matched_threshold }}% within the current subscription period.

{% if organisation.is_paid %}
Please note that automated charges for your account may apply.
{% else %}
Please note that the serving of feature flags and admin access may be disabled after a grace period, so please upgrade your organisation's account to ensure continued service.
{% endif %}

Thank you!

Expand Down
94 changes: 51 additions & 43 deletions api/tests/unit/organisations/test_unit_organisations_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ def test_handle_api_usage_notifications_below_100(
# Given
now = timezone.now()
organisation.subscription.plan = SCALE_UP
organisation.subscription.subscription_id = "fancy_id"
organisation.subscription.save()
OrganisationSubscriptionInformationCache.objects.create(
organisation=organisation,
Expand Down Expand Up @@ -328,7 +329,9 @@ def test_handle_api_usage_notifications_below_100(
assert email.body == (
"Hi there,\n\nThe API usage for Test Org has reached "
"90% within the current subscription period. Please "
"consider upgrading your organisation's account limits.\n\n"
"consider upgrading your organisation's account limits.\n\n\n"
"Please note that once the 100% use has been breached "
"automated charges for your account may apply.\n\n"
"Thank you!\n\nThe Flagsmith Team\n"
)

Expand All @@ -337,16 +340,18 @@ def test_handle_api_usage_notifications_below_100(
assert email.alternatives[0][1] == "text/html"

assert email.alternatives[0][0] == (
"<table>\n\n <tr>\n\n "
"<td>Hi there,</td>\n\n </tr>\n\n "
"<tr>\n\n <td>\n "
"The API usage for Test Org has reached\n "
"90% within the current subscription period.\n "
"Please consider upgrading your organisation's account limits.\n"
" </td>\n\n\n </tr>\n\n "
"<tr>\n\n <td>Thank you!</td>\n\n "
" </tr>\n\n <tr>\n\n "
"<td>The Flagsmith Team</td>\n\n "
"<table>\n\n <tr>\n\n <td>Hi "
"there,</td>\n\n </tr>\n\n <tr>\n\n "
" <td>\n The API usage for Test "
"Org has reached\n 90% within the current "
"subscription period.\n Please consider "
"upgrading your organisation's account limits.\n "
" \n Please note that once the 100%"
" use has been breached automated charges for your account "
"may apply.\n \n\n </td>\n\n"
"\n </tr>\n\n <tr>\n\n <td>"
"Thank you!</td>\n\n </tr>\n\n <tr>\n\n "
" <td>The Flagsmith Team</td>\n\n "
"</tr>\n\n</table>\n"
)

Expand Down Expand Up @@ -387,6 +392,7 @@ def test_handle_api_usage_notifications_above_100(
# Given
now = timezone.now()
organisation.subscription.plan = SCALE_UP
organisation.subscription.subscription_id = "fancy_id"
organisation.subscription.save()
OrganisationSubscriptionInformationCache.objects.create(
organisation=organisation,
Expand Down Expand Up @@ -421,29 +427,27 @@ def test_handle_api_usage_notifications_above_100(
email = mailoutbox[0]
assert email.subject == "Flagsmith API use has reached 100%"
assert email.body == (
"Hi there,\n\nThe API usage for Test Org has breached "
"100% within the current subscription period. Please "
"upgrade your organisation's account to ensure "
"continued service.\n\nThank you!\n\n"
"The Flagsmith Team\n"
"Hi there,\n\nThe API usage for Test Org has breached 100% "
"within the current subscription period.\n\n\nPlease note "
"that automated charges for your account may apply.\n\n\n"
"Thank you!\n\nThe Flagsmith Team\n"
)

assert len(email.alternatives) == 1
assert len(email.alternatives[0]) == 2
assert email.alternatives[0][1] == "text/html"

assert email.alternatives[0][0] == (
"<table>\n\n <tr>\n\n <td>Hi "
"there,</td>\n\n </tr>\n\n <tr>\n\n "
" <td>\n The API usage for Test Org "
"has breached\n 100% within the "
"current subscription period.\n "
"Please upgrade your organisation's account to ensure "
"continued service.\n </td>\n\n\n "
" </tr>\n\n <tr>\n\n <td>"
"Thank you!</td>\n\n </tr>\n\n <tr>\n\n"
" <td>The Flagsmith Team</td>\n\n "
"</tr>\n\n</table>\n"
"<table>\n\n <tr>\n\n <td>Hi there,"
"</td>\n\n </tr>\n\n <tr>\n\n <td>"
"\n The API usage for Test Org has breached"
"\n 100% within the current subscription period."
"\n \n Please note that "
"automated charges for your account may apply.\n "
"\n </td>\n\n\n </tr>\n\n <tr>"
"\n\n <td>Thank you!</td>\n\n </tr>"
"\n\n <tr>\n\n <td>The Flagsmith "
"Team</td>\n\n </tr>\n\n</table>\n"
)

assert email.from_email == "[email protected]"
Expand Down Expand Up @@ -482,7 +486,8 @@ def test_handle_api_usage_notifications_for_free_accounts(
mailoutbox: list[EmailMultiAlternatives],
) -> None:
# Given
assert organisation.subscription.is_free_plan
assert organisation.is_paid is False
assert organisation.subscription.is_free_plan is True
assert organisation.subscription.max_api_calls == MAX_API_CALLS_IN_FREE_PLAN

mock_api_usage = mocker.patch(
Expand Down Expand Up @@ -510,28 +515,31 @@ def test_handle_api_usage_notifications_for_free_accounts(
assert email.subject == "Flagsmith API use has reached 100%"
assert email.body == (
"Hi there,\n\nThe API usage for Test Org has breached "
"100% within the current subscription period. Please "
"upgrade your organisation's account to ensure "
"continued service.\n\nThank you!\n\n"
"The Flagsmith Team\n"
"100% within the current subscription period.\n\n\nPlease "
"note that the serving of feature flags and admin access "
"may be disabled after a grace period, so please upgrade "
"your organisation's account to ensure continued service."
"\n\n\nThank you!\n\nThe Flagsmith Team\n"
)

assert len(email.alternatives) == 1
assert len(email.alternatives[0]) == 2
assert email.alternatives[0][1] == "text/html"

assert email.alternatives[0][0] == (
"<table>\n\n <tr>\n\n <td>Hi "
"there,</td>\n\n </tr>\n\n <tr>\n\n "
" <td>\n The API usage for Test Org "
"has breached\n 100% within the "
"current subscription period.\n "
"Please upgrade your organisation's account to ensure "
"continued service.\n </td>\n\n\n "
" </tr>\n\n <tr>\n\n <td>"
"Thank you!</td>\n\n </tr>\n\n <tr>\n\n"
" <td>The Flagsmith Team</td>\n\n "
"</tr>\n\n</table>\n"
"<table>\n\n <tr>\n\n <td>Hi there,"
"</td>\n\n </tr>\n\n <tr>\n\n "
" <td>\n The API usage for Test Org has"
" breached\n 100% within the current "
"subscription period.\n \n "
" Please note that the serving of feature flags and "
"admin access may be disabled after a grace period, so "
"please upgrade your organisation's account to ensure "
"continued service.\n \n "
"</td>\n\n\n </tr>\n\n <tr>\n\n "
" <td>Thank you!</td>\n\n </tr>\n\n "
"<tr>\n\n <td>The Flagsmith Team</td>"
"\n\n </tr>\n\n</table>\n"
)

assert email.from_email == "[email protected]"
Expand Down
Loading