From d4d6d832b1b465581e0d95621bee5f69be5cada1 Mon Sep 17 00:00:00 2001 From: kevgliss Date: Fri, 2 Jun 2017 09:07:22 -0700 Subject: [PATCH] Fixing audit filtering and sorting. (#827) --- lemur/logs/service.py | 19 ++++++++++++++++++- .../app/angular/logs/view/view.tpl.html | 6 +++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lemur/logs/service.py b/lemur/logs/service.py index d73c17af..59097cb0 100644 --- a/lemur/logs/service.py +++ b/lemur/logs/service.py @@ -8,8 +8,11 @@ .. moduleauthor:: Kevin Glisson """ from flask import current_app + from lemur import database from lemur.logs.models import Log +from lemur.users.models import User +from lemur.certificates.models import Certificate def create(user, type, certificate=None): @@ -51,6 +54,20 @@ def render(args): if filt: terms = filt.split(';') - query = database.filter(query, Log, terms) + + if 'certificate.name' in terms: + sub_query = database.session_query(Certificate.id)\ + .filter(Certificate.name.ilike('%{0}%'.format(terms[1]))) + + query = query.filter(Log.certificate_id.in_(sub_query)) + + elif 'user.email' in terms: + sub_query = database.session_query(User.id)\ + .filter(User.email.ilike('%{0}%'.format(terms[1]))) + + query = query.filter(Log.user_id.in_(sub_query)) + + else: + query = database.filter(query, Log, terms) return database.sort_and_page(query, Log, args) diff --git a/lemur/static/app/angular/logs/view/view.tpl.html b/lemur/static/app/angular/logs/view/view.tpl.html index f8d1244b..496c998c 100644 --- a/lemur/static/app/angular/logs/view/view.tpl.html +++ b/lemur/static/app/angular/logs/view/view.tpl.html @@ -15,8 +15,8 @@ - @@ -26,7 +26,7 @@ -
- + + {{ momentService.createMoment(log.loggedAt) }} {{ log.user.email }} + {{ log.logType }}