diff options
| author | Alon Levy <alon@pobox.com> | 2015-01-13 08:36:01 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2015-01-13 10:24:00 +0200 |
| commit | eced38bfff26a9c7faf78683fe15f148732cd9cf (patch) | |
| tree | 452466fa7c2923702df73fd2546da94b149d9925 | |
| parent | 96534de0c0dceefde8795e879927c5bedbdaa858 (diff) | |
incorporate https://github.com/ivoviz/feedback
allows user to mark an image and send it.
sends an email to configured recipient. defaults to using localhost:25
as the SMTP server (no user name, no password, see [1] for configuration
parameters of flask-mail).
Introduces a config parameter:
FEEDBACK_RECIPIENT = feedback@localhost
left TODO:
1. customize the 'thank you' text
2. document in user guide (setting MAIL_DEFAULT_SENDER correctly)
[1] https://pythonhosted.org/Flask-Mail/#configuring-flask-mail
| -rw-r--r-- | README.mediawiki | 25 | ||||
| -rw-r--r-- | res/client/css/icons.png | bin | 0 -> 2022 bytes | |||
| -rw-r--r-- | res/etc/rhizi-server.conf | 11 | ||||
| -rw-r--r-- | src/server/rz_feedback.py | 32 | ||||
| -rw-r--r-- | src/server/rz_mail.py | 27 | ||||
| -rw-r--r-- | src/server/rz_server.py | 2 |
6 files changed, 89 insertions, 8 deletions
diff --git a/README.mediawiki b/README.mediawiki index 25bc6433..37f7dca3 100644 --- a/README.mediawiki +++ b/README.mediawiki @@ -14,14 +14,29 @@ A collaborative editor for organizing, communicating, and analyzing data in grap = Use = == requirements == +=== Server === +==== neo4j ==== Install [neo4j](http://neo4j.com/download/) -Install [gevent-socketio](https://pypi.python.org/pypi/gevent-socketio/) Or <code> Run pip install gevent-socketio </code> +==== python libs ==== +Install all of: +# [gevent-socketio](https://pypi.python.org/pypi/gevent-socketio/) +# [flask](http://flask.pocoo.org/) +# [flask-mail](https://github.com/mattupstate/flask-mail) -Install [simplejson](http://undefined.org/python/#simplejson) Or <code> Run pip install simplejson </code> - - flask uses itsdangerous which uses simplejson - - the default json converts namedtuples to arrays stripping the names. - - simplejson converts them to a dictionary, a behavior we rely on. +Or install it all via pip: +<code> + pip install gevent-socketio + pip install flask + pip install flask-mail +</code> + +=== Client === +All of the following are already bundled but noted here for reference: +# [feedback](https://github.com/ivoviz/feedback) (it also bundles [html2canvas](http://html2canvas.hertzen.com/)) +# jquery +# d3 +# FileSaver == Running Rhizi Locally == To run Rhizi locally: diff --git a/res/client/css/icons.png b/res/client/css/icons.png Binary files differnew file mode 100644 index 00000000..d2a0da7e --- /dev/null +++ b/res/client/css/icons.png diff --git a/res/etc/rhizi-server.conf b/res/etc/rhizi-server.conf index f5e3c2d3..2d105833 100644 --- a/res/etc/rhizi-server.conf +++ b/res/etc/rhizi-server.conf @@ -3,7 +3,16 @@ listen_port = 8080 development_mode = True neo4j_url = http://127.0.0.1:7474 log_path = rhizi-server.log -access_control = False +access_control = True SERVER_NAME = rhizi.local:8080 DEBUG = True + +# Mail settings +MAIL_DEFAULT_SENDER = rhizi@localhost +# 0/1 (not True - uses int) +MAIL_DEBUG = 0 +FEEDBACK_RECIPIENT = feedback@localhost + +# This should not be committed +SECRET_KEY = cographmetamaps diff --git a/src/server/rz_feedback.py b/src/server/rz_feedback.py index 74fe2c7f..677814db 100644 --- a/src/server/rz_feedback.py +++ b/src/server/rz_feedback.py @@ -1,11 +1,20 @@ import logging +import base64 from flask import request from flask import json +from flask import current_app +from flask import session +from rz_mail import send_message log = logging.getLogger('rhizi') +def decode_base64_uri(base64_encoded_data_uri): + start = base64_encoded_data_uri.find(',') + 1 + encoded = base64_encoded_data_uri[start:] + return base64.decodestring(encoded) + def feedback(): """ Email all parts as attachments to configured feedback email @@ -17,7 +26,7 @@ def feedback(): req_json = json.loads(feedback) url = req_json['url'] note = req_json['note'] - img = req_json['img'] # FIXME base64 encoded data URI + img = decode_base64_uri(req_json['img']) html = req_json['html'] return url, note, img, html @@ -26,4 +35,23 @@ def feedback(): except: log.warn('failed to sanitize inputs. request: %s' % request) - return "success" + # FIXME: should be async via celery (or another method) + session_user = session.get('username') + feedback_body = """Feedback from user: +%(user)s + +watching URL: +%(url)s + +Left note: +%(note)s +""" % dict(url=url, note=note, user=session_user if session_user else "Not logged in") + send_message(recipients=[current_app.rz_config.FEEDBACK_RECIPIENT], + subject="User feedback from Rhizi", + body=feedback_body, + attachments=[ + ('feedback_screenshot.png', img), + ('feedback_page.html', html), + ]) + + return "{}" # expects json encoded, contents discarded diff --git a/src/server/rz_mail.py b/src/server/rz_mail.py new file mode 100644 index 00000000..0ecf1d61 --- /dev/null +++ b/src/server/rz_mail.py @@ -0,0 +1,27 @@ +import magic + +from flask_mail import Mail, Message + +mail = None + +magic_mime = magic.open(magic.MAGIC_MIME) +magic_mime.load() + +def mimetype(data): + return magic_mime.buffer(data).split(';')[0] + +def init_mail(webapp): + global mail + mail = Mail(webapp) + +def send_message(recipients, subject, attachments, body): + """ + attachments is a list of tuples (filename, data) + libmagic is used to guess the mimetype + """ + msg = Message(subject, recipients=recipients) + msg.body = body + for filename, data in attachments: + msg.attach(filename=filename, content_type=mimetype(data), data=data) + mail.send(msg) + diff --git a/src/server/rz_server.py b/src/server/rz_server.py index 52db213e..87ba09a4 100644 --- a/src/server/rz_server.py +++ b/src/server/rz_server.py @@ -27,6 +27,7 @@ from flask import send_from_directory from rz_mesh import init_ws_interface from rz_kernel import RZ_Kernel +from rz_mail import init_mail import rz_api import rz_api_rest import rz_feedback @@ -270,5 +271,6 @@ if __name__ == "__main__": kernel = RZ_Kernel() webapp = init_webapp(cfg, kernel) ws_srv = init_ws_interface(cfg, kernel, webapp) + init_mail(webapp) ws_srv.serve_forever() |
