From 9055a33dcab1ba225efc5ad5999e5c323aa51c28 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 21 Oct 2019 13:42:28 +0100 Subject: [PATCH] Only show the filters if they will have an effect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If you never create any API keys we shouldn’t give you the option to see API-related events – it will only confuse things. And since there’s (currently) only one type of event left once you take API key events out of the picture it doesn’t make sense to show the filters at all. --- app/main/views/history.py | 10 +++++++--- app/templates/views/temp-history.html | 22 +++++++++++++--------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/main/views/history.py b/app/main/views/history.py index 08f696494..2512cfe72 100644 --- a/app/main/views/history.py +++ b/app/main/views/history.py @@ -4,17 +4,21 @@ from flask import render_template, request from app import current_service, format_date_numeric from app.main import main -from app.models.event import APIKeyEvents, ServiceEvents +from app.models.event import APIKeyEvent, APIKeyEvents, ServiceEvents from app.utils import user_has_permissions @main.route("/services//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( - _get_events(current_service.id, request.args.get('selected')) + days=_chunk_events_by_day(events), + show_navigation=request.args.get('selected') or any( + isinstance(event, APIKeyEvent) for event in events ) ) diff --git a/app/templates/views/temp-history.html b/app/templates/views/temp-history.html index 47c3e24f3..2047e6236 100644 --- a/app/templates/views/temp-history.html +++ b/app/templates/views/temp-history.html @@ -11,15 +11,19 @@ {{ page_header("Audit events") }} - {{ pill( - [ - ('All', None, url_for('main.history', service_id=current_service.id), None), - ('Service', 'service', url_for('main.history', service_id=current_service.id, selected='service'), None), - ('API keys', 'api', url_for('main.history', service_id=current_service.id, selected='api'), None), - ], - request.args.get('selected'), - show_count=False - ) }} + {% if show_navigation %} +
+ {{ pill( + [ + ('All', None, url_for('main.history', service_id=current_service.id), None), + ('Service settings', 'service', url_for('main.history', service_id=current_service.id, selected='service'), None), + ('API keys', 'api', url_for('main.history', service_id=current_service.id, selected='api'), None), + ], + request.args.get('selected'), + show_count=False + ) }} +
+ {% endif %} {% for day, events in days %}