mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-04-11 12:51:05 -04:00
We mostly rely on the API returning a 404 to generate 404s for trying to get things with non-UUID IDs. This is fine, except our tests often mock these API calls. So it could look like everything is working fine, except the thing your passing in might never be a valid UUID, and thus would 404 in a non-test environment. So this commit: 1. uses the `uuid` URL converter everywhere there’s something that looks like an ID in a URL parameter 2. adds a test which automates checking for 1.
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
from collections import defaultdict
|
|
from operator import attrgetter
|
|
|
|
from flask import render_template, request
|
|
|
|
from app import current_service, format_date_numeric
|
|
from app.main import main
|
|
from app.models.event import APIKeyEvent, APIKeyEvents, ServiceEvents
|
|
from app.utils import user_has_permissions
|
|
|
|
|
|
@main.route("/services/<uuid:service_id>/history")
|
|
@user_has_permissions('manage_service')
|
|
def history(service_id):
|
|
|
|
events = _get_events(current_service.id, request.args.get('selected'))
|
|
|
|
return render_template(
|
|
'views/temp-history.html',
|
|
days=_chunk_events_by_day(events),
|
|
show_navigation=request.args.get('selected') or any(
|
|
isinstance(event, APIKeyEvent) for event in events
|
|
),
|
|
user_getter=current_service.active_users.get_name_from_id,
|
|
)
|
|
|
|
|
|
def _get_events(service_id, selected):
|
|
if selected == 'api':
|
|
return APIKeyEvents(service_id)
|
|
if selected == 'service':
|
|
return ServiceEvents(service_id)
|
|
return APIKeyEvents(service_id) + ServiceEvents(service_id)
|
|
|
|
|
|
def _chunk_events_by_day(events):
|
|
|
|
days = defaultdict(list)
|
|
|
|
for event in sorted(events, key=attrgetter('time'), reverse=True):
|
|
days[format_date_numeric(event.time)].append(event)
|
|
|
|
return sorted(days.items(), reverse=True)
|