Skip to content

Commit

Permalink
Merge pull request #180 from ehenneken/feedback_forms
Browse files Browse the repository at this point in the history
feedback forms machinery
  • Loading branch information
marblestation committed Oct 19, 2020
2 parents ddeea3b + ea8856a commit 6921731
Show file tree
Hide file tree
Showing 17 changed files with 592 additions and 163 deletions.
5 changes: 3 additions & 2 deletions adsws/feedback/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .. import factory
from flask.ext.restful import Api
from flask.ext.cors import CORS
from adsws.feedback.views import SlackFeedback
from adsws.feedback.views import UserFeedback
from flask.ext.mail import Mail


Expand Down Expand Up @@ -35,6 +35,7 @@ def create_app(**kwargs_config):
)

# Add end points
api.add_resource(SlackFeedback, '/slack')
api.add_resource(UserFeedback, '/userfeedback')


return app
20 changes: 19 additions & 1 deletion adsws/feedback/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,27 @@

FEEDBACK_SLACK_END_POINT = 'https://hooks.slack.com/services/TOKEN/TOKEN'
FEEDBACK_SLACK_EMOJI = ':interrobang:'
FEEDBACK_EMAIL = 'adshelp@cfa.harvard.edu'
FORM_SLACK_EMOJI = ':inbox_tray:'
DEFAULT_EMAIL = 'adshelp@cfa.harvard.edu'
# Feedback processing depends on 'origin' attribute supplied in POST data
FEEDBACK_FORMS_ORIGIN = 'user_submission'
BBB_FEEDBACK_ORIGIN = 'bbb_feedback'
# Email template to be applied based on email subject
FEEDBACK_TEMPLATES = {
'Missing References': 'missing_references.txt',
'Associated Articles': 'associated_articles.txt',
'Updated Record': 'updated_record.txt',
'New Record': 'new_record.txt',
'Bumblebee Feedback':'bumblebee_feedback.txt'
}
# Override defaul recipient based on email subject (key)
FEEDBACK_EMAILS = {
'Missing References': 'ads@cfa.harvard.edu',
}

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']

16 changes: 16 additions & 0 deletions adsws/feedback/templates/associated_articles.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
From: {{data.name}}
Address: {{data.email}}

Correlated articles:
{% if 'other' == data.relationship -%}
{{data.custom_name}}: {{data.source}} {{data.target[0]}}
{% else -%}
{{data.relationship}}: {{data.source}} {{data.target[0]}}
{% if data.target|length > 1 -%}
{% for bibcode in data.target[1:] -%}
{% set indent_count = data.relationship | length -%}
{{bibcode | indent(indent_count + 17, true)}}
{% endfor %}
{% endif %}
{% endif %}

3 changes: 3 additions & 0 deletions adsws/feedback/templates/bumblebee_feedback.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% for key, value in data.items() -%}
**{{ key }}** {{ value }}
{% endfor %}
7 changes: 7 additions & 0 deletions adsws/feedback/templates/missing_references.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
From: {{data.name}}
Address: {{data.email}}

Missing references:
{% for reference in data.references -%}
{{reference.citing}}[tab]{{reference.cited}}[tab]{{reference.refstring}}
{% endfor %}
13 changes: 13 additions & 0 deletions adsws/feedback/templates/new_record.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
From: {{data.name}}
Address: {{data.email}}

Abstract data for new record. Summary:

Collection: {{data.new.collection[0]}}

%R {{data.new.bibcode}}
%T {{data.new.title}}
%A {{data.new.author_list}}
%D {{data.new.publicationDate}}
%J {{data.new.publication}}
%B {{data.new.abstract}}
6 changes: 6 additions & 0 deletions adsws/feedback/templates/updated_record.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
From: {{data.name}}
Address: {{data.email}}

Correction for {{data.original.bibcode}}:

{{data.diff}}
18 changes: 12 additions & 6 deletions adsws/feedback/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
"""
from flask import current_app
from flask.ext.mail import Message
import json

def send_feedback_email(name, sender, feedback):
help_email = current_app.config['FEEDBACK_EMAIL']
msg = Message(subject="Bumblebee Feedback from %s (%s)" % (name, sender),
recipients=[help_email],
sender=("adshelp", help_email),
def send_feedback_email(name, sender, subject, data, attachments=None):
# Allow the default recipient to be overriden depending on email subject
email = current_app.config['FEEDBACK_EMAILS'].get(subject, current_app.config['DEFAULT_EMAIL'])
msg = Message(subject="%s from %s (%s)" % (subject, name, sender),
recipients=[email],
sender=("ADS", email),
reply_to=(name, sender),
body=feedback)
body=data)
if attachments:
for attachment in attachments:
# Each entry is a tuple of file name and JSON data
msg.attach(attachment[0], "application/json", json.dumps(attachment[1]))
current_app.extensions['mail'].send(msg)
return msg

Expand Down
Loading

0 comments on commit 6921731

Please sign in to comment.