You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by se...@apache.org on 2022/01/31 21:29:46 UTC

[incubator-ponymail-foal] 01/02: List changed fields

This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git

commit 273405a7481e1e2c5de575200a2b0a09cf77bc29
Author: Sebb <se...@apache.org>
AuthorDate: Mon Jan 31 21:26:54 2022 +0000

    List changed fields
---
 server/endpoints/mgmt.py  | 14 +++++++++++---
 test/itest_integration.py | 15 ++++++++++-----
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/server/endpoints/mgmt.py b/server/endpoints/mgmt.py
index 8a3521b..5907085 100644
--- a/server/endpoints/mgmt.py
+++ b/server/endpoints/mgmt.py
@@ -166,13 +166,16 @@ async def process(
         email = await plugins.messages.get_email(session, permalink=doc)
         if email:
 
+            changes = [] # what changes have been seen?
             new_private = indata.get("private", True) # This allows it to be omitted; assume private
              # the property could also be a string, in which case look for explicit public value
             if not isinstance(new_private, bool):
                 new_private = (new_private != 'no') # True unless value is 'no', i.e. public
+            old_private = email.get("private")
             # if property is absent, we want to set it, so don't default it
-            changed_private = (email.get("private") != new_private)
+            changed_private = (old_private != new_private)
             if changed_private:
+                changes.append(f"Privacy: {old_private} => {new_private}")
                 email["private"] = new_private # this does not require the source to be hidden
 
             hide_source = False # we hide the source if any of its derived fields are changed
@@ -181,10 +184,12 @@ async def process(
             if new_from and not email["from"] == new_from:
                 email["from_raw"] = new_from
                 email["from"] = new_from
+                changes.append("Author")
                 hide_source = True
 
             if new_subject and not email["subject"] == new_subject:
                 email["subject"] = new_subject
+                changes.append("Subject")
                 hide_source = True
     
             origin_lid = email["list_raw"]
@@ -196,19 +201,22 @@ async def process(
                     email["list"] = new_lid
                     email["list_raw"] = new_lid
                     email["forum"] = new_lid.strip("<>").replace(".", "@", 1)
+                    changes.append(f"Listid {origin_lid} => {new_lid}")
                     hide_source = True
 
             if new_body and not email["body"] == new_body:
                 email["body"] = new_body
                 email["body_short"] = new_body[:plugins.messages.SHORT_BODY_MAX_LEN+1]
+                changes.append("Body")
                 hide_source = True
 
             if attach_edit is not None:  # Only set if truly editing attachments...
                 email["attachments"] = attach_edit
+                changes.append("Attachments")
                 hide_source = True
 
             # Save edited email
-            if changed_private or hide_source: # something changed
+            if changes: # something changed
                 if "id" in email: # id is not a valid property for mbox
                     del email["id"]
                 await session.database.update(
@@ -229,7 +237,7 @@ async def process(
 
                 # TODO this should perhaps show the actual changes?
                 await plugins.auditlog.add_entry(session, action="edit", target=doc, lid=new_lid,
-                                             log= f"Edited email {doc} from {origin_lid} archives ({origin_lid} -> {new_lid})")
+                                             log= f"Edited email {doc} from {origin_lid} archives. Changes: {', '.join(changes)}")
 
                 return aiohttp.web.Response(headers={}, status=200, text="Email successfully saved")
             else:
diff --git a/test/itest_integration.py b/test/itest_integration.py
index 9b15e8a..702ed1f 100644
--- a/test/itest_integration.py
+++ b/test/itest_integration.py
@@ -113,8 +113,8 @@ def check_access(email, cookies):
         mid, msgid, listid, private = check_email(email, cookies)
         check_source(mid, msgid, listid, private, cookies)
 
-def check_auditlog_count(count, admin_cookies):
-    jzon = mgmt_get_json({"action": 'log'}, admin_cookies)
+def check_auditlog_count(count, admin_cookies, action_filter=None):
+    jzon = mgmt_get_json({"action": 'log', "filter": action_filter}, admin_cookies)
     assert len(jzon['entries']) == count
     return jzon['entries']
 
@@ -318,8 +318,10 @@ def test_mgmt_edit():
     text = mgmt_get_text(
         {
             "action": 'edit', "document": DOCUMENT_EDIT_TEST,
-            # "from": '', "subject": '', "list": test_list_id, 
-            "body": str(time.time()), "private": False,
+            "body": str(time.time()),
+            "from": str(time.time()),
+            "subject": str(time.time()),
+            "private": False, # default is True
         },
         admin_cookies
         )
@@ -327,6 +329,9 @@ def test_mgmt_edit():
 
     check_auditlog_count(3, admin_cookies)
 
+    log = check_auditlog_count(1, admin_cookies, 'edit')[0]['log']
+    assert 'Changes: Author, Subject, Body' in log # This is a fragile test..
+
     jzon = requests.get(
         f"{API_BASE}/stats.lua",
         params={"list": TEST_LIST2, "domain": TEST_DOMAIN, "emailsOnly": True, "d": 'gte=0d'}
@@ -355,4 +360,4 @@ def test_mgmt_edit():
 
 def test_mgmt_log_after():
     admin_cookies = get_cookies('admin')
-    check_auditlog_count(3, admin_cookies)
+    check_auditlog_count(3, admin_cookies)
\ No newline at end of file