Skip to content

Commit 2230d0f

Browse files
committed
Prompting for Signature, and making call
1 parent 8c4d510 commit 2230d0f

File tree

7 files changed

+53
-11
lines changed

7 files changed

+53
-11
lines changed

packet/packet.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,32 @@
22
from .models import Freshman, UpperSignature, FreshSignature, MiscSignature, db
33

44

5-
def sign(member_username, freshman_username):
5+
# Signing Function
6+
def sign(signer_username, freshman_username):
67
freshman = Freshman.query.filter_by(rit_username=freshman_username).first()
78
if freshman is None:
89
return False
9-
1010
packet = freshman.current_packet()
1111
if packet is None:
1212
return False
1313
if not packet.is_open():
1414
return False
1515

16-
upper_signature = UpperSignature.query.filter_by(member=member_username).first()
17-
fresh_signature = FreshSignature.query.filter_by(freshman_username=member_username).first()
16+
try:
17+
upper_signature = UpperSignature.query.filter_by(member=signer_username)[0]
18+
except IndexError:
19+
upper_signature = None
20+
try:
21+
fresh_signature = FreshSignature.query.filter_by(freshman=signer_username)[0]
22+
except IndexError:
23+
fresh_signature = None
24+
1825
if upper_signature:
1926
upper_signature.signed = True
2027
elif fresh_signature:
2128
fresh_signature.signed = True
2229
else:
23-
db.session.add(MiscSignature(packet.id, member_username, datetime.now(), packet))
30+
db.session.add(MiscSignature(packet.id, signer_username, datetime.now(), packet))
2431
db.session.commit()
2532

2633
return True

packet/routes/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
from packet.packet import sign
44

55

6-
@app.route("/api/v1/<member_username>/sign/<packet_username>")
6+
@app.route("/api/v1/<member_username>/sign/<packet_username>", methods=["POST"])
77
@auth.oidc_auth
88
@before_request
99
def sign(member_username, packet_username, info):
10-
if info.uid != member_username:
10+
if info['uid'] != member_username:
1111
if info.member_info:
12-
if "eboard-evaluations" not in info.member_info.group_list:
12+
if "eboard-evaluations" not in info['member_info']['group_list']:
1313
return "Error: You are not evals"
1414
else:
1515
return "Error: UID Submission Mismatch"

packet/static/js/signing.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
$(document).ready(function () {
2+
3+
$('.sign-button').click(function () {
4+
var packetData = $(this).get(0).dataset;
5+
var userData = $("#userInfo").val();
6+
console.log(userData);
7+
swal({
8+
title: "Are you sure?",
9+
text: "Once a packet is signed it can only be unsigned from request to the Evals Director",
10+
icon: "warning",
11+
buttons: true,
12+
dangerMode: true,
13+
})
14+
.then((willSign) => {
15+
if (willSign) {
16+
$.ajax({
17+
url: "/api/v1/" + userData + "/sign/" + packetData.freshman_uid,
18+
method: "POST",
19+
success: function (data) {
20+
swal("Congratulations or I'm Sorry\nYou've signed " + packetData.freshman_name + "'s packet", {
21+
icon: "success",
22+
});
23+
}
24+
});
25+
}
26+
});
27+
});
28+
29+
});

packet/templates/active_packets.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ <h3 class="page-title">Active Packets</h3>
3131
{{ packet.freshman.name }}
3232
</td>
3333
<td>
34-
<span class="glyphicon glyphicon-ok-sign green eval-info-status"></span>
3534
{{ packet.signatures_received() }}
3635
</td>
3736
<td class="sign-packet" align="right">
3837
{# if not signed #}
39-
<button class="btn btn-primary">Sign</button>
38+
<button class="btn btn-primary sign-button"
39+
data-freshman_uid="{{ packet.freshman.rit_username }}"
40+
data-freshman_name="{{ packet.freshman.name }}">Sign
41+
</button>
4042
{# else if signed #}
4143
<button class="btn btn-primary" disabled="disabled"><i
4244
class="fa fa-check"></i>&nbsp;Signed
@@ -55,7 +57,6 @@ <h3 class="page-title">Active Packets</h3>
5557
</div>
5658
{% else %}
5759
<div class="alert alert-info" role="alert">
58-
<span class="glyphicon glyphicon-info-sign white" style="padding-right:5px"></span>
5960
There are currently no active packets.
6061
</div>
6162
{% endif %}

packet/templates/include/head.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet"/>
2424

25+
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
26+
2527
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
2628

2729
<link rel="stylesheet" href="/static/css/packet.css">

packet/templates/include/nav.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
</a>
2626

2727
<div class="dropdown-menu" aria-labelledby="user01">
28+
<input id="userInfo" hidden value="{{ info.uid }}">
2829
{% if info.realm == "csh" %}
2930
<a class="dropdown-item" href="/">Profile</a>
3031
<a class="dropdown-item" href="https://themeswitcher.csh.rit.edu/">Theme</a>

packet/templates/include/scripts.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
1111

12+
<script src="/static/js/signing.js"></script>
13+
1214
<script type="text/javascript">
1315
$(document).ready(function(){
1416
$('[data-toggle="tooltip"]').tooltip()

0 commit comments

Comments
 (0)