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 org ID and link to usage page in email notifications #5178

Merged
merged 3 commits into from
Mar 4, 2025
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
1 change: 1 addition & 0 deletions api/organisations/task_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def _send_api_usage_notification(
"organisation": organisation,
"matched_threshold": matched_threshold,
"grace_period": not hasattr(organisation, "breached_grace_period"),
"url": get_current_site_url(),
}

send_mail(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@
<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="{{url}}">{{url}}</a>.
This is a system generated notification related to your Flagsmith API Usage. As per previous warnings, we have had to block your organisation {{ organisation.name }} (ID: {{ organisation.id }}){% if grace_period %} after the 7 day grace period{% endif %}. Flags are not currently being served for your organisation, 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>


</tr>

<tr>
<td>
{% with usage_url="{{ url }}/organisation/{{ organisation.id | urlencode }}/usage" %}
You can view the details of your organisation's API usage at <a href="{{ usage_url }}">{{ usage_url }}</a>.
{% endwith %}
</td>
</tr>

<tr>

<td>Thank you!</td>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
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 {{ url }}.
This is a system generated notification related to your Flagsmith API usage. As per previous warnings, we have had to block your organisation {{ organisation.name }} (ID: {{ organisation.id }}){% if grace_period %} after the 7 day grace period{% endif %}. Flags are not currently being served for your organisation, and it will continue to be blocked until your billing period resets or you upgrade your account. You can upgrade your account at {{ url }}.

{% with usage_url="{{ url }}/organisation/{{ organisation.id | urlencode }}/usage" %}
You can view the details of your organisation's API usage at <a href="{{ usage_url }}">{{ usage_url }}</a>.
{% endwith %}

Thank you!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@
<tr>

<td>
This is a system generated notification related to your Flagsmith API Usage. Your company,
{{ organisation.name }}, has reached {{ matched_threshold }}% of your API usage within the
This is a system generated notification related to your Flagsmith API usage. Your organisation,
{{ organisation.name }} (ID: {{ organisation.id }}), has reached {{ matched_threshold }}% of your API usage within the
current subscription period.

{% if organisation.is_paid %}
If this is expected, no action is required. If you are expecting to go over, you can upgrade your organisations account
If this is expected, no action is required. If you are expecting to go over, you can upgrade your organisation's account
limits by reaching out to [email protected]. We will automatically charge for overages at the end of the pay period. For more information check the <a href="https://www.flagsmith.com/terms-of-service">Terms of Service</a>.
{% else %}
Please note that once 100% use has been breached, the serving of feature flags and admin access may
be disabled{% if grace_period %} after a 7-day grace period{% endif %}. Please reach out to
[email protected] in order to upgrade your account.
{% endif %}

{% with usage_url="{{ url }}/organisation/{{ organisation.id | urlencode }}/usage" %}
You can view the details of your organisation's API usage at <a href="{{ usage_url }}">{{ usage_url }}</a>.
{% endwith %}
</td>


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

This is a system generated notification related to your Flagsmith API Usage. Your company, {{ organisation.name }}, has
reached {{ matched_threshold }}% of your API usage within the current subscription period.
This is a system generated notification related to your Flagsmith API usage. Your organisation, {{ organisation.name }} (ID: {{ organisation.id }}),
has reached {{ matched_threshold }}% of its API usage within the current subscription period.

{% if organisation.is_paid %}
If this is expected, no action is required. If you are expecting to go over, you can upgrade your organisations account
limits by reaching out to [email protected]. We will automatically charge for overages at the end of the pay period. For more information check the Terms of Service at https://www.flagsmith.com/terms-of-service.
If this is expected, no action is required. If you are expecting to go over, you can upgrade your organisation's account
limits by reaching out to [email protected]. We will automatically charge for overages at the end of the pay period. For more information, check the Terms of Service at https://www.flagsmith.com/terms-of-service.
{% else %}
Please note that once 100% use has been breached, the serving of feature flags and admin access may be disabled{% if grace_period %}
after a 7-day grace period{% endif %}. Please reach out to [email protected] in order to upgrade your account.
{% endif %}

{% with usage_url="{{ url }}/organisation/{{ organisation.id | urlencode }}/usage" %}
You can view the details of your organisation's API usage at {{ url }}/organisation/{{ organisation.id }}/usage.
{% endwith %}

Thank you!

The Flagsmith Team
The Flagsmith team
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
<tr>

<td>
This is a system generated notification related to your Flagsmith API Usage. Your company,
{{ organisation.name }}, has reached {{ matched_threshold }}% of your API usage within the
This is a system generated notification related to your Flagsmith API usage. Your organisation,
{{ organisation.name }} (ID: {{ organisation.id }}), has reached {{ matched_threshold }}% of your API usage within the
current subscription period.

{% if organisation.is_paid %}
We will charge for overages at the end of the pay period. Please see the pricing page for more information or check the <a href="https://www.flagsmith.com/terms-of-service">Terms of Service</a>.
You can reach out to [email protected] if youd like to take advantage of better contracted rates.
You can reach out to [email protected] if you'd like to take advantage of better contracted rates.
{% else %}
Please note that the serving of feature flags and admin access will be disabled{% if grace_period %} after a 7 day grace
period{% endif %} until the next subscription period. If youd like to continue service you can upgrade your
organisations account (see pricing page).
period{% endif %} until the next subscription period. If you'd like to continue service you can upgrade your
organisation's account (see pricing page).
{% endif %}

{% with usage_url="{{ url }}/organisation/{{ organisation.id | urlencode }}/usage" %}
You can view the details of your organisation's API usage at <a href="{{ usage_url }}">{{ usage_url }}</a>.
{% endwith %}
</td>


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

This is a system generated notification related to your Flagsmith API Usage. Your company, {{ organisation.name }},
This is a system generated notification related to your Flagsmith API Usage. Your organisation, {{ organisation.name }} (ID: {{ organisation.id }}),
has reached {{ matched_threshold }}% of your API usage within the current subscription period.

{% if organisation.is_paid %}
We will charge for overages at the end of the pay period. Please see the pricing page for more information or check the Terms of Service at https://www.flagsmith.com/terms-of-service.
You can reach out to [email protected] if youd like to take advantage of better contracted rates.
You can reach out to [email protected] if you'd like to take advantage of better contracted rates.
{% else %}
Please note that the serving of feature flags and admin access will be disabled{% if grace_period %} after a 7 day
grace period{% endif %} until the next subscription period. If youd like to continue service you can upgrade your
organisations account (see pricing page).
grace period{% endif %} until the next subscription period. If you'd like to continue service you can upgrade your
organisation's account (see pricing page).
{% endif %}

{% with usage_url="{{ url }}/organisation/{{ organisation.id | urlencode }}/usage" %}
You can view the details of your organisation's API usage at {{ usage_url }}.
{% endwith %}

Thank you!

The Flagsmith Team
26 changes: 22 additions & 4 deletions api/tests/unit/organisations/test_unit_organisations_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,11 @@ def test_handle_api_usage_notifications_below_100(
assert email.subject == "Flagsmith API use has reached 90%"
assert email.body == render_to_string(
"organisations/api_usage_notification.txt",
context={"organisation": organisation, "matched_threshold": 90},
context={
"organisation": organisation,
"matched_threshold": 90,
"url": get_current_site_url(),
},
)

assert len(email.alternatives) == 1
Expand All @@ -458,7 +462,11 @@ def test_handle_api_usage_notifications_below_100(

assert email.alternatives[0][0] == render_to_string(
"organisations/api_usage_notification.html",
context={"organisation": organisation, "matched_threshold": 90},
context={
"organisation": organisation,
"matched_threshold": 90,
"url": get_current_site_url(),
},
)

assert email.from_email == "[email protected]"
Expand Down Expand Up @@ -590,7 +598,11 @@ def test_handle_api_usage_notifications_above_100(
assert email.subject == "Flagsmith API use has reached 100%"
assert email.body == render_to_string(
"organisations/api_usage_notification_limit.txt",
context={"organisation": organisation, "matched_threshold": 100},
context={
"organisation": organisation,
"matched_threshold": 100,
"url": get_current_site_url(),
},
)

assert len(email.alternatives) == 1
Expand All @@ -599,7 +611,11 @@ def test_handle_api_usage_notifications_above_100(

assert email.alternatives[0][0] == render_to_string(
"organisations/api_usage_notification_limit.html",
context={"organisation": organisation, "matched_threshold": 100},
context={
"organisation": organisation,
"matched_threshold": 100,
"url": get_current_site_url(),
},
)

assert email.from_email == "[email protected]"
Expand Down Expand Up @@ -727,6 +743,7 @@ def test_handle_api_usage_notifications_for_free_accounts(
"organisation": organisation,
"matched_threshold": 100,
"grace_period": True,
"url": get_current_site_url(),
},
)

Expand All @@ -740,6 +757,7 @@ def test_handle_api_usage_notifications_for_free_accounts(
"organisation": organisation,
"matched_threshold": 100,
"grace_period": True,
"url": get_current_site_url(),
},
)

Expand Down
Loading