Skip to content

Commit 6b070a6

Browse files
committed
Refactored and fixed packet signing
1 parent 8e70e54 commit 6b070a6

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

packet/routes/api.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
1-
from packet import auth, app
1+
from packet import auth, app, db
22
from packet.utils import before_request
3-
from packet.packet import sign as sign_packet
3+
from packet.models import Packet, MiscSignature
44

55

6-
@app.route("/api/v1/<member_username>/sign/<packet_username>", methods=["POST"])
6+
@app.route("/api/v1/sign/<packet_username>/<packet_id>/", methods=["POST"])
77
@auth.oidc_auth
88
@before_request
9-
def sign(member_username, packet_username, info):
10-
if info['uid'] != member_username:
11-
if info['member_info']:
12-
if "eboard-evaluations" not in info['member_info']['group_list']:
13-
return "Error: You are not evals"
9+
def sign(packet_username, packet_id, info):
10+
packet = Packet.query.filter_by(freshman_username=packet_username, id=packet_id).first()
11+
12+
if packet is not None and packet.is_open():
13+
if app.config["REALM"] == "csh":
14+
# Check if the CSHer is an upperclassman and if so, sign that row
15+
for sig in filter(lambda sig: sig.member == info["uid"], packet.upper_signatures):
16+
sig.signed = True
17+
db.session.commit()
18+
return "Success: Signed Packet: " + packet_username
19+
20+
# The CSHer is a misc so add a new row
21+
db.session.add(MiscSignature(packet=packet, member=info["uid"]))
22+
db.session.commit()
23+
return "Success: Signed Packet: " + packet_username
1424
else:
15-
return "Error: UID Submission Mismatch"
16-
if not sign_packet(member_username, packet_username):
17-
return "Error: Signature not valid. Reason: Unknown"
18-
return "Success: Signed Packet: " + packet_username
25+
# Check if the freshman is onfloor and if so, sign that row
26+
for sig in filter(lambda sig: sig.freshman_username == info["uid"], packet.fresh_signatures):
27+
sig.signed = True
28+
db.session.commit()
29+
return "Success: Signed Packet: " + packet_username
1930

31+
return "Error: Signature not valid. Reason: Unknown"

packet/static/js/signing.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $(document).ready(function () {
1313
.then((willSign) => {
1414
if (willSign) {
1515
$.ajax({
16-
url: "/api/v1/" + userData + "/sign/" + packetData.freshman_uid,
16+
url: "/api/v1/sign/" + packetData.freshman_uid + "/" + packetData.packet_id + "/",
1717
method: "POST",
1818
success: function (data) {
1919
swal("Congratulations or I'm sorry\nYou've signed " + packetData.freshman_name + "'s packet.", {

packet/templates/active_packets.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ <h3 class="page-title">Active Packets</h3>
4848
<td class="sign-packet" align="right">
4949
{% if not packet.did_sign_result and info.uid != packet.rit_username %}
5050
<button class="btn btn-sm btn-primary sign-button"
51-
data-freshman_uid="{{ packet.rit_username }}"
51+
data-freshman_uid="{{ packet.freshman_username }}"
52+
data-packet_id="{{ packet.id }}"
5253
data-freshman_name="{{ get_rit_name(packet.freshman_username) }}">
5354
Sign
5455
</button>

packet/templates/packet.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ <h3>{{ get_rit_name(packet.freshman_username) }}</h3>
1313
{% if can_sign and not did_sign %}
1414
<button class="btn btn-primary sign-button"
1515
data-freshman_uid="{{ packet.freshman_username }}"
16+
data-packet_id="{{ packet.id }}"
1617
data-freshman_name="{{ get_rit_name(packet.freshman_username) }}">Sign
1718
</button>
1819
{% elif did_sign %}

0 commit comments

Comments
 (0)