diff --git a/frontend/scss/components/buttons.scss b/frontend/scss/components/buttons.scss index 7147bb87..bec420ce 100644 --- a/frontend/scss/components/buttons.scss +++ b/frontend/scss/components/buttons.scss @@ -11,4 +11,10 @@ button { &.signed-button { float: right; } + + @media screen and (min-width: 992px) { + &.report-button { + margin-top: 0.5rem !important; + } + } } diff --git a/packet/commands.py b/packet/commands.py index 10d9bb98..4237c61f 100644 --- a/packet/commands.py +++ b/packet/commands.py @@ -7,7 +7,7 @@ import csv import click -from packet.mail import send_mail +from packet.mail import send_start_packet_mail from . import app, db from .models import Freshman, Packet, FreshSignature, UpperSignature, MiscSignature from .ldap import ldap_get_eboard_role, ldap_get_active_rtps, ldap_get_3das, ldap_get_webmasters, \ @@ -131,7 +131,7 @@ def create_packets(freshmen_csv): for freshman in Freshman.query.filter(Freshman.rit_username.in_(freshmen_in_csv)).all(): packet = Packet(freshman=freshman, start=start, end=end) db.session.add(packet) - send_mail(packet) + send_start_packet_mail(packet) for member in all_upper: sig = UpperSignature(packet=packet, member=member.uid) diff --git a/packet/mail.py b/packet/mail.py index 077c6793..c7a653e1 100644 --- a/packet/mail.py +++ b/packet/mail.py @@ -6,7 +6,7 @@ mail = Mail(app) -def send_mail(packet): +def send_start_packet_mail(packet): if app.config['MAIL_PROD']: recipients = ["<" + packet.freshman.rit_username + "@rit.edu>"] msg = Message(subject="CSH Packet Starts " + packet.start.strftime('%A, %B %-d'), @@ -17,3 +17,19 @@ def send_mail(packet): msg.body = render_template(template + '.txt', packet=packet) msg.html = render_template(template + '.html', packet=packet) mail.send(msg) + + +def send_report_mail(form_results, reporter): + if app.config['MAIL_PROD']: + recipients = [""] + msg = Message(subject="Packet Report", + sender=app.config.get("MAIL_USERNAME"), + recipients=recipients) + + person = form_results['person'] + report = form_results['report'] + + template = 'mail/report' + msg.body = render_template(template + '.txt', person=person, report=report, reporter=reporter) + msg.html = render_template(template + '.html', person=person, report=report, reporter=reporter) + mail.send(msg) diff --git a/packet/routes/api.py b/packet/routes/api.py index 8866855e..abae590c 100644 --- a/packet/routes/api.py +++ b/packet/routes/api.py @@ -1,8 +1,11 @@ """ Shared API endpoints """ +from flask import request from packet import app, db +from packet.context_processors import get_rit_name +from packet.mail import send_report_mail from packet.utils import before_request, packet_auth, notify_slack from packet.models import Packet, MiscSignature @@ -36,6 +39,16 @@ def sign(packet_id, info): app.logger.warn("Failed to add {}'s signature to packet {}".format(info["uid"], packet_id)) return "Error: Signature not valid. Reason: Unknown" + +@app.route("/api/v1/report/", methods=["POST"]) +@packet_auth +@before_request +def report(info): + form_results = request.form + send_report_mail(form_results, get_rit_name(info['uid'])) + return "Success: " + get_rit_name(info['uid']) + " sent a report" + + def commit_sig(packet, was_100): db.session.commit() if not was_100 and packet.is_100(): diff --git a/packet/static/js/report.js b/packet/static/js/report.js new file mode 100644 index 00000000..2154bd84 --- /dev/null +++ b/packet/static/js/report.js @@ -0,0 +1,50 @@ +const dialogs = Swal.mixin({ + customClass: { + confirmButton: 'btn m-1 btn-primary', + cancelButton: 'btn btn-light', + input: 'form-control' + }, + buttonsStyling: false, + confirmButtonText: 'Next →', + showCancelButton: true, +}); + +$("#freshman-report").click(function () { + dialogs.queue([ + { + title: 'Who are you reporting?', + input: 'text', + text: 'Please give a full name to report' + }, + { + title: 'What happened?', + input: 'textarea', + text: 'What would you like to report?' + } + ]).then((result) => { + if (result.value) { + dialogs.fire({ + title: 'Thank you for reaching out!', + html: + 'Person:
' +
+                    result.value[0] +
+                    '
' + + 'Report:
' +
+                    result.value[1] +
+                    '
', + confirmButtonText: 'All Done', + showCancelButton: false, + preConfirm: () => { + $.ajax({ + url: "/api/v1/report/", + method: "POST", + data: { + "person": result.value[0], + "report": result.value[1] + } + }); + } + }) + } + }) +}); diff --git a/packet/templates/active_packets.html b/packet/templates/active_packets.html index 1856c46f..fd5fdf20 100644 --- a/packet/templates/active_packets.html +++ b/packet/templates/active_packets.html @@ -27,10 +27,8 @@

Active Packets

Name - {% if info.realm == "csh" %} - Signatures - Signatures - {% endif %} + Signatures + Signatures Signatures {% if can_sign %} Sign diff --git a/packet/templates/extend/base.html b/packet/templates/extend/base.html index b2410b6e..418e93d6 100644 --- a/packet/templates/extend/base.html +++ b/packet/templates/extend/base.html @@ -26,4 +26,4 @@ {% endblock %} - \ No newline at end of file + diff --git a/packet/templates/include/nav.html b/packet/templates/include/nav.html index 3eefda82..fb8f2a62 100644 --- a/packet/templates/include/nav.html +++ b/packet/templates/include/nav.html @@ -18,6 +18,10 @@ + {% else %} + {% endif %} diff --git a/packet/templates/include/scripts.html b/packet/templates/include/scripts.html index fbc0fd05..af0b7632 100644 --- a/packet/templates/include/scripts.html +++ b/packet/templates/include/scripts.html @@ -10,3 +10,6 @@ +{% if info.realm == "intro" %} + +{% endif %} diff --git a/packet/templates/mail/report.html b/packet/templates/mail/report.html new file mode 100644 index 00000000..dbfedcbc --- /dev/null +++ b/packet/templates/mail/report.html @@ -0,0 +1,10 @@ +{% extends "extend/email.html" %} + +{% block body %} +
+

Hello,

+

{{ reporter }} just made a report against {{ person }}

+

The report reads:

+
{{ report }}
+
+{% endblock %} diff --git a/packet/templates/mail/report.txt b/packet/templates/mail/report.txt new file mode 100644 index 00000000..7a5576c7 --- /dev/null +++ b/packet/templates/mail/report.txt @@ -0,0 +1,7 @@ +Hello, + +{{ reporter }} just made a report against {{ person }} + +The report reads: + +{{ report }}