Selaa lähdekoodia

use can disable PGP on an alias

Son NK 5 vuotta sitten
vanhempi
commit
13bb9810b6
3 muutettua tiedostoa jossa 64 lisäystä ja 3 poistoa
  1. 53 2
      app/dashboard/templates/dashboard/index.html
  2. 5 0
      app/models.py
  3. 6 1
      server.py

+ 53 - 2
app/dashboard/templates/dashboard/index.html

@@ -372,10 +372,26 @@
                   Save
                 </a>
               </div>
-
-
             </div>
 
+            {% if alias.mailbox_support_pgp() %}
+              <div class="small-text mt-2" data-toogle="tooltip"
+                   title="You can decide to turn off the PGP for an alias. This can be useful if the sender already encrypts the emails">
+                PGP
+                <i class="fe fe-help-circle"></i>
+              </div>
+              <div>
+                <label class="custom-switch cursor pl-0">
+                  <input type="checkbox" class="enable-disable-pgp custom-switch-input"
+                         data-alias="{{ alias.id }}"
+                         data-alias-email="{{ alias.email }}"
+                      {{ "checked" if alias.pgp_enabled() else "" }}>
+
+                  <span class="custom-switch-indicator"></span>
+                </label>
+              </div>
+            {% endif %}
+
             <div class="row mt-3">
               <div class="col">
                 <form method="post">
@@ -563,6 +579,41 @@
       }
     })
 
+    $(".enable-disable-pgp").change(async function (e) {
+      let aliasId = $(this).data("alias");
+      let alias = $(this).data("alias-email");
+      var oldValue = !$(this).prop("checked");
+      let newValue = !oldValue;
+
+      try {
+        let res = await fetch(`/api/aliases/${aliasId}`, {
+          method: "PUT",
+          headers: {
+            "Content-Type": "application/json",
+          },
+          body: JSON.stringify({
+            disable_pgp: oldValue,
+          }),
+        });
+
+        if (res.ok) {
+          if (newValue) {
+            toastr.success(`PGP is enabled for ${alias}`);
+          } else {
+            toastr.info(`PGP is disabled for ${alias}`);
+          }
+        } else {
+          toastr.error("Sorry for the inconvenience! Could you refresh the page & retry please?", "Unknown Error");
+          // reset to the original value
+          $(this).prop("checked", oldValue);
+        }
+      } catch (e) {
+        toastr.error("Sorry for the inconvenience! Could you refresh the page & retry please?", "Unknown Error");
+        // reset to the original value
+        $(this).prop("checked", oldValue);
+      }
+    })
+
     $(".save-note").on("click", async function () {
       let aliasId = $(this).data("alias");
       let note = $(`#note-${aliasId}`).val();

+ 5 - 0
app/models.py

@@ -678,6 +678,11 @@ class Alias(db.Model, ModelMixin):
                 return True
         return False
 
+    def pgp_enabled(self) -> bool:
+        if self.mailbox_support_pgp() and not self.disable_pgp:
+            return True
+        return False
+
     @classmethod
     def create(cls, **kw):
         r = cls(**kw)

+ 6 - 1
server.py

@@ -167,7 +167,12 @@ def fake_data():
     api_key = ApiKey.create(user_id=user.id, name="Firefox")
     api_key.code = "codeFF"
 
-    m1 = Mailbox.create(user_id=user.id, email="m1@cd.ef", verified=True)
+    m1 = Mailbox.create(
+        user_id=user.id,
+        email="m1@cd.ef",
+        verified=True,
+        pgp_finger_print="fake fingerprint",
+    )
     db.session.commit()
 
     for i in range(31):