Skip to content

Commit f428db7

Browse files
authored
Merge pull request #36 from ComputerScienceHouse/develop
Allow connections to LDAP with self-signed certs
2 parents 9fce821 + aa1c04d commit f428db7

10 files changed

Lines changed: 314 additions & 276 deletions

File tree

.pylintrc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ disable =
1414
global-statement,
1515
cyclic-import,
1616
locally-disabled,
17-
file-ignored
17+
file-ignored,
18+
inconsistent-return-statements,
19+
no-else-return
1820

1921
[REPORTS]
2022
output-format = text
@@ -28,6 +30,9 @@ single-line-if-stmt = no
2830
no-space-check = trailing-comma,dict-separator
2931
max-module-lines = 1000
3032
indent-string = ' '
33+
string-quote=single-avoid-escape
34+
triple-quote=single
35+
docstring-quote=double
3136

3237
[MISCELLANEOUS]
3338
notes = FIXME,XXX,TODO

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ python:
55
install:
66
- "pip install -r requirements.txt"
77
script:
8-
- "pylint selections"
8+
- "pylint --load-plugins pylint_quotes selections"

requirements.txt

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,52 @@
1-
alabaster==0.7.10
1+
alabaster==0.7.12
22
alembic==0.9.9
3-
asn1crypto==0.24.0
4-
astroid==1.6.2
5-
Beaker==1.9.0
3+
astroid==2.4.1
4+
Beaker==1.11.0
65
blinker==1.4
7-
certifi==2018.1.18
6+
certifi==2020.4.5.1
87
cffi==1.14.0
98
chardet==3.0.4
10-
click==6.7
11-
cryptography==2.3
9+
click==7.1.2
10+
cryptography==2.9.2
1211
csh-ldap==2.2.0
13-
Flask==1.0
12+
dnspython==1.16.0
13+
Flask==1.1.2
1414
Flask-Migrate==2.1.1
1515
Flask-pyoidc==1.2.0
1616
Flask-SQLAlchemy==2.3.2
17-
future==0.16.0
17+
future==0.18.2
1818
gunicorn==19.7.1
19-
idna==2.6
20-
isort==4.3.4
21-
itsdangerous==0.24
22-
Jinja2~=2.10.3
23-
lazy-object-proxy==1.3.1
24-
lxml==4.2.1
25-
Mako==1.0.7
26-
MarkupSafe==1.0
19+
idna==2.9
20+
isort==4.3.21
21+
itsdangerous==1.1.0
22+
Jinja2==2.11.2
23+
lazy-object-proxy==1.4.3
24+
lxml==4.5.0
25+
Mako==1.1.2
26+
MarkupSafe==1.1.1
2727
mccabe==0.6.1
2828
oic==0.11.0.1
29-
Pillow==6.2.2
30-
pyasn1==0.4.2
31-
pyasn1-modules==0.2.1
32-
pycparser==2.18
33-
pycryptodomex==3.5.1
34-
pyjwkest==1.4.0
35-
pyldap==3.0.0.post1
36-
pylint==1.8.3
29+
Pillow==7.1.2
30+
pyasn1==0.4.8
31+
pyasn1-modules==0.2.8
32+
pycparser==2.20
33+
pycryptodomex==3.9.7
34+
pyjwkest==1.4.2
35+
pylint==2.5.2
36+
pylint-quotes==0.2.1
3737
PyMySQL==0.8.0
38-
pyOpenSSL==17.5.0
39-
python-dateutil==2.7.2
38+
pyOpenSSL==19.1.0
39+
python-dateutil==2.8.1
4040
python-docx==0.8.6
41-
python-editor==1.0.3
41+
python-editor==1.0.4
4242
python-ldap==3.0.0
4343
python-resize-image==1.1.11
44-
requests==2.20.0
45-
six==1.11.0
44+
requests==2.23.0
4645
sentry-sdk==0.14.3
47-
SQLAlchemy~=1.3.0
48-
urllib3==1.24.2
49-
Werkzeug==0.15.5
50-
wrapt==1.10.11
46+
six==1.14.0
47+
SQLAlchemy==1.3.17
48+
srvlookup==2.0.0
49+
toml==0.10.1
50+
urllib3==1.25.9
51+
Werkzeug==1.0.1
52+
wrapt==1.12.1

selections/__init__.py

Lines changed: 61 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# pylint: disable=wrong-import-position
12
import os
23
from collections import defaultdict
34

5+
import ldap
46
import csh_ldap
57
from flask import Flask
68
from flask_migrate import Migrate
@@ -14,15 +16,16 @@
1416
app = 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'))
1921
else:
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

@@ -46,52 +49,55 @@
4649
from selections.utils import before_request, get_member_info
4750

4851

49-
@app.route("/")
52+
@app.route('/')
5053
@auth.oidc_auth
5154
@before_request
5255
def 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

112139
application = app

0 commit comments

Comments
 (0)