diff --git a/app/dao/notifications_dao.py b/app/dao/notifications_dao.py index 155616801..efd13426e 100644 --- a/app/dao/notifications_dao.py +++ b/app/dao/notifications_dao.py @@ -83,6 +83,7 @@ def dao_get_template_usage(service_id, limit_days=None): Template.id.label('template_id'), Template.name, Template.template_type, + Template.hidden, notifications_aggregate_query.c.count ).join( notifications_aggregate_query, diff --git a/app/dao/services_dao.py b/app/dao/services_dao.py index 57d5aa866..6ad83d214 100644 --- a/app/dao/services_dao.py +++ b/app/dao/services_dao.py @@ -522,6 +522,7 @@ def dao_fetch_monthly_historical_usage_by_template_for_service(service_id, year) stat.month = result.month stat.year = result.year stat.count = result.count + stat.hidden = result.hidden stats.append(stat) month = get_london_month_from_utc_column(Notification.created_at) @@ -533,6 +534,7 @@ def dao_fetch_monthly_historical_usage_by_template_for_service(service_id, year) if fy_start < datetime.now() < fy_end: today_results = db.session.query( Notification.template_id, + Template.hidden, Template.name, Template.template_type, extract('month', month).label('month'), @@ -547,6 +549,7 @@ def dao_fetch_monthly_historical_usage_by_template_for_service(service_id, year) Notification.key_type != KEY_TYPE_TEST ).group_by( Notification.template_id, + Template.hidden, Template.name, Template.template_type, month, @@ -571,6 +574,7 @@ def dao_fetch_monthly_historical_usage_by_template_for_service(service_id, year) new_stat.month = int(today_result.month) new_stat.year = int(today_result.year) new_stat.count = today_result.count + new_stat.hidden = today_result.hidden stats.append(new_stat) return stats diff --git a/app/dao/stats_template_usage_by_month_dao.py b/app/dao/stats_template_usage_by_month_dao.py index 29aba1cdc..49e95cfe1 100644 --- a/app/dao/stats_template_usage_by_month_dao.py +++ b/app/dao/stats_template_usage_by_month_dao.py @@ -35,6 +35,7 @@ def insert_or_update_stats_for_template(template_id, month, year, count): def dao_get_template_usage_stats_by_service(service_id, year): return db.session.query( StatsTemplateUsageByMonth.template_id, + Template.hidden, Template.name, Template.template_type, StatsTemplateUsageByMonth.month, diff --git a/app/dao/templates_dao.py b/app/dao/templates_dao.py index fb7dc7602..c664c4346 100644 --- a/app/dao/templates_dao.py +++ b/app/dao/templates_dao.py @@ -135,6 +135,7 @@ def dao_get_templates_for_cache(cache): query = db.session.query(Template.id.label('template_id'), Template.template_type, Template.name, + Template.hidden, cache_subq.c.count.label('count') ).join(cache_subq, Template.id == cache_subq.c.template_id diff --git a/app/service/rest.py b/app/service/rest.py index 99f03cee9..32305e301 100644 --- a/app/service/rest.py +++ b/app/service/rest.py @@ -536,7 +536,8 @@ def get_monthly_template_usage(service_id): 'type': i.template_type, 'month': i.month, 'year': i.year, - 'count': i.count + 'count': i.count, + 'hidden': i.hidden } ) diff --git a/app/template_statistics/rest.py b/app/template_statistics/rest.py index 86548dc00..f71a40492 100644 --- a/app/template_statistics/rest.py +++ b/app/template_statistics/rest.py @@ -47,7 +47,8 @@ def get_template_statistics_for_service_by_day(service_id): 'count': data.count, 'template_id': str(data.template_id), 'template_name': data.name, - 'template_type': data.template_type + 'template_type': data.template_type, + 'template_hidden': data.hidden } return jsonify(data=[serialize(row) for row in stats]) diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index 92a74c233..86f7641de 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -1831,7 +1831,7 @@ def test_get_template_usage_by_month_returns_two_templates( sample_service ): - template_one = create_template(sample_service) + template_one = create_template(sample_service, hidden=True) # add a historical notification for template not1 = create_notification_history( @@ -1889,6 +1889,7 @@ def test_get_template_usage_by_month_returns_two_templates( assert resp_json[0]["month"] == 4 assert resp_json[0]["year"] == 2017 assert resp_json[0]["count"] == 1 + assert resp_json[0]["hidden"] is True assert resp_json[1]["template_id"] == str(sample_template.id) assert resp_json[1]["name"] == sample_template.name @@ -1896,6 +1897,7 @@ def test_get_template_usage_by_month_returns_two_templates( assert resp_json[1]["month"] == 4 assert resp_json[1]["year"] == 2017 assert resp_json[1]["count"] == 3 + assert resp_json[1]["hidden"] is False assert resp_json[2]["template_id"] == str(sample_template.id) assert resp_json[2]["name"] == sample_template.name @@ -1903,6 +1905,7 @@ def test_get_template_usage_by_month_returns_two_templates( assert resp_json[2]["month"] == 11 assert resp_json[2]["year"] == 2017 assert resp_json[2]["count"] == 1 + assert resp_json[2]["hidden"] is False def test_search_for_notification_by_to_field(client, notify_db, notify_db_session):