diff --git a/ennstatus/__init__.py b/ennstatus/__init__.py --- a/ennstatus/__init__.py +++ b/ennstatus/__init__.py @@ -66,9 +66,6 @@ def create_app(): csrf.init_app(app) moment.init_app(app) - from .status.functions import mail - mail.init_app(app) - from .root.views import root_page app.register_blueprint(root_page) diff --git a/ennstatus/root/functions.py b/ennstatus/root/functions.py --- a/ennstatus/root/functions.py +++ b/ennstatus/root/functions.py @@ -16,113 +16,72 @@ from flask import render_template, current_app, flash -from flask_mail import Mail, Message - -from ennstatus.status.functions import mail +import rt -def send_membership_mail(form): - try: - body = render_template('root/membership_mail.txt', - username=form.username.data, - email=form.email.data, - membership=form.membership.data, - c3l=form.c3l.data, - fullname=form.fullname.data, - street=form.street.data, - zip=form.zip.data, - city=form.city.data, - country=form.country.data, - gpg=form.gpg.data - ) +def create_membership_ticket(form): + url = current_app.config['ENNSTATUS_RT_URL'] + '/REST/1.0' + tracker = rt.Rt(url, + current_app.config['ENNSTATUS_RT_USER'], + current_app.config['ENNSTATUS_RT_PASSWORD'] + ) - recipients = current_app.config['ENNSTATUS_MEMBERSHIP_MAIL'] - with mail.connect() as conn: - for recipient in recipients: - msg = Message( - 'New membership application', - sender='ennstatus@enn.lu' - ) - msg.add_recipient(recipient) - current_app.logger.debug('Before encryption') - current_app.logger.debug(body) - if current_app.extensions['gnupg']: - encrypted_body = str( - current_app.extensions['gnupg'].encrypt( - body, - recipient, - always_trust=True - ) - ) - else: - encrypted_body = None - current_app.logger.debug('After encryption') - current_app.logger.debug(body) - msg.body = encrypted_body if encrypted_body else body - conn.send(msg) - flash('Application successfully submitted!', 'success') - except KeyError: + body = render_template( + 'root/membership_mail.txt', + username=form.username.data, + email=form.email.data, + membership=form.membership.data, + c3l=form.c3l.data, + fullname=form.fullname.data, + street=form.street.data, + zip=form.zip.data, + city=form.city.data, + country=form.country.data, + gpg=form.gpg.data + ) + + tracker.login() + try: + tracker.create_ticket( + Queue=current_app.config['ENNSTATUS_MEMBERSHIP_RT_QUEUE'], + Subject='New membership application: %s' % form.username.data, + Text=body + ) + except: flash( 'Internal server error! Please get in touch with us at info@enn.lu!', 'error' ) - current_app.logger.error('Membership admin not found!') - except AssertionError: - pass - except Exception as e: + finally: + tracker.logout() + + +def create_bridgeprogram_ticket(form): + url = current_app.config['ENNSTATUS_RT_URL'] + '/REST/1.0' + tracker = rt.Rt(url, + current_app.config['ENNSTATUS_RT_USER'], + current_app.config['ENNSTATUS_RT_PASSWORD'] + ) + + body = render_template( + 'root/bridgeprogram_mail.txt', + fullname=form.fullname.data, + email=form.email.data, + bridgename=form.bridgename.data, + duration=form.duration.data, + payment=form.payment.data + ) + tracker.login() + try: + tracker.create_ticket( + Queue=current_app.config['ENNSTATUS_BRIDGEPROGRAM_RT_QUEUE'], + Subject='New bridgeprogram application: %s' % form.email.data, + Text=body + ) + except: flash( 'Internal server error! Please get in touch with us at info@enn.lu!', 'error' ) - current_app.logger.error('Unexpected error: %s' % e, - exc_info=True) - - -def send_bridgeprogram_mail(form): - - try: - body = render_template('root/bridgeprogram_mail.txt', - fullname=form.fullname.data, - email=form.email.data, - bridgename=form.bridgename.data, - duration=form.duration.data, - payment=form.payment.data - ) - - recipients = current_app.config['ENNSTATUS_BRIDGEPROGRAM_MAIL'] - with mail.connect() as conn: - for recipient in recipients: - msg = Message('New bridge program application', - sender='ennstatus@enn.lu') - msg.add_recipient(recipient) - if current_app.extensions['gnupg']: - encrypted_body = str( - current_app.extensions['gnupg'].encrypt( - body, - recipient, - always_trust=True - ) - ) - else: - encrypted_body = None - msg.body = encrypted_body if encrypted_body else body - conn.send(msg) - flash( - 'Application successfully submitted! We will send you an email with further information!', - 'success' - ) - except KeyError: - flash( - 'Internal server error! Please get in touch with us at info@enn.lu', - 'error' - ) - current_app.logger.error('Bridgeprogram admin not found!') - except AssertionError: - pass - except Exception as e: - flash( - 'Internal server error! Please get in touch with us at info@enn.lu!', - 'error' - ) - current_app.logger.error('Unexpected error: %s' % e, - exc_info=True) + finally: + tracker.logout() diff --git a/ennstatus/root/views.py b/ennstatus/root/views.py --- a/ennstatus/root/views.py +++ b/ennstatus/root/views.py @@ -19,8 +19,8 @@ from flask import (Blueprint, render_tem from ennstatus.root.forms import BPMForm, MembershipForm, BridgeprogramForm from ennstatus.root.constants import BPM_ADDRESSES -from ennstatus.root.functions import (send_membership_mail, - send_bridgeprogram_mail) +from ennstatus.root.functions import (create_membership_ticket, + create_bridgeprogram_ticket) root_page = Blueprint('root', __name__) @@ -49,7 +49,7 @@ def bridgeprogram(): if request.method == 'POST': current_app.logger.debug('Validation form') if form.validate_on_submit(): - send_bridgeprogram_mail(form) + create_bridgeprogram_ticket(form) return redirect(url_for('root.bridgeprogram')) return render_template('root/bridgeprogram.html', form=form) @@ -69,7 +69,7 @@ def membership(): if request.method == 'POST': current_app.logger.debug('Validating form') if form.validate_on_submit(): - send_membership_mail(form) + create_membership_ticket(form) return redirect(url_for('root.member')) return render_template('root/membership.html', form=form) diff --git a/ennstatus/status/functions.py b/ennstatus/status/functions.py --- a/ennstatus/status/functions.py +++ b/ennstatus/status/functions.py @@ -22,12 +22,8 @@ from collections import defaultdict from datetime import datetime from flask import current_app -from flask_mail import Mail, Message - from ..api.model import Server -mail = Mail() - def single_server(name): diff --git a/requirements.in b/requirements.in --- a/requirements.in +++ b/requirements.in @@ -2,7 +2,6 @@ Babel click Flask-Bootstrap Flask-HTTPAuth -Flask-Mail Flask-Moment Flask-WTF Flask diff --git a/requirements.txt b/requirements.txt --- a/requirements.txt +++ b/requirements.txt @@ -5,15 +5,13 @@ # pip-compile requirements.in # Babel==2.2.0 -blinker==1.4 # via flask-mail click==6.3 dominate==2.1.17 # via flask-bootstrap Flask-Bootstrap==3.3.5.7 Flask-HTTPAuth==2.7.2 -Flask-Mail==0.9.1 Flask-Moment==0.5.1 Flask-WTF==0.12 -Flask==0.10.1 # via flask-bootstrap, flask-httpauth, flask-mail, flask-moment, flask-wtf +Flask==0.10.1 # via flask-bootstrap, flask-httpauth, flask-moment, flask-wtf itsdangerous==0.24 # via flask Jinja2==2.8 # via flask jsonschema==2.5.1