Skip to content

Commit

Permalink
Merge pull request #102 from ehenneken/github71
Browse files Browse the repository at this point in the history
Email for BBB feedback
  • Loading branch information
romanchyla committed Aug 3, 2016
2 parents 40cfb83 + a4ef1d4 commit 63aba55
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
6 changes: 4 additions & 2 deletions adsws/feedback/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
CORS_METHODS = ['POST', 'GET']
12 changes: 11 additions & 1 deletion adsws/feedback/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -11,4 +21,4 @@ def err(error_dictionary):
:return: tuple of error message and error number
"""
return {'error': error_dictionary['body']}, error_dictionary['number']
return {'error': error_dictionary['body']}, error_dictionary['number']
15 changes: 13 additions & 2 deletions adsws/feedback/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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']
Expand Down
11 changes: 7 additions & 4 deletions adsws/tests/test_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand Down

0 comments on commit 63aba55

Please sign in to comment.