Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions frontend/scss/components/buttons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ button {
&.signed-button {
float: right;
}

@media screen and (min-width: 992px) {
&.report-button {
margin-top: 0.5rem !important;
}
}
}
4 changes: 2 additions & 2 deletions packet/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 17 additions & 1 deletion packet/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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 = ["<[email protected]>"]
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)
13 changes: 13 additions & 0 deletions packet/routes/api.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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():
Expand Down
50 changes: 50 additions & 0 deletions packet/static/js/report.js
Original file line number Diff line number Diff line change
@@ -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 &rarr;',
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: <pre><code>' +
result.value[0] +
'</code></pre>' +
'Report: <pre><code>' +
result.value[1] +
'</code></pre>',
confirmButtonText: 'All Done',
showCancelButton: false,
preConfirm: () => {
$.ajax({
url: "/api/v1/report/",
method: "POST",
data: {
"person": result.value[0],
"report": result.value[1]
}
});
}
})
}
})
});
6 changes: 2 additions & 4 deletions packet/templates/active_packets.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ <h4 class="page-title">Active Packets</h4>
<thead>
<tr>
<th>Name</th>
{% if info.realm == "csh" %}
<th>Signatures</th>
<th>Signatures</th>
{% endif %}
<th>Signatures</th>
<th>Signatures</th>
<th>Signatures</th>
{% if can_sign %}
<th>Sign</th>
Expand Down
2 changes: 1 addition & 1 deletion packet/templates/extend/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
{% endblock %}

</body>
</html>
</html>
4 changes: 4 additions & 0 deletions packet/templates/include/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<li class="nav-item">
<a class="nav-link" href="{{ url_for("upperclassmen_total") }}">Signatures</a>
</li>
{% else %}
<li class="nav-item">
<button id="freshman-report" class="btn btn-sm btn-default report-button">Report</button>
</li>
{% endif %}

</ul>
Expand Down
3 changes: 3 additions & 0 deletions packet/templates/include/scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/js/select2.min.js"></script>

<script src="{{ url_for('static', filename='js/signing.min.js') }}"></script>
{% if info.realm == "intro" %}
<script src="{{ url_for('static', filename='js/report.min.js') }}"></script>
{% endif %}
10 changes: 10 additions & 0 deletions packet/templates/mail/report.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "extend/email.html" %}

{% block body %}
<div class="container main">
<p>Hello,</p>
<p><code>{{ reporter }}</code> just made a report against <code>{{ person }}</code></p>
<p>The report reads: </p>
<pre><code>{{ report }}</code></pre>
</div>
{% endblock %}
7 changes: 7 additions & 0 deletions packet/templates/mail/report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Hello,

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

The report reads:

{{ report }}