diff --git a/adsws/feedback/config.py b/adsws/feedback/config.py index 9092195..5c43228 100644 --- a/adsws/feedback/config.py +++ b/adsws/feedback/config.py @@ -3,12 +3,14 @@ the application name. """ EXTENSIONS = [ - 'adsws.ext.ratelimiter' + 'adsws.ext.ratelimiter', + 'adsws.ext.mail' ] FEEDBACK_SLACK_END_POINT = 'https://hooks.slack.com/services/TOKEN/TOKEN' +FEEDBACK_SLACK_EMOJI = ':interrobang:' GOOGLE_RECAPTCHA_ENDPOINT = 'https://www.google.com/recaptcha/api/siteverify' GOOGLE_RECAPTCHA_PRIVATE_KEY = 'MY_PRIVATE_KEY' CORS_DOMAINS = ['https://ui.adsabs.harvard.edu'] CORS_HEADERS = [] -CORS_METHODS = ['POST', 'GET'] \ No newline at end of file +CORS_METHODS = ['POST', 'GET'] diff --git a/adsws/feedback/utils.py b/adsws/feedback/utils.py index e3eb104..92380fc 100644 --- a/adsws/feedback/utils.py +++ b/adsws/feedback/utils.py @@ -3,6 +3,16 @@ for this module. But are also used in differing modules insidide the same project, and so do not belong to anything specific. """ +from flask import current_app +from flask.ext.mail import Message + +def send_feedback_email(name, sender, feedback): + msg = Message(subject="Bumblebee Feedback", + recipients=['ehenneken@cfa.harvard.edu'], + sender=(name, sender), + body=feedback) + current_app.extensions['mail'].send(msg) + return msg def err(error_dictionary): """ @@ -11,4 +21,4 @@ def err(error_dictionary): :return: tuple of error message and error number """ - return {'error': error_dictionary['body']}, error_dictionary['number'] \ No newline at end of file + return {'error': error_dictionary['body']}, error_dictionary['number'] diff --git a/adsws/feedback/views.py b/adsws/feedback/views.py index cd2cd9b..31794d5 100644 --- a/adsws/feedback/views.py +++ b/adsws/feedback/views.py @@ -11,6 +11,7 @@ from adsws.feedback.utils import err from adsws.accounts.utils import verify_recaptcha, get_post_data from werkzeug.exceptions import BadRequestKeyError +from utils import send_feedback_email API_DOCS = 'https://github.com/adsabs/adsabs-dev-api' ERROR_UNVERIFIED_CAPTCHA = dict( @@ -52,13 +53,23 @@ def prettify_post(post_data): except BadRequestKeyError: raise - icon_emoji = ':goberserk:' + feedback_email = 'no email sent' + if post_data.has_key('_replyto') and post_data.has_key('name'): + try: + res = send_feedback_email(name, reply_to, comments) + feedback_email = 'success' + except: + pass + feedback_email = 'failed' + + icon_emoji = current_app.config['FEEDBACK_SLACK_EMOJI'] text = [ '```Incoming Feedback```', '*Commenter*: {}'.format(name), '*e-mail*: {}'.format(reply_to), - '*Feedback*: {}'.format(comments) + '*Feedback*: {}'.format(comments), + '*sent to adshelp*: {}'.format(feedback_email) ] used = ['channel', 'username', 'name', '_replyto', 'comments', 'g-recaptcha-response'] diff --git a/adsws/tests/test_feedback.py b/adsws/tests/test_feedback.py index 78d59e4..643c4c5 100644 --- a/adsws/tests/test_feedback.py +++ b/adsws/tests/test_feedback.py @@ -252,14 +252,16 @@ def test_parser_parses_content(self): """ Tests that the input given is parsed sensibly for slack """ + emoji = current_app.config['FEEDBACK_SLACK_EMOJI'] post_data_sent = { 'text': '```Incoming Feedback```\n' '*Commenter*: Commenter\n' '*e-mail*: commenter@email.com\n' - '*Feedback*: Why are my citations missing?', + '*Feedback*: Why are my citations missing?\n' + '*sent to adshelp*: failed', 'username': 'TownCrier', 'channel': '#feedback', - 'icon_emoji': ':goberserk:' + 'icon_emoji': emoji } form_data = { @@ -278,17 +280,18 @@ def test_can_send_abritrary_keyword_values(self): Test the end point is not restrictive on the keyword values it can create content for. """ - + emoji = current_app.config['FEEDBACK_SLACK_EMOJI'] post_data_sent = { 'text': '```Incoming Feedback```\n' '*Commenter*: Commenter\n' '*e-mail*: commenter@email.com\n' '*Feedback*: Why are my citations missing?\n' + '*sent to adshelp*: failed\n' '*IP Address*: 127.0.0.1\n' '*Browser*: Firefox v42', 'username': 'TownCrier', 'channel': '#feedback', - 'icon_emoji': ':goberserk:' + 'icon_emoji': emoji } form_data = {