diff --git a/app/main/forms.py b/app/main/forms.py index afec80f9f..90a4409fc 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -50,6 +50,7 @@ from app.main.validators import ( CommonlyUsedPassword, CsvFileValidator, DoesNotStartWithDoubleZero, + FieldCannotContainComma, LettersNumbersSingleQuotesFullStopsAndUnderscoresOnly, MustContainAlphanumericCharacters, NoCommasInPlaceHolders, @@ -1650,7 +1651,11 @@ def get_placeholder_form_instance( ) # TODO: replace with us_mobile_number else: field = GovukTextInputField( - placeholder_name, validators=[DataRequired(message="Cannot be empty")] + placeholder_name, + validators=[ + DataRequired(message="Cannot be empty"), + FieldCannotContainComma(), + ], ) PlaceholderForm.placeholder_value = field diff --git a/app/main/validators.py b/app/main/validators.py index 4dd04017b..1dfc97c48 100644 --- a/app/main/validators.py +++ b/app/main/validators.py @@ -161,6 +161,15 @@ class DoesNotStartWithDoubleZero: raise ValidationError(self.message) +class FieldCannotContainComma: + def __init__(self, message="Cannot contain a comma"): + self.message = message + + def __call__(self, form, field): + if field.data and "," in field.data: + raise ValidationError(self.message) + + class MustContainAlphanumericCharacters: regex = re.compile(r".*[a-zA-Z0-9].*[a-zA-Z0-9].*") diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 4c70b85fd..4966c0300 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -1,5 +1,4 @@ import calendar -from collections import defaultdict from datetime import datetime from functools import partial from itertools import groupby @@ -13,7 +12,6 @@ from app import ( billing_api_client, current_service, job_api_client, - notification_api_client, service_api_client, socketio, template_statistics_client, @@ -83,18 +81,9 @@ def service_dashboard(service_id): return redirect(url_for("main.choose_template", service_id=service_id)) job_response = job_api_client.get_jobs(service_id)["data"] - notifications_response = notification_api_client.get_notifications_for_service( - service_id - )["notifications"] service_data_retention_days = 7 - aggregate_notifications_by_job = defaultdict(list) - for notification in notifications_response: - job_id = notification.get("job", {}).get("id", None) - if job_id: - aggregate_notifications_by_job[job_id].append(notification) - - job_and_notifications = [ + jobs = [ { "job_id": job["id"], "time_left": get_time_left(job["created_at"]), @@ -105,20 +94,20 @@ def service_dashboard(service_id): ".view_job", service_id=current_service.id, job_id=job["id"] ), "created_at": job["created_at"], - "processing_finished": job["processing_finished"], - "processing_started": job["processing_started"], + "processing_finished": job.get("processing_finished"), + "processing_started": job.get("processing_started"), "notification_count": job["notification_count"], "created_by": job["created_by"], - "notifications": aggregate_notifications_by_job.get(job["id"], []), + "template_name": job["template_name"], + "original_file_name": job["original_file_name"], } for job in job_response - if aggregate_notifications_by_job.get(job["id"], []) ] return render_template( "views/dashboard/dashboard.html", updates_url=url_for(".service_dashboard_updates", service_id=service_id), partials=get_dashboard_partials(service_id), - job_and_notifications=job_and_notifications, + jobs=jobs, service_data_retention_days=service_data_retention_days, ) diff --git a/app/templates/views/dashboard/dashboard.html b/app/templates/views/dashboard/dashboard.html index aba7d2ac6..e8e5ec633 100644 --- a/app/templates/views/dashboard/dashboard.html +++ b/app/templates/views/dashboard/dashboard.html @@ -55,31 +55,30 @@ - {% if job_and_notifications %} - {% for job in job_and_notifications[:5] %} - {% if job.job_id and job.notifications %} + {% if jobs %} + {% for job in jobs[:5] %} {% set notification = job.notifications[0] %} - {{ notification.job.original_file_name[:12] if notification.job.original_file_name else 'Manually entered number'}} + {{ job.original_file_name[:12] if job.original_file_name else 'Manually entered number'}}
View Batch - {{ notification.template.name }} + {{ job.template_name }} {{ (job.processing_finished if job.processing_finished else job.processing_started if job.processing_started else job.created_at)|format_datetime_table }} - {{ notification.created_by.name }} + {{ job.created_by.name }} {{ job.notification_count}} - {% if notification and job.time_left != "Data no longer available" %} + {% if job.time_left != "Data no longer available" %} Download {{ job.time_left }} {% elif job %} @@ -87,7 +86,6 @@ {% endif %} - {% endif %} {% endfor %} {% else %} diff --git a/deploy-config/production.yml b/deploy-config/production.yml index c114a65bf..b99c4dd54 100644 --- a/deploy-config/production.yml +++ b/deploy-config/production.yml @@ -1,6 +1,6 @@ env: production instances: 2 -memory: 4G +memory: 1.5G public_admin_route: beta.notify.gov cloud_dot_gov_route: notify.app.cloud.gov redis_enabled: 1 diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index d0d48bffc..bccfa27b4 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -305,10 +305,6 @@ def test_inbound_messages_shows_count_of_messages_when_there_are_messages( mock_get_inbound_sms_summary, ): service_one["permissions"] = ["inbound_sms"] - mocker.patch( - "app.notification_api_client.get_notifications_for_service", - return_value=FAKE_ONE_OFF_NOTIFICATION, - ) page = client_request.get( "main.service_dashboard", service_id=SERVICE_ONE_ID, @@ -337,10 +333,6 @@ def test_inbound_messages_shows_count_of_messages_when_there_are_no_messages( mock_get_inbound_sms_summary_with_no_messages, ): service_one["permissions"] = ["inbound_sms"] - mocker.patch( - "app.notification_api_client.get_notifications_for_service", - return_value=FAKE_ONE_OFF_NOTIFICATION, - ) page = client_request.get( "main.service_dashboard", service_id=SERVICE_ONE_ID, @@ -839,10 +831,6 @@ def test_should_not_show_upcoming_jobs_on_dashboard_if_count_is_0( }, ) mocker.patch("app.job_api_client.get_jobs", return_value=MOCK_JOBS) - mocker.patch( - "app.notification_api_client.get_notifications_for_service", - return_value=FAKE_ONE_OFF_NOTIFICATION, - ) page = client_request.get( "main.service_dashboard", service_id=SERVICE_ONE_ID, @@ -919,10 +907,6 @@ def test_correct_font_size_for_big_numbers( mocker.patch("app.main.views.dashboard.get_dashboard_totals", return_value=totals) mocker.patch("app.job_api_client.get_jobs", return_value=MOCK_JOBS) - mocker.patch( - "app.notification_api_client.get_notifications_for_service", - return_value=FAKE_ONE_OFF_NOTIFICATION, - ) page = client_request.get( "main.service_dashboard", service_id=service_one["id"], @@ -952,10 +936,6 @@ def test_should_not_show_jobs_on_dashboard_for_users_with_uploads_page( mock_get_free_sms_fragment_limit, mock_get_inbound_sms_summary, ): - mocker.patch( - "app.notification_api_client.get_notifications_for_service", - return_value=FAKE_ONE_OFF_NOTIFICATION, - ) page = client_request.get( "main.service_dashboard", service_id=SERVICE_ONE_ID,