1+ # pylint: disable=wrong-import-position
12import os
23from collections import defaultdict
34
5+ import ldap
46import csh_ldap
57from flask import Flask
68from flask_migrate import Migrate
1416app = Flask (__name__ )
1517
1618# Check if deployed on OpenShift, if so use environment.
17- if os .path .exists (os .path .join (os .getcwd (), " config.py" )):
18- app .config .from_pyfile (os .path .join (os .getcwd (), " config.py" ))
19+ if os .path .exists (os .path .join (os .getcwd (), ' config.py' )):
20+ app .config .from_pyfile (os .path .join (os .getcwd (), ' config.py' ))
1921else :
20- app .config .from_pyfile (os .path .join (os .getcwd (), " config.env.py" ))
22+ app .config .from_pyfile (os .path .join (os .getcwd (), ' config.env.py' ))
2123
22- auth = OIDCAuthentication (app , issuer = app .config [" OIDC_ISSUER" ],
23- client_registration_info = app .config [" OIDC_CLIENT_CONFIG" ])
24+ auth = OIDCAuthentication (app , issuer = app .config [' OIDC_ISSUER' ],
25+ client_registration_info = app .config [' OIDC_CLIENT_CONFIG' ])
2426
2527# Create a connection to CSH LDAP
28+ ldap .set_option (ldap .OPT_X_TLS_REQUIRE_CERT , ldap .OPT_X_TLS_ALLOW )
2629_ldap = csh_ldap .CSHLDAP (
2730 app .config ['LDAP_BIND_DN' ], app .config ['LDAP_BIND_PASS' ])
2831
4649from selections .utils import before_request , get_member_info
4750
4851
49- @app .route ("/" )
52+ @app .route ('/' )
5053@auth .oidc_auth
5154@before_request
5255def main (info = None ):
53- is_evals = " eboard-evaluations" in info ['member_info' ]['group_list' ]
54- is_rtp = " rtp" in info ['member_info' ]['group_list' ]
55- member = members .query .filter_by (username = info ['uid' ]).first ()
56+ is_evals = ' eboard-evaluations' in info ['member_info' ]['group_list' ]
57+ is_rtp = ' rtp' in info ['member_info' ]['group_list' ]
58+ member = Members .query .filter_by (username = info ['uid' ]).first ()
5659
57- all_applications = applicant .query .all ()
58- all_users = [u .username for u in members .query .all ()]
60+ all_applications = Applicant .query .all ()
61+ all_users = [u .username for u in Members .query .all ()]
5962
6063 averages = {}
6164 reviewers = defaultdict (list )
6265 evaluated = {}
63- for application in all_applications :
66+ for applicant in all_applications :
6467 score_sum = 0
65- results = submission .query .filter_by (
66- application = application .id ,
67- medium = " Paper" ).all ()
68- phone_r = submission .query .filter_by (
69- application = application .id ,
70- medium = " Phone" ).first ()
68+ results = Submission .query .filter_by (
69+ application = applicant .id ,
70+ medium = ' Paper' ).all ()
71+ phone_r = Submission .query .filter_by (
72+ application = applicant .id ,
73+ medium = ' Phone' ).first ()
7174 for result in results :
7275 score_sum += int (result .score )
73- reviewers [application .id ].append (result .member )
74- reviewers [application .id ] = sorted (reviewers [application .id ])
76+ reviewers [applicant .id ].append (result .member )
77+ reviewers [applicant .id ] = sorted (reviewers [applicant .id ])
7578 if len (results ) != 0 :
7679 avg = int (score_sum / len (results ))
7780 if phone_r :
7881 avg += phone_r .score
79- averages [application .id ] = avg
82+ averages [applicant .id ] = avg
8083 else :
81- averages [application .id ] = 0
82- reviewers [application .id ] = []
83- evaluated [application .id ] = bool (submission .query .filter_by (application = application .id , medium = " Phone" ).all ())
84+ averages [applicant .id ] = 0
85+ reviewers [applicant .id ] = []
86+ evaluated [applicant .id ] = bool (Submission .query .filter_by (application = applicant .id , medium = ' Phone' ).all ())
8487
85- if member and member .team or is_evals or is_rtp :
86- team = members .query .filter_by (team = member .team )
87- reviewed_apps = [a .application for a in submission .query .filter_by (
88+ if member and member .team :
89+ team = Members .query .filter_by (team = member .team )
90+ reviewed_apps = [a .application for a in Submission .query .filter_by (
8891 member = info ['uid' ]).all ()]
89- applications = [{
90- "id" : a .id ,
91- "gender" : a .gender ,
92- "reviewed" : a .id in reviewed_apps ,
93- "interview" : a .phone_int ,
94- "review_count" : submission .query .filter_by (application = a .id ).count ()} for a in applicant .query .filter_by (team = member .team ).all ()]
92+ applications = [
93+ {
94+ 'id' : a .id ,
95+ 'gender' : a .gender ,
96+ 'reviewed' : a .id in reviewed_apps ,
97+ 'interview' : a .phone_int ,
98+ 'review_count' : Submission .query .filter_by (application = a .id ).count ()
99+ } for a in Applicant .query .filter_by (team = member .team ).all ()
100+ ]
95101
96102 return render_template (
97103 'index.html' ,
@@ -104,9 +110,30 @@ def main(info=None):
104110 averages = averages ,
105111 evaluated = evaluated ,
106112 reviewers = reviewers )
113+ elif is_evals or is_rtp :
114+ all_users .append (info ['uid' ])
115+ return render_template (
116+ 'index.html' ,
117+ info = info ,
118+ all_applications = all_applications ,
119+ all_users = all_users ,
120+ averages = averages ,
121+ evaluated = evaluated ,
122+ reviewers = reviewers )
123+ else :
124+ return render_template (
125+ 'index.html' ,
126+ info = info ,
127+ all_users = all_users )
128+
129+
130+ @app .route ('/logout' )
131+ @auth .oidc_logout
132+ def logout ():
133+ return redirect ('/' , 302 )
107134
108135
109- if __name__ == " __main__" :
136+ if __name__ == ' __main__' :
110137 app .run ()
111138
112139application = app
0 commit comments