mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-04-04 01:21:19 -04:00
@@ -311,6 +311,26 @@ def init_app(application):
|
||||
def _nav_selected():
|
||||
return navigation
|
||||
|
||||
@application.context_processor
|
||||
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():
|
||||
g.start = monotonic()
|
||||
|
||||
@@ -47,6 +47,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
|
||||
|
||||
@@ -80,6 +80,9 @@ def get_example_csv_rows(template, use_example_as_example=True, submitted_fields
|
||||
@main.route("/services/<uuid:service_id>/send/<uuid:template_id>/csv", methods=['GET', 'POST'])
|
||||
@user_has_permissions('send_messages', restrict_admin_usage=True)
|
||||
def send_messages(service_id, template_id):
|
||||
notification_count = service_api_client.get_notification_count(service_id)
|
||||
remaining_messages = current_service.message_limit - notification_count
|
||||
|
||||
db_template = current_service.get_template_with_user_permission_or_403(template_id, current_user)
|
||||
|
||||
email_reply_to = None
|
||||
@@ -154,7 +157,8 @@ def send_messages(service_id, template_id):
|
||||
column_headings=list(ascii_uppercase[:len(column_headings)]),
|
||||
example=[column_headings, get_example_csv_rows(template)],
|
||||
form=form,
|
||||
allowed_file_extensions=Spreadsheet.ALLOWED_FILE_EXTENSIONS
|
||||
allowed_file_extensions=Spreadsheet.ALLOWED_FILE_EXTENSIONS,
|
||||
remaining_messages=remaining_messages
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -527,10 +530,15 @@ class ServiceAPIClient(NotifyAdminAPIClient):
|
||||
|
||||
def get_notification_count(self, service_id):
|
||||
# if cache is not set, or not enabled, return 0
|
||||
|
||||
count = redis_client.get(daily_limit_cache_key(service_id)) or 0
|
||||
|
||||
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,5 +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 class="govuk-body">Messages Left / Daily Limit</p>
|
||||
<ul>
|
||||
<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 %}
|
||||
|
||||
@@ -93,5 +93,8 @@
|
||||
Only showing the first {{ count_of_displayed_recipients }} rows
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
<div>
|
||||
<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 %}
|
||||
|
||||
@@ -56,4 +56,9 @@
|
||||
<h2 class="heading-medium">Your file will populate this template ({{ template.name }})</h2>
|
||||
{{ template|string }}
|
||||
|
||||
<div>
|
||||
<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 %}
|
||||
|
||||
@@ -325,7 +325,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 Switch service '
|
||||
'Test Service Switch service '
|
||||
''
|
||||
'Dashboard '
|
||||
'Send messages '
|
||||
|
||||
@@ -1751,7 +1751,7 @@ def test_upload_csvfile_with_valid_phone_shows_all_numbers(
|
||||
assert '202 867 0750' not in page.text
|
||||
assert 'Only showing the first 50 rows' in page.text
|
||||
|
||||
mock_get_notification_count.assert_called_once_with(service_one['id'])
|
||||
mock_get_notification_count.assert_called_with(service_id=service_one['id'])
|
||||
|
||||
|
||||
@pytest.mark.parametrize('international_sms_permission, should_allow_international', [
|
||||
|
||||
Reference in New Issue
Block a user