Merge pull request #677 from alphagov/no-jobs-on-api-get

No jobs on api get
This commit is contained in:
minglis
2016-09-19 12:31:04 +01:00
committed by GitHub
9 changed files with 431 additions and 34 deletions

View File

@@ -21,7 +21,7 @@ from app.models import (
NOTIFICATION_CREATED,
NOTIFICATION_SENDING,
NOTIFICATION_PENDING,
NOTIFICATION_TEMPORARY_FAILURE)
NOTIFICATION_TEMPORARY_FAILURE, KEY_TYPE_NORMAL)
from app.dao.dao_utils import transactional
from app.statsd_decorators import statsd
@@ -232,24 +232,29 @@ 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)
query = Notification.query.filter(*filters)
query = _filter_query(query, filter_dict)
if personalisation:
query = query.options(
joinedload('template_history')
)
return query.order_by(desc(Notification.created_at)).paginate(
page=page,
per_page=page_size

View File

@@ -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,

View File

@@ -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):

View File

@@ -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(