mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
Merge branch 'master' into remove-provider_statistics
Conflicts: tests/app/notifications/rest/test_callbacks.py
This commit is contained in:
@@ -21,7 +21,7 @@ from app.models import (
|
||||
NOTIFICATION_CREATED,
|
||||
NOTIFICATION_SENDING,
|
||||
NOTIFICATION_PENDING,
|
||||
NOTIFICATION_TEMPORARY_FAILURE)
|
||||
NOTIFICATION_TEMPORARY_FAILURE, KEY_TYPE_NORMAL, KEY_TYPE_TEST)
|
||||
|
||||
from app.dao.dao_utils import transactional
|
||||
from app.statsd_decorators import statsd
|
||||
@@ -97,7 +97,7 @@ def dao_get_template_usage(service_id, limit_days=None):
|
||||
Template.template_type
|
||||
)
|
||||
|
||||
query_filter = [table.service_id == service_id]
|
||||
query_filter = [table.service_id == service_id, table.key_type != KEY_TYPE_TEST]
|
||||
if limit_days is not None:
|
||||
query_filter.append(table.created_at >= days_ago(limit_days))
|
||||
|
||||
@@ -110,7 +110,9 @@ def dao_get_template_usage(service_id, limit_days=None):
|
||||
|
||||
@statsd(namespace="dao")
|
||||
def dao_get_last_template_usage(template_id):
|
||||
return NotificationHistory.query.filter(NotificationHistory.template_id == template_id) \
|
||||
return NotificationHistory.query.filter(
|
||||
NotificationHistory.template_id == template_id,
|
||||
NotificationHistory.key_type != KEY_TYPE_TEST) \
|
||||
.join(Template) \
|
||||
.order_by(desc(NotificationHistory.created_at)) \
|
||||
.first()
|
||||
@@ -232,17 +234,24 @@ def get_notifications_for_service(service_id,
|
||||
page_size=None,
|
||||
limit_days=None,
|
||||
key_type=None,
|
||||
personalisation=False):
|
||||
personalisation=False,
|
||||
include_jobs=False):
|
||||
if page_size is None:
|
||||
page_size = current_app.config['PAGE_SIZE']
|
||||
|
||||
filters = [Notification.service_id == service_id]
|
||||
|
||||
if limit_days is not None:
|
||||
days_ago = date.today() - timedelta(days=limit_days)
|
||||
filters.append(func.date(Notification.created_at) >= days_ago)
|
||||
|
||||
if not include_jobs or (key_type and key_type != KEY_TYPE_NORMAL):
|
||||
filters.append(Notification.job_id.is_(None))
|
||||
|
||||
if key_type is not None:
|
||||
filters.append(Notification.key_type == key_type)
|
||||
else:
|
||||
filters.append(Notification.key_type != KEY_TYPE_TEST)
|
||||
|
||||
query = Notification.query.filter(*filters)
|
||||
query = _filter_query(query, filter_dict)
|
||||
@@ -250,6 +259,7 @@ def get_notifications_for_service(service_id,
|
||||
query = query.options(
|
||||
joinedload('template_history')
|
||||
)
|
||||
|
||||
return query.order_by(desc(Notification.created_at)).paginate(
|
||||
page=page,
|
||||
per_page=page_size
|
||||
|
||||
@@ -23,8 +23,8 @@ from app.models import (
|
||||
Permission,
|
||||
User,
|
||||
InvitedUser,
|
||||
Service
|
||||
)
|
||||
Service,
|
||||
KEY_TYPE_TEST)
|
||||
from app.statsd_decorators import statsd
|
||||
|
||||
|
||||
@@ -156,7 +156,8 @@ def _stats_for_service_query(service_id):
|
||||
Notification.status,
|
||||
func.count(Notification.id).label('count')
|
||||
).filter(
|
||||
Notification.service_id == service_id
|
||||
Notification.service_id == service_id,
|
||||
Notification.key_type != KEY_TYPE_TEST
|
||||
).group_by(
|
||||
Notification.notification_type,
|
||||
Notification.status,
|
||||
|
||||
@@ -168,6 +168,7 @@ def get_notification_by_id(notification_id):
|
||||
@notifications.route('/notifications', methods=['GET'])
|
||||
def get_all_notifications():
|
||||
data = notifications_filter_schema.load(request.args).data
|
||||
include_jobs = data.get('include_jobs', False)
|
||||
page = data['page'] if 'page' in data else 1
|
||||
page_size = data['page_size'] if 'page_size' in data else current_app.config.get('PAGE_SIZE')
|
||||
limit_days = data.get('limit_days')
|
||||
@@ -179,7 +180,8 @@ def get_all_notifications():
|
||||
page=page,
|
||||
page_size=page_size,
|
||||
limit_days=limit_days,
|
||||
key_type=api_user.key_type)
|
||||
key_type=api_user.key_type,
|
||||
include_jobs=include_jobs)
|
||||
return jsonify(
|
||||
notifications=notification_with_personalisation_schema.dump(pagination.items, many=True).data,
|
||||
page_size=page_size,
|
||||
|
||||
@@ -421,6 +421,7 @@ class NotificationsFilterSchema(ma.Schema):
|
||||
page = fields.Int(required=False)
|
||||
page_size = fields.Int(required=False)
|
||||
limit_days = fields.Int(required=False)
|
||||
include_jobs = fields.Boolean(required=False)
|
||||
|
||||
@pre_load
|
||||
def handle_multidict(self, in_data):
|
||||
|
||||
@@ -219,7 +219,8 @@ def get_all_notifications_for_service(service_id):
|
||||
filter_dict=data,
|
||||
page=page,
|
||||
page_size=page_size,
|
||||
limit_days=limit_days)
|
||||
limit_days=limit_days,
|
||||
include_jobs=True)
|
||||
kwargs = request.args.to_dict()
|
||||
kwargs['service_id'] = service_id
|
||||
return jsonify(
|
||||
|
||||
Reference in New Issue
Block a user