Skip to content

Commit fe8ef31

Browse files
authored
Merge pull request #151 from devinmatte/report
Report an issue to Evals
2 parents af22d6e + 3ccb94a commit fe8ef31

File tree

11 files changed

+115
-8
lines changed

11 files changed

+115
-8
lines changed

frontend/scss/components/buttons.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ button {
1111
&.signed-button {
1212
float: right;
1313
}
14+
15+
@media screen and (min-width: 992px) {
16+
&.report-button {
17+
margin-top: 0.5rem !important;
18+
}
19+
}
1420
}

packet/commands.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import csv
88
import click
99

10-
from packet.mail import send_mail
10+
from packet.mail import send_start_packet_mail
1111
from . import app, db
1212
from .models import Freshman, Packet, FreshSignature, UpperSignature, MiscSignature
1313
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):
131131
for freshman in Freshman.query.filter(Freshman.rit_username.in_(freshmen_in_csv)).all():
132132
packet = Packet(freshman=freshman, start=start, end=end)
133133
db.session.add(packet)
134-
send_mail(packet)
134+
send_start_packet_mail(packet)
135135

136136
for member in all_upper:
137137
sig = UpperSignature(packet=packet, member=member.uid)

packet/mail.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
mail = Mail(app)
77

88

9-
def send_mail(packet):
9+
def send_start_packet_mail(packet):
1010
if app.config['MAIL_PROD']:
1111
recipients = ["<" + packet.freshman.rit_username + "@rit.edu>"]
1212
msg = Message(subject="CSH Packet Starts " + packet.start.strftime('%A, %B %-d'),
@@ -17,3 +17,19 @@ def send_mail(packet):
1717
msg.body = render_template(template + '.txt', packet=packet)
1818
msg.html = render_template(template + '.html', packet=packet)
1919
mail.send(msg)
20+
21+
22+
def send_report_mail(form_results, reporter):
23+
if app.config['MAIL_PROD']:
24+
recipients = ["<[email protected]>"]
25+
msg = Message(subject="Packet Report",
26+
sender=app.config.get("MAIL_USERNAME"),
27+
recipients=recipients)
28+
29+
person = form_results['person']
30+
report = form_results['report']
31+
32+
template = 'mail/report'
33+
msg.body = render_template(template + '.txt', person=person, report=report, reporter=reporter)
34+
msg.html = render_template(template + '.html', person=person, report=report, reporter=reporter)
35+
mail.send(msg)

packet/routes/api.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
"""
22
Shared API endpoints
33
"""
4+
from flask import request
45

56
from packet import app, db
7+
from packet.context_processors import get_rit_name
8+
from packet.mail import send_report_mail
69
from packet.utils import before_request, packet_auth, notify_slack
710
from packet.models import Packet, MiscSignature
811

@@ -36,6 +39,16 @@ def sign(packet_id, info):
3639
app.logger.warn("Failed to add {}'s signature to packet {}".format(info["uid"], packet_id))
3740
return "Error: Signature not valid. Reason: Unknown"
3841

42+
43+
@app.route("/api/v1/report/", methods=["POST"])
44+
@packet_auth
45+
@before_request
46+
def report(info):
47+
form_results = request.form
48+
send_report_mail(form_results, get_rit_name(info['uid']))
49+
return "Success: " + get_rit_name(info['uid']) + " sent a report"
50+
51+
3952
def commit_sig(packet, was_100):
4053
db.session.commit()
4154
if not was_100 and packet.is_100():

packet/static/js/report.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const dialogs = Swal.mixin({
2+
customClass: {
3+
confirmButton: 'btn m-1 btn-primary',
4+
cancelButton: 'btn btn-light',
5+
input: 'form-control'
6+
},
7+
buttonsStyling: false,
8+
confirmButtonText: 'Next &rarr;',
9+
showCancelButton: true,
10+
});
11+
12+
$("#freshman-report").click(function () {
13+
dialogs.queue([
14+
{
15+
title: 'Who are you reporting?',
16+
input: 'text',
17+
text: 'Please give a full name to report'
18+
},
19+
{
20+
title: 'What happened?',
21+
input: 'textarea',
22+
text: 'What would you like to report?'
23+
}
24+
]).then((result) => {
25+
if (result.value) {
26+
dialogs.fire({
27+
title: 'Thank you for reaching out!',
28+
html:
29+
'Person: <pre><code>' +
30+
result.value[0] +
31+
'</code></pre>' +
32+
'Report: <pre><code>' +
33+
result.value[1] +
34+
'</code></pre>',
35+
confirmButtonText: 'All Done',
36+
showCancelButton: false,
37+
preConfirm: () => {
38+
$.ajax({
39+
url: "/api/v1/report/",
40+
method: "POST",
41+
data: {
42+
"person": result.value[0],
43+
"report": result.value[1]
44+
}
45+
});
46+
}
47+
})
48+
}
49+
})
50+
});

packet/templates/active_packets.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ <h4 class="page-title">Active Packets</h4>
2727
<thead>
2828
<tr>
2929
<th>Name</th>
30-
{% if info.realm == "csh" %}
31-
<th>Signatures</th>
32-
<th>Signatures</th>
33-
{% endif %}
30+
<th>Signatures</th>
31+
<th>Signatures</th>
3432
<th>Signatures</th>
3533
{% if can_sign %}
3634
<th>Sign</th>

packet/templates/extend/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
{% endblock %}
2727

2828
</body>
29-
</html>
29+
</html>

packet/templates/include/nav.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
<li class="nav-item">
1919
<a class="nav-link" href="{{ url_for("upperclassmen_total") }}">Signatures</a>
2020
</li>
21+
{% else %}
22+
<li class="nav-item">
23+
<button id="freshman-report" class="btn btn-sm btn-default report-button">Report</button>
24+
</li>
2125
{% endif %}
2226

2327
</ul>

packet/templates/include/scripts.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/js/select2.min.js"></script>
1111

1212
<script src="{{ url_for('static', filename='js/signing.min.js') }}"></script>
13+
{% if info.realm == "intro" %}
14+
<script src="{{ url_for('static', filename='js/report.min.js') }}"></script>
15+
{% endif %}

packet/templates/mail/report.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% extends "extend/email.html" %}
2+
3+
{% block body %}
4+
<div class="container main">
5+
<p>Hello,</p>
6+
<p><code>{{ reporter }}</code> just made a report against <code>{{ person }}</code></p>
7+
<p>The report reads: </p>
8+
<pre><code>{{ report }}</code></pre>
9+
</div>
10+
{% endblock %}

0 commit comments

Comments
 (0)