Skip to content

Commit

Permalink
Merge pull request #33863 from dimagi/cs/SC-3233-cap-active-banners-be
Browse files Browse the repository at this point in the history
Cap active banners to 3 max
  • Loading branch information
Charl1996 committed Dec 13, 2023
2 parents 21af621 + 59aa239 commit ee3d8d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions corehq/apps/domain/templates/domain/admin/manage_alerts.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<h3>
{% trans "Available Alerts" %}
</h3>
<p>
{% trans "You can only have 3 alerts activated at any one time" %}
</p>
<table class="table">
<thead>
<tr>
Expand Down
7 changes: 7 additions & 0 deletions corehq/apps/domain/views/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
from corehq.toggles import NAMESPACE_DOMAIN
from corehq.toggles.models import Toggle

MAX_ACTIVE_ALERTS = 3


class BaseProjectSettingsView(BaseDomainView):
section_name = gettext_lazy("Project Settings")
Expand Down Expand Up @@ -611,6 +613,11 @@ def _load_alert(alert_id, domain):

def _apply_update(request, alert):
command = request.POST.get('command')
domain_alerts = Alert.objects.filter(created_by_domain=request.domain)
if command == "activate" and len(domain_alerts) >= MAX_ACTIVE_ALERTS:
messages.error(request, _("Only 3 active alerts allowed!"))
return

if command in ['activate', 'deactivate']:
_update_alert(alert, command)
messages.success(request, _("Alert updated!"))
Expand Down

0 comments on commit ee3d8d4

Please sign in to comment.