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 61b1865dcbb810b2f9e9b854d0bd2ba3d4b3ac3f Author: Daniel Gruno <[email protected]> AuthorDate: Mon Sep 27 13:44:21 2021 -0500 Allow for hide/unhide --- server/endpoints/mgmt.py | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/server/endpoints/mgmt.py b/server/endpoints/mgmt.py index 3c761f5..b2ad597 100644 --- a/server/endpoints/mgmt.py +++ b/server/endpoints/mgmt.py @@ -42,13 +42,13 @@ async def process( numentries = int(indata.get("size", 50)) page = int(indata.get("page", 0)) out = [] - async for entry in plugins.auditlog.view(session, page=page, num_entries=numentries, raw=True, filter=("edit", "delete",)): + async for entry in plugins.auditlog.view(session, page=page, num_entries=numentries, raw=True, filter=("edit","delete","hide","unhide")): out.append(entry) return { "entries": out } - # Deleting/hiding a document? + # Deleting a document? elif action == "delete": delcount = 0 for doc in docs: @@ -64,13 +64,43 @@ async def process( index=session.database.dbs.source, id=email["dbid"], ) else: # Standard behavior: hide the email from everyone. - await session.database.index( - index=session.database.dbs.mbox, body=email, id=email["id"], + await session.database.update( + index=session.database.dbs.mbox, body={"doc": email}, id=email["id"], ) lid = email.get("list_raw", "??") await plugins.auditlog.add_entry(session, action="delete", target=doc, lid=lid, log=f"Removed email {doc} from {lid} archives") delcount += 1 return aiohttp.web.Response(headers={}, status=200, text=f"Removed {delcount} emails from archives.") + # Hiding one or more emails? + elif action == "hide": + hidecount = 0 + for doc in docs: + assert isinstance(doc, str), "Document ID must be a string" + email = await plugins.messages.get_email(session, permalink=doc) + if email and isinstance(email, dict) and plugins.aaa.can_access_email(session, email): + email["deleted"] = True + await session.database.update( + index=session.database.dbs.mbox, body={"doc": email}, id=email["id"], + ) + lid = email.get("list_raw", "??") + await plugins.auditlog.add_entry(session, action="hide", target=doc, lid=lid, log=f"Hid email {doc} from {lid} archives") + hidecount += 1 + return aiohttp.web.Response(headers={}, status=200, text=f"Hid {hidecount} emails from archives.") + # Exposing (unhiding) one or more emails? + elif action == "unhide": + hidecount = 0 + for doc in docs: + assert isinstance(doc, str), "Document ID must be a string" + email = await plugins.messages.get_email(session, permalink=doc) + if email and isinstance(email, dict) and plugins.aaa.can_access_email(session, email): + email["deleted"] = False + await session.database.update( + index=session.database.dbs.mbox, body={"doc": email}, id=email["id"], + ) + lid = email.get("list_raw", "??") + await plugins.auditlog.add_entry(session, action="unhide", target=doc, lid=lid, log=f"Unhid email {doc} from {lid} archives") + hidecount += 1 + return aiohttp.web.Response(headers={}, status=200, text=f"Unhid {hidecount} emails from archives.") # Editing an email in place elif action == "edit": new_from = indata.get("from")
