Skip to content

Commit 25d43f2

Browse files
committed
gatekeep
1 parent d3a0280 commit 25d43f2

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

conditional/__init__.py

Lines changed: 35 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,32 @@ def health():
159166
return {'status': 'ok'}
160167

161168

169+
@app.route("/gatekeep/<username>")
170+
def gatekeep_status(username):
171+
token = request.headers.get("X-VOTE-TOKEN","")
172+
if token != app.config["VOTE_TOKEN"]:
173+
return "Users cannot access this page", 403
174+
# number of committee meetings attended
175+
c_meetings = len([m.meeting_id for m in
176+
MemberCommitteeAttendance.query.filter(
177+
MemberCommitteeAttendance.uid == username
178+
) if CommitteeMeeting.query.filter(
179+
CommitteeMeeting.id == m.meeting_id).first().approved])
180+
# technical seminar total
181+
t_seminars = len([s.seminar_id for s in
182+
MemberSeminarAttendance.query.filter(
183+
MemberSeminarAttendance.uid == username
184+
) if TechnicalSeminar.query.filter(
185+
TechnicalSeminar.id == s.seminar_id).first().approved])
186+
# house meeting total
187+
h_meetings = len([(m.meeting_id, m.attendance_status) for m in
188+
MemberHouseMeetingAttendance.query.filter(
189+
MemberHouseMeetingAttendance.uid == username)])
190+
result = c_meetings >= 6 and t_seminars >= 2 and h_meetings >= 6
191+
return {"result": result}, 200
192+
193+
194+
162195
@app.errorhandler(404)
163196
@app.errorhandler(500)
164197
@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)