[feat] Display mixnet status on outgoing emails
authorRuben Pollan <meskio@sindominio.net>
Tue, 1 Aug 2017 22:05:25 +0000 (00:05 +0200)
committerRuben Pollan <meskio@sindominio.net>
Tue, 1 Aug 2017 22:05:25 +0000 (00:05 +0200)
service/src/pixelated/resources/mixnet_resource.py [new file with mode: 0644]
service/src/pixelated/resources/root_resource.py
web-ui/app/js/mail_view/ui/recipients/recipient.js
web-ui/app/scss/base/_colors.scss
web-ui/app/scss/views/_compose-view.scss
web-ui/app/templates/compose/fixed_recipient.hbs

diff --git a/service/src/pixelated/resources/mixnet_resource.py b/service/src/pixelated/resources/mixnet_resource.py
new file mode 100644 (file)
index 0000000..aa895c9
--- /dev/null
@@ -0,0 +1,61 @@
+#
+# Copyright (c) 2017 LEAP
+#
+# Pixelated is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Pixelated is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
+
+import json
+
+from email.utils import parseaddr
+from pixelated.resources import respond_json_deferred, BaseResource
+from twisted.web import server
+from twisted.logger import Logger
+from txzmq import ZmqEndpoint, ZmqEndpointType
+from txzmq import ZmqFactory, ZmqREQConnection
+
+from leap.bitmask.core import ENDPOINT
+
+
+class MixnetResource(BaseResource):
+    # XXX: this is hacky, we should use bitmask.js properly in the web-ui
+    #      But, if we and up doing zmq interface, we can do
+    #      something more generic for all the API.
+
+    isLeaf = True
+    log = Logger()
+
+    def render_GET(self, request):
+        zf = ZmqFactory()
+        e = ZmqEndpoint(ZmqEndpointType.connect, ENDPOINT)
+        _conn = ZmqREQConnection(zf, e)
+
+        _mail = self.mail_service(request)
+        userid = _mail.account_email
+        _, address = parseaddr(request.args.get('search')[0])
+
+        def callback(resp_json):
+            response = json.loads(resp_json[0])
+            if response['error'] is not None:
+                respond_json_deferred(response['error'], request, status_code=404)
+            else:
+                respond_json_deferred(response['result'], request, status_code=200)
+
+        def err(fail):
+            respond_json_deferred(str(fail), request, status_code=404)
+
+        data = ["mail", "mixnet_status", userid, address]
+        d = _conn.sendMsg(*data)
+        d.addCallback(callback)
+        d.addErrback(err)
+
+        return server.NOT_DONE_YET
index b014a59..6398c00 100644 (file)
@@ -35,6 +35,7 @@ from pixelated.resources.mail_resource import MailResource
 from pixelated.resources.mails_resource import MailsResource
 from pixelated.resources.tags_resource import TagsResource
 from pixelated.resources.keys_resource import KeysResource
+from pixelated.resources.mixnet_resource import MixnetResource
 from twisted.web.resource import NoResource
 from twisted.web.static import File
 
@@ -96,6 +97,7 @@ class RootResource(BaseResource):
         self._child_resources.add('backup-account', BackupAccountResource(self._services_factory, authenticator, provider))
         self._child_resources.add('sandbox', SandboxResource(self._protected_static_folder))
         self._child_resources.add('keys', KeysResource(self._services_factory))
+        self._child_resources.add('mixnet', MixnetResource(self._services_factory))
         self._child_resources.add(AttachmentsResource.BASE_URL, AttachmentsResource(self._services_factory))
         self._child_resources.add('contacts', ContactsResource(self._services_factory))
         self._child_resources.add('features', FeaturesResource(provider))
index c13a52b..1986610 100644 (file)
@@ -89,6 +89,25 @@ define(
         }.bind(this));
       };
 
+      this.discoverMixnet = function () {
+        var p = $.getJSON('/mixnet?search=' + this.attr.address).promise();
+        p.done(function (stat) {
+          switch (stat.status) {
+            case 'ok':
+              this.$node.find('.recipient-mixnet').addClass('mixnet');
+              break;
+            case 'unsuported':
+              this.$node.find('.recipient-mixnet').addClass('unsuported-mixnet');
+              break;
+            default:
+              this.$node.find('.recipient-mixnet').addClass('not-mixnet');
+          }
+        }.bind(this));
+        p.fail(function () {
+          this.$node.find('.recipient-mixnet').addClass('not-mixnet');
+        }.bind(this));
+      };
+
       this.getMailAddress = function() {
         return this.$node.find('input[type=hidden]').val();
       };
@@ -105,6 +124,7 @@ define(
             this.sinalizeInvalid();
         } else {
             this.discoverEncryption();
+            this.discoverMixnet();
         }
       });
     }
index c7807e8..c23714f 100644 (file)
@@ -59,6 +59,9 @@ $will_be_encrypted: $success;
 $wont_be_encrypted: $attention;
 $recipients_font_color: #828282;
 
+$will_be_mixed: $success;
+$unsuported_mixed: $light_gray;
+
 /* Attachments */
 $attachment_text: #555;
 $attachment_icon: lighten($attachment_text, 30);
index 61e785a..be19318 100644 (file)
                 background-color: $background_light_grey;
                 border: 1px solid $border_light_grey;
                 border-radius: 2px;
+
+                .recipient-mixnet {
+                    &:before {
+                        font-family: FontAwesome;
+                        padding-right: 6px;
+                        font-size: 1.4em;
+                    }
+
+                    &.mixnet {
+                        &:before {
+                            color: $will_be_mixed;
+                            content: "\f135";
+                        }
+                    }
+
+                    &.unsuported-mixnet {
+                        &:before {
+                            color: $unsuported_mixed;
+                            content: "\f135";
+                        }
+                    }
+
+                    &.not-mixnet {
+                        &:before {
+                            color: $unsuported_mixed;
+                            content: "";
+                        }
+                    }
+                }
             }
 
             .recipient-del {
index 8b01717..59efd7e 100644 (file)
@@ -1,7 +1,7 @@
 <div class="fixed-recipient">
   <span class="recipient-area">
     <div class="recipient-value">
-      <span>{{ address }}</span> <a class="recipient-del" href="#" data-label="{{t 'click-to-remove'}}"/>
+      <span class="recipient-mixnet"></span><span>{{ address }}</span> <a class="recipient-del" href="#" data-label="{{t 'click-to-remove'}}"/>
     </div>
   </span>
   <input type="hidden" value="{{ address }}" name="{{ name }}" />