diff --git a/app/__init__.py b/app/__init__.py
index 26b0c27fb9..4958739aa4 100644
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -134,6 +134,7 @@ def create_app():
from app.api.auth import ticket_blueprint, authorised_blueprint
from app.api.admin_translations import admin_blueprint
from app.api.orders import alipay_blueprint
+ from app.api.settings import admin_misc_routes
app.register_blueprint(api_v1)
app.register_blueprint(event_copy)
@@ -151,6 +152,7 @@ def create_app():
app.register_blueprint(authorised_blueprint)
app.register_blueprint(admin_blueprint)
app.register_blueprint(alipay_blueprint)
+ app.register_blueprint(admin_misc_routes)
sa.orm.configure_mappers()
diff --git a/app/api/helpers/mail.py b/app/api/helpers/mail.py
index b8d434165c..e987263349 100644
--- a/app/api/helpers/mail.py
+++ b/app/api/helpers/mail.py
@@ -11,7 +11,8 @@
from app.api.helpers.utilities import string_empty, get_serializer, str_generator
from app.models.mail import Mail, USER_CONFIRM, NEW_SESSION, USER_CHANGE_EMAIL, SESSION_ACCEPT_REJECT, EVENT_ROLE, \
AFTER_EVENT, MONTHLY_PAYMENT_EMAIL, MONTHLY_PAYMENT_FOLLOWUP_EMAIL, EVENT_EXPORTED, EVENT_EXPORT_FAIL, \
- EVENT_IMPORTED, EVENT_IMPORT_FAIL, TICKET_PURCHASED_ATTENDEE, TICKET_CANCELLED, TICKET_PURCHASED, USER_EVENT_ROLE
+ EVENT_IMPORTED, EVENT_IMPORT_FAIL, TICKET_PURCHASED_ATTENDEE, TICKET_CANCELLED, TICKET_PURCHASED, USER_EVENT_ROLE, \
+ TEST_MAIL
from app.models.user import User
@@ -289,6 +290,14 @@ def send_import_mail(email, event_name=None, error_text=None, event_url=None):
)
+def send_test_email(recipient):
+ send_email(to=recipient,
+ action=TEST_MAIL,
+ subject=MAILS[TEST_MAIL]['subject'],
+ html=MAILS[TEST_MAIL]['message']
+ )
+
+
def send_email_change_user_email(user, email):
serializer = get_serializer()
hash_ = str(base64.b64encode(bytes(serializer.dumps([email, str_generator()]), 'utf-8')), 'utf-8')
@@ -298,7 +307,6 @@ def send_email_change_user_email(user, email):
def send_email_to_attendees(order, purchaser_id, attachments=None):
-
for holder in order.ticket_holders:
if holder.user and holder.user.id == purchaser_id:
# Ticket holder is the purchaser
diff --git a/app/api/helpers/system_mails.py b/app/api/helpers/system_mails.py
index cc3347ea08..c7da2edc34 100644
--- a/app/api/helpers/system_mails.py
+++ b/app/api/helpers/system_mails.py
@@ -7,7 +7,7 @@
SESSION_SCHEDULE, NEXT_EVENT, EVENT_PUBLISH, AFTER_EVENT, USER_CHANGE_EMAIL, USER_REGISTER_WITH_PASSWORD, \
TICKET_PURCHASED, EVENT_EXPORTED, EVENT_EXPORT_FAIL, MAIL_TO_EXPIRED_ORDERS, MONTHLY_PAYMENT_EMAIL, \
MONTHLY_PAYMENT_FOLLOWUP_EMAIL, EVENT_IMPORTED, EVENT_IMPORT_FAIL, TICKET_PURCHASED_ORGANIZER, TICKET_CANCELLED, \
- TICKET_PURCHASED_ATTENDEE, PASSWORD_CHANGE, PASSWORD_RESET_AND_VERIFY, USER_EVENT_ROLE
+ TICKET_PURCHASED_ATTENDEE, PASSWORD_CHANGE, PASSWORD_RESET_AND_VERIFY, USER_EVENT_ROLE, TEST_MAIL
MAILS = {
EVENT_PUBLISH: {
@@ -254,5 +254,12 @@
u"The error was as follows -
" +
u"
{error_text}"
)
+ },
+ TEST_MAIL: {
+ 'recipient': 'User',
+ 'subject': u'Test Mail Subject',
+ 'message': (
+ u"This is a Test E-mail."
+ )
}
}
diff --git a/app/api/settings.py b/app/api/settings.py
index 53cfb30492..20ed8838d5 100644
--- a/app/api/settings.py
+++ b/app/api/settings.py
@@ -1,5 +1,5 @@
from flask import current_app as app
-from flask import request
+from flask import jsonify, request, Blueprint, make_response
from flask_jwt import current_identity as current_user, _jwt_required
from flask_rest_jsonapi import ResourceDetail
@@ -8,6 +8,12 @@
from app.models import db
from app.models.setting import Setting
from app.settings import refresh_settings
+from app.api.helpers.mail import send_test_email
+from app.api.helpers.errors import UnprocessableEntityError
+from app.api.helpers.permissions import is_admin
+
+
+admin_misc_routes = Blueprint('admin_misc', __name__, url_prefix='/v1')
class Environment:
@@ -51,3 +57,14 @@ def before_get(self, args, kwargs):
def after_patch(self, result):
# Update settings cache after PATCH
refresh_settings()
+
+
+@admin_misc_routes.route('/test-mail', methods=['POST'])
+@is_admin
+def test_email_setup():
+ recipient = request.json.get('recipient')
+ if not recipient:
+ return UnprocessableEntityError({'source': 'recipient'},
+ 'Required parameter recipient not found').respond()
+ send_test_email(recipient)
+ return make_response(jsonify(message='Test mail sent, please verify delivery'), 200)
diff --git a/app/models/mail.py b/app/models/mail.py
index 8d76ab7015..99191591f2 100644
--- a/app/models/mail.py
+++ b/app/models/mail.py
@@ -31,6 +31,7 @@
MONTHLY_PAYMENT_FOLLOWUP_EMAIL = 'Monthly Payment Follow Up Email'
EVENT_IMPORTED = 'Event Imported'
EVENT_IMPORT_FAIL = 'Event Import Failed'
+TEST_MAIL = 'Test Mail'
class Mail(db.Model):