|
1 | | -from packet import auth, app |
| 1 | +from packet import auth, app, db |
2 | 2 | from packet.utils import before_request |
3 | | -from packet.packet import sign as sign_packet |
| 3 | +from packet.models import Packet, MiscSignature |
4 | 4 |
|
5 | 5 |
|
6 | | -@app.route("/api/v1/<member_username>/sign/<packet_username>", methods=["POST"]) |
| 6 | +@app.route("/api/v1/sign/<packet_username>/<packet_id>/", methods=["POST"]) |
7 | 7 | @auth.oidc_auth |
8 | 8 | @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 |
14 | 24 | 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 |
19 | 30 |
|
| 31 | + return "Error: Signature not valid. Reason: Unknown" |
0 commit comments