diff --git a/app/job/rest.py b/app/job/rest.py index 8f6512404..1a1f512f3 100644 --- a/app/job/rest.py +++ b/app/job/rest.py @@ -18,7 +18,12 @@ from app.dao.services_dao import ( from app.dao.templates_dao import (dao_get_template_by_id) from app.dao.notifications_dao import get_notifications_for_job -from app.schemas import job_schema, unarchived_template_schema, notifications_filter_schema, notification_status_schema +from app.schemas import ( + job_schema, + unarchived_template_schema, + notifications_filter_schema, + notification_schema +) from app.celery.tasks import process_job @@ -57,7 +62,7 @@ def get_all_notifications_for_service_job(service_id, job_id): kwargs['service_id'] = service_id kwargs['job_id'] = job_id return jsonify( - notifications=notification_status_schema.dump(pagination.items, many=True).data, + notifications=notification_schema.dump(pagination.items, many=True).data, page_size=page_size, total=pagination.total, links=pagination_links( diff --git a/app/notifications/rest.py b/app/notifications/rest.py index bffc59b98..6ec85e463 100644 --- a/app/notifications/rest.py +++ b/app/notifications/rest.py @@ -26,7 +26,7 @@ from app.notifications.process_client_response import ( from app.schemas import ( email_notification_schema, sms_template_notification_schema, - notification_status_schema, + notification_with_template_schema, notifications_filter_schema, notifications_statistics_schema, day_schema, @@ -175,7 +175,7 @@ def get_notifications(notification_id): notification = notifications_dao.get_notification(str(api_user.service_id), notification_id, key_type=api_user.key_type) - return jsonify(data={"notification": notification_status_schema.dump(notification).data}), 200 + return jsonify(data={"notification": notification_with_template_schema.dump(notification).data}), 200 @notifications.route('/notifications', methods=['GET']) @@ -193,7 +193,7 @@ def get_all_notifications(): limit_days=limit_days, key_type=api_user.key_type) return jsonify( - notifications=notification_status_schema.dump(pagination.items, many=True).data, + notifications=notification_with_template_schema.dump(pagination.items, many=True).data, page_size=page_size, total=pagination.total, links=pagination_links( diff --git a/app/schemas.py b/app/schemas.py index 7857a728e..baeceac3d 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -144,7 +144,7 @@ class NotificationModelSchema(BaseSchema): class Meta: model = models.Notification strict = True - exclude = ("_personalisation",) + exclude = ('_personalisation', 'job', 'service', 'template', 'api_key', '') class BaseTemplateSchema(BaseSchema): @@ -280,7 +280,7 @@ class SmsAdminNotificationSchema(SmsNotificationSchema): content = fields.Str(required=True) -class NotificationStatusSchema(BaseSchema): +class NotificationWithTemplateSchema(BaseSchema): template = fields.Nested(TemplateSchema, only=["id", "name", "template_type", "content", "subject"], dump_only=True) job = fields.Nested(JobSchema, only=["id", "original_file_name"], dump_only=True) @@ -516,8 +516,9 @@ sms_template_notification_schema = SmsTemplateNotificationSchema() job_sms_template_notification_schema = JobSmsTemplateNotificationSchema() email_notification_schema = EmailNotificationSchema() job_email_template_notification_schema = JobEmailTemplateNotificationSchema() -notification_status_schema = NotificationStatusSchema() -notification_status_schema_load_json = NotificationStatusSchema(load_json=True) +notification_schema = NotificationModelSchema() +notification_with_template_schema = NotificationWithTemplateSchema() +notification_with_template_schema_load_json = NotificationWithTemplateSchema(load_json=True) invited_user_schema = InvitedUserSchema() permission_schema = PermissionSchema() email_data_request_schema = EmailDataSchema() diff --git a/app/service/rest.py b/app/service/rest.py index 617ccb84d..b6b3e461b 100644 --- a/app/service/rest.py +++ b/app/service/rest.py @@ -33,7 +33,7 @@ from app.schemas import ( user_schema, from_to_date_schema, permission_schema, - notification_status_schema, + notification_with_template_schema, notifications_filter_schema, detailed_service_schema ) @@ -224,7 +224,7 @@ def get_all_notifications_for_service(service_id): kwargs = request.args.to_dict() kwargs['service_id'] = service_id return jsonify( - notifications=notification_status_schema.dump(pagination.items, many=True).data, + notifications=notification_with_template_schema.dump(pagination.items, many=True).data, page_size=page_size, total=pagination.total, links=pagination_links( diff --git a/app/spec/rest.py b/app/spec/rest.py index 400cb5849..9cd36c381 100644 --- a/app/spec/rest.py +++ b/app/spec/rest.py @@ -10,7 +10,7 @@ api_spec = APISpec( version='0.0.0' ) -api_spec.definition('NotificationStatusSchema', properties={ +api_spec.definition('NotificationWithTemplateSchema', properties={ "content_char_count": { "format": "int32", "type": "integer" @@ -106,14 +106,14 @@ api_spec.definition('NotificationStatusSchema', properties={ }) api_spec.definition('NotificationSchema', properties={ "notification": { - "$ref": "#/definitions/NotificationStatusSchema" + "$ref": "#/definitions/NotificationWithTemplateSchema" } }) api_spec.definition('NotificationsSchema', properties={ "notifications": { "type": "array", "items": { - "$ref": "#/definitions/NotificationStatusSchema" + "$ref": "#/definitions/NotificationWithTemplateSchema" } } }) diff --git a/tests/app/job/test_rest.py b/tests/app/job/test_rest.py index ea65bb447..c7a056f77 100644 --- a/tests/app/job/test_rest.py +++ b/tests/app/job/test_rest.py @@ -296,6 +296,9 @@ def test_get_all_notifications_for_job_in_order_of_job_number(notify_api, assert resp['notifications'][2]['job_row_number'] == notification_3.job_row_number assert response.status_code == 200 + # make sure we're not loading templates + assert 'template' not in resp['notifications'][0] + @pytest.mark.parametrize( "expected_notification_count, status_args",