Skip to content

Commit c874b46

Browse files
committed
gatekeep
1 parent d3a0280 commit c874b46

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

conditional/__init__.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import structlog
55
from csh_ldap import CSHLDAP
6-
from flask import Flask, redirect, render_template, g
6+
from flask import Flask, redirect, render_template, request, g
77
from flask_migrate import Migrate
88
from flask_gzip import Gzip
99
from flask_pyoidc.flask_pyoidc import OIDCAuthentication
@@ -56,7 +56,14 @@ def start_of_year():
5656

5757

5858
# pylint: disable=C0413
59-
from .models.models import UserLog
59+
from .models.models import (
60+
CommitteeMeeting,
61+
MemberCommitteeAttendance,
62+
MemberHouseMeetingAttendance,
63+
MemberSeminarAttendance,
64+
TechnicalSeminar,
65+
UserLog,
66+
)
6067

6168

6269
# Configure Logging
@@ -159,6 +166,33 @@ def health():
159166
return {'status': 'ok'}
160167

161168

169+
@app.route("/gatekeep", methods=['POST'])
170+
def gatekeep_status():
171+
post_data = request.get_json()
172+
if post_data['token'] != app.config["VOTE_TOKEN"]:
173+
return "Users cannot access this page", 403
174+
user_name = post_data['username']
175+
# number of committee meetings attended
176+
c_meetings = len([m.meeting_id for m in
177+
MemberCommitteeAttendance.query.filter(
178+
MemberCommitteeAttendance.uid == user_name
179+
) if CommitteeMeeting.query.filter(
180+
CommitteeMeeting.id == m.meeting_id).first().approved])
181+
# technical seminar total
182+
t_seminars = len([s.seminar_id for s in
183+
MemberSeminarAttendance.query.filter(
184+
MemberSeminarAttendance.uid == user_name
185+
) if TechnicalSeminar.query.filter(
186+
TechnicalSeminar.id == s.seminar_id).first().approved])
187+
# house meeting total
188+
h_meetings = len([(m.meeting_id, m.attendance_status) for m in
189+
MemberHouseMeetingAttendance.query.filter(
190+
MemberHouseMeetingAttendance.uid == user_name)])
191+
result = c_meetings >= 6 and t_seminars >= 2 and h_meetings >= 6
192+
return {"result": result}, 200
193+
194+
195+
162196
@app.errorhandler(404)
163197
@app.errorhandler(500)
164198
@auth.oidc_auth("default")

config.env.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@
5252

5353
# General config
5454
DUES_PER_SEMESTER = env.get("CONDITIONAL_DUES_PER_SEMESTER", 80)
55+
56+
# Vote config
57+
VOTE_TOKEN = env.get("CONDITIONAL_VOTE_TOKEN", "")

0 commit comments

Comments
 (0)