Skip to content

Commit f6092d6

Browse files
committed
Merge branch 'develop' into HEAD
2 parents b9cb166 + a4d4bbd commit f6092d6

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

config.env.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@
2323
# LDAP config
2424
LDAP_BIND_DN = environ.get("PACKET_LDAP_BIND_DN", None)
2525
LDAP_BIND_PASS = environ.get("PACKET_LDAP_BIND_PASS", None)
26+
27+
# Slack URL for pushing to #general
28+
SLACK_WEBHOOK_URL = environ.get("PACKET_SLACK_URL", None)

packet/models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ def did_sign(self, username, is_csh):
103103
# The user must be a misc CSHer that hasn't signed this packet or an off-floor freshmen
104104
return False
105105

106+
def is_100(self):
107+
"""
108+
Checks if this packet has reached 100%
109+
"""
110+
return self.signatures_required().total == self.signatures_recieved().total
111+
106112
@classmethod
107113
def open_packets(cls):
108114
"""

packet/routes/api.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from packet import app, db
2-
from packet.utils import before_request, packet_auth
2+
from packet.utils import before_request, packet_auth, notify_slack
33
from packet.models import Packet, MiscSignature
44

55

@@ -10,25 +10,32 @@ def sign(packet_id, info):
1010
packet = Packet.by_id(packet_id)
1111

1212
if packet is not None and packet.is_open():
13+
was_100 = packet.is_100()
1314
if app.config["REALM"] == "csh":
1415
# Check if the CSHer is an upperclassman and if so, sign that row
1516
for sig in filter(lambda sig: sig.member == info["uid"], packet.upper_signatures):
1617
sig.signed = True
1718
db.session.commit()
1819
app.logger.info("Member {} signed packet {} as an upperclassman".format(info["uid"], packet_id))
20+
if not was_100 and packet.is_100():
21+
notify_slack(packet.freshman.name)
1922
return "Success: Signed Packet: " + packet.freshman_username
2023

2124
# The CSHer is a misc so add a new row
2225
db.session.add(MiscSignature(packet=packet, member=info["uid"]))
2326
db.session.commit()
2427
app.logger.info("Member {} signed packet {} as a misc".format(info["uid"], packet_id))
28+
if not was_100 and packet.is_100():
29+
notify_slack(packet.freshman.name)
2530
return "Success: Signed Packet: " + packet.freshman_username
2631
else:
2732
# Check if the freshman is onfloor and if so, sign that row
2833
for sig in filter(lambda sig: sig.freshman_username == info["uid"], packet.fresh_signatures):
2934
sig.signed = True
3035
db.session.commit()
3136
app.logger.info("Freshman {} signed packet {}".format(info["uid"], packet_id))
37+
if not was_100 and packet.is_100():
38+
notify_slack(packet.freshman.name)
3239
return "Success: Signed Packet: " + packet.freshman_username
3340

3441
app.logger.warn("Failed to add {}'s signature to packet {}".format(info["uid"], packet_id))

packet/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,15 @@ def wrapped_function(*args, **kwargs):
8787
return func(*args, **kwargs)
8888

8989
return wrapped_function
90+
91+
def notify_slack(name: str):
92+
"""
93+
Sends a congratulate on sight decree to Slack
94+
"""
95+
if app.config["SLACK_WEBHOOK_URL"] is None:
96+
app.logger.warn("SLACK_WEBHOOK_URL not configured, not sending message to slack.")
97+
return
98+
99+
msg = f'{name} got :100: on packet. Shower on sight.'
100+
requests.put(app.config["SLACK_WEBHOOK_URL"], json={'text':msg})
101+
app.logger.info("Posted 100% notification to slack for " + name)

0 commit comments

Comments
 (0)