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/09/27 19:12:04 UTC

[incubator-ponymail-foal] branch master updated (b9f0817 -> 7712e89)

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

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


    from b9f0817  regen JS
     new 5fbaf62  allow removing attachments from disk and docs
     new 4071ba7  add in attachment modification features
     new 7712e89  regen JS

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 server/endpoints/mgmt.py | 25 +++++++++++++++++++++++++
 webui/js/ponymail.js     | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 webui/js/source/mgmt.js  | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 113 insertions(+), 4 deletions(-)

[incubator-ponymail-foal] 02/03: add in attachment modification features

Posted by hu...@apache.org.
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 4071ba75f6b4bad3728ee22813d67eea9dfe595d
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Mon Sep 27 14:11:49 2021 -0500

    add in attachment modification features
---
 webui/js/source/mgmt.js | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/webui/js/source/mgmt.js b/webui/js/source/mgmt.js
index ad75382..b0f2b08 100644
--- a/webui/js/source/mgmt.js
+++ b/webui/js/source/mgmt.js
@@ -18,6 +18,37 @@ async function POST(url, formdata, state) {
     return resp
 }
 
+// Removes an attachment from the archives
+async function admin_del_attachment(hash) {
+    if (!confirm("Are you sure you wish remove this attachment from the archives?")) {
+        return
+    }
+    // rewrite attachments for email
+    let new_attach = [];
+    for (let el of admin_email_meta.attachments) {
+        if (el.hash != hash) {
+            new_attach.push(el);
+        }
+    }
+    admin_email_meta.attachments = new_attach;
+    formdata = JSON.stringify({
+        action: "delatt",
+        document: hash
+    });
+    // remove attachment
+    let rv = await POST('%sapi/mgmt.json'.format(apiURL), formdata, {});
+    let response = await rv.text();
+
+    // Edit email in place
+    admin_save_email(true);
+
+    if (rv.status == 200) {
+        modal("Attachment removed", "Server responded with: " + response, "help");
+    } else {
+        modal("Something went wrong!", "Server responded with: " + response, "error");
+    }
+}
+
 // Hides an email from the archives
 async function admin_hide_email() {
     if (!confirm("Are you sure you wish to hide this email from the archives?")) {
@@ -73,12 +104,16 @@ async function admin_delete_email() {
 }
 
 // Saves an email with edits
-async function admin_save_email() {
+async function admin_save_email(edit_attachment = false) {
     let from = document.getElementById('email_from').value;
     let subject = document.getElementById('email_subject').value;
     let listname = document.getElementById('email_listname').value;
     let private = document.getElementById('email_private').value;
     let body = document.getElementById('email_body').value;
+    let attach = null;
+    if (edit_attachment) {
+        attach = admin_email_meta.attachments;
+    }
     let formdata = JSON.stringify({
         action: "edit",
         document: admin_current_email,
@@ -86,10 +121,12 @@ async function admin_save_email() {
         subject: subject,
         list: listname,
         private: private,
-        body: body
+        body: body,
+        attachments: attach
     })
     let rv = await POST('%sapi/mgmt.json'.format(apiURL), formdata, {});
     let response = await rv.text();
+    if (edit_attachment && rv.status == 200) return
     if (rv.status == 200) {
         modal("Email changed", "Server responded with: " + response, "help");
     } else {
@@ -223,6 +260,11 @@ function admin_email_preview(stats, json) {
             if (attachment.size >= 1024) fs = ` ${Math.floor(attachment.size/1024)} KB`;
             if (attachment.size >= 1024 * 1024) fs = ` ${Math.floor(attachment.size/(1024*10.24))/100} MB`;
             alinks.push(fs);
+            let adel = new HTML('a', {
+                onclick: `admin_del_attachment('${attachment.hash}');`,
+                href: "javascript:void(0);"
+            }, "Delete attachment");
+            alinks.push(adel);
             alinks.push(new HTML('br'));
         }
         let attach_value = new HTML('div', {

[incubator-ponymail-foal] 01/03: allow removing attachments from disk and docs

Posted by hu...@apache.org.
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 5fbaf625b78e7dcbe2a2dc485511a0b76d398c17
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Mon Sep 27 14:11:31 2021 -0500

    allow removing attachments from disk and docs
---
 server/endpoints/mgmt.py | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/server/endpoints/mgmt.py b/server/endpoints/mgmt.py
index b2ad597..062347a 100644
--- a/server/endpoints/mgmt.py
+++ b/server/endpoints/mgmt.py
@@ -101,6 +101,28 @@ async def process(
                 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.")
+    # Removing an attachment
+    elif action == "delatt":
+        delcount = 0
+        for doc in docs:
+            assert isinstance(doc, str), "Attachment ID must be a string"
+            attachment = None
+            try:
+                assert session.database, "Database not connected!"
+                attachment = await session.database.get(
+                    index=session.database.dbs.attachment, id=doc
+                )
+            except plugins.database.DBError:
+                pass  # attachment not found
+
+            if attachment and isinstance(attachment, dict):
+                await session.database.delete(
+                    index=session.database.dbs.attachment, id=attachment["_id"],
+                )
+                lid = "<system>"
+                await plugins.auditlog.add_entry(session, action="delatt", target=doc, lid=lid, log=f"Removed attachment {doc} from the archives")
+                delcount += 1
+        return aiohttp.web.Response(headers={}, status=200, text=f"Removed {delcount} attachments from archives.")
     # Editing an email in place
     elif action == "edit":
         new_from = indata.get("from")
@@ -108,6 +130,7 @@ async def process(
         new_list = indata.get("list", "")
         private = indata.get("private", "no") == "yes"
         new_body = indata.get("body", "")
+        attach_edit = indata.get("attachments", None)
 
         # Check for consistency so we don't pollute the database
         assert isinstance(doc, str) and doc, "Document ID is missing or invalid"
@@ -136,6 +159,8 @@ async def process(
             email["list"] = lid
             email["list_raw"] = lid
             email["body"] = new_body
+            if attach_edit is not None:  # Only set if truly editing attachments...
+                email["attachments"] = attach_edit
 
             # Save edited email
             await session.database.update(

[incubator-ponymail-foal] 03/03: regen JS

Posted by hu...@apache.org.
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 7712e894e55e954b90a786c6f12503d7cf44cedd
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Mon Sep 27 14:11:56 2021 -0500

    regen JS
---
 webui/js/ponymail.js | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/webui/js/ponymail.js b/webui/js/ponymail.js
index 4b409e5..65c1af1 100644
--- a/webui/js/ponymail.js
+++ b/webui/js/ponymail.js
@@ -2706,6 +2706,37 @@ async function POST(url, formdata, state) {
     return resp
 }
 
+// Removes an attachment from the archives
+async function admin_del_attachment(hash) {
+    if (!confirm("Are you sure you wish remove this attachment from the archives?")) {
+        return
+    }
+    // rewrite attachments for email
+    let new_attach = [];
+    for (let el of admin_email_meta.attachments) {
+        if (el.hash != hash) {
+            new_attach.push(el);
+        }
+    }
+    admin_email_meta.attachments = new_attach;
+    formdata = JSON.stringify({
+        action: "delatt",
+        document: hash
+    });
+    // remove attachment
+    let rv = await POST('%sapi/mgmt.json'.format(apiURL), formdata, {});
+    let response = await rv.text();
+
+    // Edit email in place
+    admin_save_email(true);
+
+    if (rv.status == 200) {
+        modal("Attachment removed", "Server responded with: " + response, "help");
+    } else {
+        modal("Something went wrong!", "Server responded with: " + response, "error");
+    }
+}
+
 // Hides an email from the archives
 async function admin_hide_email() {
     if (!confirm("Are you sure you wish to hide this email from the archives?")) {
@@ -2761,12 +2792,16 @@ async function admin_delete_email() {
 }
 
 // Saves an email with edits
-async function admin_save_email() {
+async function admin_save_email(edit_attachment = false) {
     let from = document.getElementById('email_from').value;
     let subject = document.getElementById('email_subject').value;
     let listname = document.getElementById('email_listname').value;
     let private = document.getElementById('email_private').value;
     let body = document.getElementById('email_body').value;
+    let attach = null;
+    if (edit_attachment) {
+        attach = admin_email_meta.attachments;
+    }
     let formdata = JSON.stringify({
         action: "edit",
         document: admin_current_email,
@@ -2774,10 +2809,12 @@ async function admin_save_email() {
         subject: subject,
         list: listname,
         private: private,
-        body: body
+        body: body,
+        attachments: attach
     })
     let rv = await POST('%sapi/mgmt.json'.format(apiURL), formdata, {});
     let response = await rv.text();
+    if (edit_attachment && rv.status == 200) return
     if (rv.status == 200) {
         modal("Email changed", "Server responded with: " + response, "help");
     } else {
@@ -2911,6 +2948,11 @@ function admin_email_preview(stats, json) {
             if (attachment.size >= 1024) fs = ` ${Math.floor(attachment.size/1024)} KB`;
             if (attachment.size >= 1024 * 1024) fs = ` ${Math.floor(attachment.size/(1024*10.24))/100} MB`;
             alinks.push(fs);
+            let adel = new HTML('a', {
+                onclick: `admin_del_attachment('${attachment.hash}');`,
+                href: "javascript:void(0);"
+            }, "Delete attachment");
+            alinks.push(adel);
             alinks.push(new HTML('br'));
         }
         let attach_value = new HTML('div', {