Add template hidden field in response

This commit is contained in:
Ken Tsang
2018-03-05 13:38:41 +00:00
parent ee9b6f1fe0
commit 564504bf97
7 changed files with 15 additions and 3 deletions

View File

@@ -83,6 +83,7 @@ def dao_get_template_usage(service_id, limit_days=None):
Template.id.label('template_id'), Template.id.label('template_id'),
Template.name, Template.name,
Template.template_type, Template.template_type,
Template.hidden,
notifications_aggregate_query.c.count notifications_aggregate_query.c.count
).join( ).join(
notifications_aggregate_query, notifications_aggregate_query,

View File

@@ -522,6 +522,7 @@ def dao_fetch_monthly_historical_usage_by_template_for_service(service_id, year)
stat.month = result.month stat.month = result.month
stat.year = result.year stat.year = result.year
stat.count = result.count stat.count = result.count
stat.hidden = result.hidden
stats.append(stat) stats.append(stat)
month = get_london_month_from_utc_column(Notification.created_at) 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: if fy_start < datetime.now() < fy_end:
today_results = db.session.query( today_results = db.session.query(
Notification.template_id, Notification.template_id,
Template.hidden,
Template.name, Template.name,
Template.template_type, Template.template_type,
extract('month', month).label('month'), 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 Notification.key_type != KEY_TYPE_TEST
).group_by( ).group_by(
Notification.template_id, Notification.template_id,
Template.hidden,
Template.name, Template.name,
Template.template_type, Template.template_type,
month, 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.month = int(today_result.month)
new_stat.year = int(today_result.year) new_stat.year = int(today_result.year)
new_stat.count = today_result.count new_stat.count = today_result.count
new_stat.hidden = today_result.hidden
stats.append(new_stat) stats.append(new_stat)
return stats return stats

View File

@@ -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): def dao_get_template_usage_stats_by_service(service_id, year):
return db.session.query( return db.session.query(
StatsTemplateUsageByMonth.template_id, StatsTemplateUsageByMonth.template_id,
Template.hidden,
Template.name, Template.name,
Template.template_type, Template.template_type,
StatsTemplateUsageByMonth.month, StatsTemplateUsageByMonth.month,

View File

@@ -135,6 +135,7 @@ def dao_get_templates_for_cache(cache):
query = db.session.query(Template.id.label('template_id'), query = db.session.query(Template.id.label('template_id'),
Template.template_type, Template.template_type,
Template.name, Template.name,
Template.hidden,
cache_subq.c.count.label('count') cache_subq.c.count.label('count')
).join(cache_subq, ).join(cache_subq,
Template.id == cache_subq.c.template_id Template.id == cache_subq.c.template_id

View File

@@ -536,7 +536,8 @@ def get_monthly_template_usage(service_id):
'type': i.template_type, 'type': i.template_type,
'month': i.month, 'month': i.month,
'year': i.year, 'year': i.year,
'count': i.count 'count': i.count,
'hidden': i.hidden
} }
) )

View File

@@ -47,7 +47,8 @@ def get_template_statistics_for_service_by_day(service_id):
'count': data.count, 'count': data.count,
'template_id': str(data.template_id), 'template_id': str(data.template_id),
'template_name': data.name, '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]) return jsonify(data=[serialize(row) for row in stats])

View File

@@ -1831,7 +1831,7 @@ def test_get_template_usage_by_month_returns_two_templates(
sample_service sample_service
): ):
template_one = create_template(sample_service) template_one = create_template(sample_service, hidden=True)
# add a historical notification for template # add a historical notification for template
not1 = create_notification_history( 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]["month"] == 4
assert resp_json[0]["year"] == 2017 assert resp_json[0]["year"] == 2017
assert resp_json[0]["count"] == 1 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]["template_id"] == str(sample_template.id)
assert resp_json[1]["name"] == sample_template.name 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]["month"] == 4
assert resp_json[1]["year"] == 2017 assert resp_json[1]["year"] == 2017
assert resp_json[1]["count"] == 3 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]["template_id"] == str(sample_template.id)
assert resp_json[2]["name"] == sample_template.name 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]["month"] == 11
assert resp_json[2]["year"] == 2017 assert resp_json[2]["year"] == 2017
assert resp_json[2]["count"] == 1 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): def test_search_for_notification_by_to_field(client, notify_db, notify_db_session):