Skip to content

Commit bc8b71c

Browse files
authored
Merge pull request #418 from ComputerScienceHouse/develop
Merge dev into main
2 parents 18cae60 + 66bceec commit bc8b71c

25 files changed

+434
-301
lines changed

.github/workflows/python-app.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515

1616
strategy:
1717
matrix:
18-
python-version: [3.8, 3.9]
18+
python-version: [3.12]
1919

2020
steps:
2121
- name: Install ldap dependencies

.pylintrc

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ disable =
99
duplicate-code,
1010
no-member,
1111
parse-error,
12-
bad-continuation,
1312
too-few-public-methods,
1413
global-statement,
1514
cyclic-import,
@@ -18,14 +17,11 @@ disable =
1817

1918
[REPORTS]
2019
output-format = text
21-
files-output = no
2220
reports = no
2321

2422
[FORMAT]
2523
max-line-length = 120
26-
max-statement-lines = 75
2724
single-line-if-stmt = no
28-
no-space-check = trailing-comma,dict-separator
2925
max-module-lines = 1000
3026
indent-string = ' '
3127

@@ -73,8 +69,6 @@ good-names=logger,id,ID
7369
# Bad variable names which should always be refused, separated by a comma
7470
bad-names=foo,bar,baz,toto,tutu,tata
7571

76-
# List of builtins function names that should not be used, separated by a comma
77-
bad-functions=apply,input
7872

7973

8074
[DESIGN]
@@ -90,4 +84,4 @@ min-public-methods = 2
9084
max-public-methods = 20
9185

9286
[EXCEPTIONS]
93-
overgeneral-exceptions = Exception
87+
overgeneral-exceptions = builtins.Exception

Dockerfile

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
FROM docker.io/python:3.8-buster
2-
MAINTAINER Devin Matte <matted@csh.rit.edu>
1+
FROM docker.io/python:3.12-bookworm
2+
MAINTAINER Computer Science House <webmaster@csh.rit.edu>
33

44
RUN mkdir /opt/conditional
55

@@ -8,19 +8,23 @@ ADD requirements.txt /opt/conditional
88
WORKDIR /opt/conditional
99

1010
RUN apt-get -yq update && \
11-
apt-get -yq install libsasl2-dev libldap2-dev libssl-dev gcc g++ make && \
11+
apt-get -yq install libsasl2-dev libldap2-dev libldap-common libssl-dev gcc g++ make && \
1212
pip install -r requirements.txt && \
1313
apt-get -yq clean all
1414

15+
ENV NVM_DIR /usr/local/nvm
16+
ENV NODE_VERSION v10.24.1
17+
RUN mkdir -p $NVM_DIR
18+
19+
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
20+
21+
RUN /bin/bash -c "source $NVM_DIR/nvm.sh && nvm install $NODE_VERSION"
22+
1523
ADD . /opt/conditional
1624

17-
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
18-
apt-get -yq update && \
19-
apt-get -yq install nodejs && \
20-
npm install && \
21-
npm run production && \
22-
rm -rf node_modules && \
23-
apt-get -yq remove nodejs npm && \
25+
RUN /bin/bash -c "source $NVM_DIR/nvm.sh && nvm use --delete-prefix $NODE_VERSION && npm install && npm run production"
26+
27+
RUN rm -rf node_modules && \
2428
apt-get -yq clean all
2529

2630
RUN ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime

conditional/__init__.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
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
10+
from flask_pyoidc.provider_configuration import ProviderConfiguration, ClientMetadata
1011
from flask_sqlalchemy import SQLAlchemy
1112

1213
import sentry_sdk
@@ -39,8 +40,10 @@
3940
app.config['LDAP_BIND_PW'],
4041
ro=app.config['LDAP_RO'])
4142

42-
auth = OIDCAuthentication(app, issuer=app.config["OIDC_ISSUER"],
43-
client_registration_info=app.config["OIDC_CLIENT_CONFIG"])
43+
client_metadata = ClientMetadata(app.config["OIDC_CLIENT_CONFIG"])
44+
provider_config = ProviderConfiguration(issuer=app.config["OIDC_ISSUER"], client_registration_info=client_metadata)
45+
46+
auth = OIDCAuthentication({'default': provider_config}, app)
4447

4548
app.secret_key = app.config["SECRET_KEY"]
4649

@@ -55,7 +58,6 @@ def start_of_year():
5558
# pylint: disable=C0413
5659
from .models.models import UserLog
5760

58-
5961
# Configure Logging
6062
def request_processor(logger, log_method, event_dict): # pylint: disable=unused-argument, redefined-outer-name
6163
if 'request' in event_dict:
@@ -99,6 +101,7 @@ def database_processor(logger, log_method, event_dict): # pylint: disable=unuse
99101
# pylint: disable=wrong-import-order
100102
from conditional.util import context_processors
101103
from conditional.util.auth import get_user
104+
from conditional.util.member import gatekeep_status
102105
from .blueprints.dashboard import dashboard_bp # pylint: disable=ungrouped-imports
103106
from .blueprints.attendance import attendance_bp
104107
from .blueprints.major_project_submission import major_project_bp
@@ -137,7 +140,7 @@ def static_proxy(path):
137140

138141

139142
@app.route('/')
140-
@auth.oidc_auth
143+
@auth.oidc_auth("default")
141144
def default_route():
142145
return redirect('/dashboard')
143146

@@ -156,12 +159,25 @@ def health():
156159
return {'status': 'ok'}
157160

158161

162+
@app.route("/gatekeep/<username>")
163+
def gatekeep(username):
164+
token = request.headers.get("X-VOTE-TOKEN", "")
165+
if token != app.config["VOTE_TOKEN"]:
166+
return "Users cannot access this page", 403
167+
try:
168+
gatekeep_data = gatekeep_status(username)
169+
except KeyError:
170+
return "", 404
171+
172+
return gatekeep_data, 200
173+
174+
159175
@app.errorhandler(404)
160176
@app.errorhandler(500)
161-
@auth.oidc_auth
177+
@auth.oidc_auth("default")
162178
@get_user
163179
def route_errors(error, user_dict=None):
164-
data = dict()
180+
data = {}
165181

166182
# Handle the case where the header isn't present
167183
if user_dict['username'] is not None:

0 commit comments

Comments
 (0)