##// END OF EJS Templates
audit-logs: added *basic* support for NOT query term in audit logs.
marcink -
r1824:fdf0761c default
parent child Browse files
Show More
@@ -1837,6 +1837,7 b' def journal_filter_help():'
1837 1837 'Example filter terms:\n' +
1838 1838 ' repository:vcs\n' +
1839 1839 ' username:marcin\n' +
1840 ' username:(NOT marcin)\n' +
1840 1841 ' action:*push*\n' +
1841 1842 ' ip:127.0.0.1\n' +
1842 1843 ' date:20120101\n' +
@@ -23,10 +23,10 b' import logging'
23 23 from whoosh.qparser.default import QueryParser, query
24 24 from whoosh.qparser.dateparse import DateParserPlugin
25 25 from whoosh.fields import (TEXT, Schema, DATETIME)
26 from sqlalchemy.sql.expression import or_, and_, func
26 from sqlalchemy.sql.expression import or_, and_, not_, func
27 27
28 28 from rhodecode.model.db import UserLog
29 from rhodecode.lib.utils2 import remove_prefix, remove_suffix
29 from rhodecode.lib.utils2 import remove_prefix, remove_suffix, safe_unicode
30 30
31 31 # JOURNAL SCHEMA used only to generate queries in journal. We use whoosh
32 32 # querylang to build sql queries and filter journals
@@ -54,7 +54,7 b' def user_log_filter(user_log, search_ter'
54 54 if search_term:
55 55 qp = QueryParser('repository', schema=JOURNAL_SCHEMA)
56 56 qp.add_plugin(DateParserPlugin())
57 qry = qp.parse(unicode(search_term))
57 qry = qp.parse(safe_unicode(search_term))
58 58 log.debug('Filtering using parsed query %r' % qry)
59 59
60 60 def wildcard_handler(col, wc_term):
@@ -89,16 +89,27 b' def user_log_filter(user_log, search_ter'
89 89 return func.lower(field).startswith(func.lower(val))
90 90 elif isinstance(term, query.DateRange):
91 91 return and_(field >= val[0], field <= val[1])
92 elif isinstance(term, query.Not):
93 return not_(field == val)
92 94 return func.lower(field) == func.lower(val)
93 95
94 if isinstance(qry, (query.And, query.Term, query.Prefix, query.Wildcard,
95 query.DateRange)):
96 if isinstance(qry, (query.And, query.Not, query.Term, query.Prefix,
97 query.Wildcard, query.DateRange)):
96 98 if not isinstance(qry, query.And):
97 99 qry = [qry]
100
98 101 for term in qry:
99 field = term.fieldname
100 val = (term.text if not isinstance(term, query.DateRange)
101 else [term.startdate, term.enddate])
102 if isinstance(term, query.Not):
103 not_term = [z for z in term.leaves()][0]
104 field = not_term.fieldname
105 val = not_term.text
106 elif isinstance(term, query.DateRange):
107 field = term.fieldname
108 val = [term.startdate, term.enddate]
109 else:
110 field = term.fieldname
111 val = term.text
112
102 113 user_log = user_log.filter(get_filterion(field, val, term))
103 114 elif isinstance(qry, query.Or):
104 115 filters = []
General Comments 0
You need to be logged in to leave comments. Login now