mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-14 23:08:07 -04:00
This commit introduces a slightly hacky way of putting usernames against events, given that the API only returns user IDs. It does so without: - making changes to the API - making a pages that could potentially fire off dozens of API calls (ie one per user) This comes with the limitation that it can only get names for those team members who are still in the team. Otherwise it will say ‘Unknown’. In the future the API should probably return the name and email address for the user who initiated the event, and whether that user was acting in a platform admin capacity.
43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
from collections import defaultdict
|
|
|
|
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/<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 events:
|
|
days[format_date_numeric(event.time)].append(event)
|
|
|
|
return sorted(days.items(), reverse=True)
|