mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-03 13:18:57 -04:00
Added global remaining daily messages across services to ui
This commit is contained in:
@@ -312,9 +312,24 @@ def init_app(application):
|
||||
return navigation
|
||||
|
||||
@application.context_processor
|
||||
def _attach_current_remaining_messages():
|
||||
request
|
||||
return {'side_nav_remaining_messages': current_service.message_limit - service_api_client.get_notification_count(service_id=current_service.id)}
|
||||
def _attach_current_daily_remaining_messages_per_service():
|
||||
remaining_messages = 0
|
||||
|
||||
if hasattr(current_service, 'message_limit'):
|
||||
remaining_messages = current_service.message_limit - service_api_client.get_notification_count(
|
||||
service_id=current_service.id)
|
||||
|
||||
return {'daily_remaining_messages': remaining_messages}
|
||||
|
||||
@application.context_processor
|
||||
def _attach_current_global_daily_messages():
|
||||
remaining_global_messages = 0
|
||||
|
||||
if current_app:
|
||||
global_limit = current_app.config['GLOBAL_SERVICE_MESSAGE_LIMIT']
|
||||
global_messages_count = service_api_client.get_global_notification_count()
|
||||
remaining_global_messages = global_limit - global_messages_count
|
||||
return {'daily_global_messages_remaining': remaining_global_messages}
|
||||
|
||||
@application.before_request
|
||||
def record_start_time():
|
||||
@@ -400,9 +415,6 @@ def load_organisation_before_request():
|
||||
raise
|
||||
|
||||
|
||||
def load_current_daily_messages_per_service():
|
||||
service = request.args.get('service')
|
||||
|
||||
def save_service_or_org_after_request(response):
|
||||
# Only save the current session if the request is 200
|
||||
service_id = request.view_args.get('service_id', None) if request.view_args else None
|
||||
|
||||
@@ -45,6 +45,8 @@ class Config(object):
|
||||
|
||||
DEFAULT_SERVICE_LIMIT = 50
|
||||
|
||||
GLOBAL_SERVICE_MESSAGE_LIMIT = 5000
|
||||
|
||||
EMAIL_EXPIRY_SECONDS = 3600 # 1 hour
|
||||
INVITATION_EXPIRY_SECONDS = 3600 * 24 * 2 # 2 days - also set on api
|
||||
EMAIL_2FA_EXPIRY_SECONDS = 1800 # 30 Minutes
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
from datetime import datetime
|
||||
|
||||
from notifications_utils.clients.redis import daily_limit_cache_key
|
||||
from notifications_utils.clients.redis import (
|
||||
daily_limit_cache_key,
|
||||
daily_total_cache_key,
|
||||
)
|
||||
|
||||
from app.extensions import redis_client
|
||||
from app.notify_client import NotifyAdminAPIClient, _attach_current_user, cache
|
||||
@@ -532,5 +535,12 @@ class ServiceAPIClient(NotifyAdminAPIClient):
|
||||
|
||||
return int(count)
|
||||
|
||||
def get_global_notification_count(self):
|
||||
# if cache is not set, or not enabled, return 0
|
||||
|
||||
count = redis_client.get(daily_total_cache_key()) or 0
|
||||
|
||||
return int(count)
|
||||
|
||||
|
||||
service_api_client = ServiceAPIClient()
|
||||
|
||||
@@ -26,11 +26,15 @@
|
||||
<li><a class="govuk-link govuk-link--no-visited-state{{ main_navigation.is_selected('team-members') }}" href="{{ url_for('.manage_users', service_id=current_service.id) }}">Team members</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</nav>
|
||||
</nav><br>
|
||||
<div>
|
||||
<p>Messages Left / Daily Limit</p>
|
||||
<p class="govuk-body">Messages Left / Daily Limit</p>
|
||||
<ul>
|
||||
<li>{{ side_nav_remaining_messages }} / {{ current_service.message_limit }}</li>
|
||||
<li>{{ daily_remaining_messages }} / {{ current_service.message_limit }}</li>
|
||||
</ul><br>
|
||||
<p class="govuk-body">Messages Left Across Services</p>
|
||||
<ul>
|
||||
<li>{{ daily_global_messages_remaining }}</li>
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
{% macro navigation_service_name(service) %}
|
||||
<div class="navigation-service-name govuk-!-font-weight-bold">
|
||||
{{ service.name }}
|
||||
<p class="govuk-body"> Daily Message Limit: {{ service.message_limit }}</p>
|
||||
{% if not service.active %}
|
||||
<span class="navigation-service-type navigation-service-type--suspended">Suspended</span>
|
||||
{% endif %}
|
||||
|
||||
@@ -94,9 +94,7 @@
|
||||
</p>
|
||||
{% endif %}
|
||||
<div>
|
||||
<h2 class="heading-medium">Daily messages remaining: </h2>
|
||||
<p class="govuk-body">{{ remaining_messages }}</p>
|
||||
<h2 class="heading-medium">Remaining messages if sent: </h2>
|
||||
<p class="govuk-body">{{ remaining_messages - count_of_recipients }}</p>
|
||||
<h2 class="heading-medium">Messages remaining today / Messages left if list is sent </h2>
|
||||
<p class="govuk-body">{{ remaining_messages }} / {{ remaining_messages - count_of_recipients }}</p>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@@ -57,10 +57,8 @@
|
||||
{{ template|string }}
|
||||
|
||||
<div>
|
||||
<h2 class="heading-medium">Daily message limit for this service:</h2>
|
||||
<p class="govuk-body">{{ current_service.name }} - {{ current_service.message_limit }}</p>
|
||||
<h2 class="heading-medium">Daily remaining messages for this service:</h2>
|
||||
<p class="govuk-body">{{ side_nav_remaining_messages }}</p>
|
||||
<h2 class="heading-medium">Messages Remaining Today / Daily Message Limit</h2>
|
||||
<p class="govuk-body"> {{ daily_remaining_messages }} / {{ current_service.message_limit }}</p>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -322,7 +322,7 @@ def test_should_show_back_to_service_if_user_belongs_to_service(
|
||||
):
|
||||
mock_get_service.return_value = service_one
|
||||
expected_page_text = (
|
||||
'Test Service Daily Message Limit: 50 Switch service '
|
||||
'Test Service Switch service '
|
||||
''
|
||||
'Dashboard '
|
||||
'Send messages '
|
||||
|
||||
Reference in New Issue
Block a user