You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by hu...@apache.org on 2021/03/31 12:01:33 UTC
[incubator-ponymail-foal] 09/14: allow filtering for certain actions
This is an automated email from the ASF dual-hosted git repository.
humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git
commit 2fabfdb30700e07b0b3375c9b3bc6beaed4b4e26
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Wed Mar 31 12:42:09 2021 +0200
allow filtering for certain actions
---
server/plugins/auditlog.py | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/server/plugins/auditlog.py b/server/plugins/auditlog.py
index fb5eeae..51ac108 100644
--- a/server/plugins/auditlog.py
+++ b/server/plugins/auditlog.py
@@ -44,13 +44,22 @@ class AuditLogEntry:
async def view(
- session: plugins.session.SessionObject, page: int = 0, num_entries: int = 50, raw: bool = False
+ session: plugins.session.SessionObject, page: int = 0, num_entries: int = 50, raw: bool = False, filter: typing.List[str] = []
) -> typing.AsyncGenerator:
""" Returns N entries from the audit log, paginated """
assert session.database, "No database connection could be found!"
- res = await session.database.search(
- index=session.database.dbs.auditlog, size=num_entries, from_=page * num_entries, sort="date:desc",
- )
+ if not filter:
+ res = await session.database.search(
+ index=session.database.dbs.auditlog, size=num_entries, from_=page * num_entries, sort="date:desc",
+ )
+ else:
+ res = await session.database.search(
+ index=session.database.dbs.auditlog, size=num_entries, from_=page * num_entries, sort="date:desc",
+ body={
+ "query": {"bool": {"must": [{"terms": {"action": filter}}]}}
+ },
+ )
+
for doc in res["hits"]["hits"]:
doc["_source"]["id"] = doc["_id"]
if raw: