Skip to content

Commit 34f9f43

Browse files
committed
gatekeep
1 parent d3a0280 commit 34f9f43

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

conditional/__init__.py

Lines changed: 29 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,7 @@ def start_of_year():
5656

5757

5858
# pylint: disable=C0413
59-
from .models.models import UserLog
59+
from .models.models import CommitteeMeeting, MemberCommitteeAttendance, MemberHouseMeetingAttendance, MemberSeminarAttendance, TechnicalSeminar, UserLog
6060

6161

6262
# Configure Logging
@@ -159,6 +159,33 @@ def health():
159159
return {'status': 'ok'}
160160

161161

162+
@app.route("/gatekeep", methods=['POST'])
163+
def gatekeep_status():
164+
post_data = request.get_json()
165+
if post_data['token'] != app.config["VOTE_TOKEN"]:
166+
return "Users cannot access this page", 403
167+
user_name = post_data['username']
168+
# number of committee meetings attended
169+
c_meetings = len([m.meeting_id for m in
170+
MemberCommitteeAttendance.query.filter(
171+
MemberCommitteeAttendance.uid == user_name
172+
) if CommitteeMeeting.query.filter(
173+
CommitteeMeeting.id == m.meeting_id).first().approved])
174+
# technical seminar total
175+
t_seminars = len([s.seminar_id for s in
176+
MemberSeminarAttendance.query.filter(
177+
MemberSeminarAttendance.uid == user_name
178+
) if TechnicalSeminar.query.filter(
179+
TechnicalSeminar.id == s.seminar_id).first().approved])
180+
# house meeting total
181+
h_meetings = len([(m.meeting_id, m.attendance_status) for m in
182+
MemberHouseMeetingAttendance.query.filter(
183+
MemberHouseMeetingAttendance.uid == user_name)])
184+
result = c_meetings >= 6 and t_seminars >= 2 and h_meetings >= 6
185+
return {"result": result}, 200
186+
187+
188+
162189
@app.errorhandler(404)
163190
@app.errorhandler(500)
164191
@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)