Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/exchange #108

Merged
merged 158 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
158 commits
Select commit Hold shift + click to select a range
637ac44
feature: login endpoint authenticating with sigarra
tomaspalma Feb 23, 2024
3dc9b82
fix: session cookies are now created with correct attributes
tomaspalma Feb 24, 2024
1565c79
Merge pull request #1 from tomaspalma/feature/sigarra-auth
tomaspalma Feb 28, 2024
a7a384f
started student schedule route
joaonevesf Feb 29, 2024
b072f0b
student_schedule request working
joaonevesf Mar 1, 2024
2dbf74a
add: schema for direct exchange and started api to submit exchange
tomaspalma Mar 1, 2024
4266230
feat: verifying an exchange is now working
tomaspalma Mar 1, 2024
0b5bb33
add: jwt key is now from env file or from os env var
tomaspalma Mar 1, 2024
fd97fac
feat: when creating exchange request, the exchange id is now not harc…
tomaspalma Mar 1, 2024
7ce080c
added get for course schedules on sigarra
joaonevesf Mar 1, 2024
d58905e
feat: checking for overlaps and if students belong to classes to exch…
tomaspalma Mar 2, 2024
9cd2313
add: exchange confirmation jwt expiration date
tomaspalma Mar 3, 2024
a9e5f33
fix: undeclared variable
tomaspalma Mar 3, 2024
bd05f39
Merge pull request #2 from tomaspalma/feature/accept-exchange-code-ge…
tomaspalma Mar 3, 2024
7c868fd
fix: class overlap bugs
tomaspalma Mar 4, 2024
9c52fd9
now fetching UC name from db
pfpo Mar 4, 2024
8331a14
fix: direct exchange was not added correctly for the auth user
tomaspalma Mar 5, 2024
32e61a0
Merge branch 'develop' into feature/student-schedule
pfpo Mar 5, 2024
ecef785
moved function to utils
pfpo Mar 5, 2024
07c27fa
fix: import corrected
tomaspalma Mar 5, 2024
7b991ae
fixed: api not sending 403 status
joaonevesf Mar 6, 2024
f20216c
Merge pull request #7 from tomaspalma/feature/student-schedule
joaonevesf Mar 6, 2024
fddd046
Merge branch 'develop' into feature/accept-exchange-code-generation
tomaspalma Mar 6, 2024
ced7671
fix: return json indicating success to frontend
tomaspalma Mar 7, 2024
fc2efd5
Merge pull request #5 from tomaspalma/feature/accept-exchange-code-ge…
tomaspalma Mar 7, 2024
da66ee0
logout now deletes backend session
joaonevesf Mar 7, 2024
dfe9918
fix: class overlap bugs
tomaspalma Mar 4, 2024
d3ccb90
fix: direct exchange was not added correctly for the auth user
tomaspalma Mar 5, 2024
d79b9c4
fix: return json indicating success to frontend
tomaspalma Mar 7, 2024
dec14ed
fix: overlap checking only after student schedules are totally changed
tomaspalma Mar 8, 2024
3d83be5
Merge pull request #10 from tomaspalma/feature/logout-backend-session
joaonevesf Mar 9, 2024
c07b134
refactor: extracted functionality into functions for better readibility
tomaspalma Mar 9, 2024
13c351c
Merge branch 'develop' into fix/improve-overlap-checking
tomaspalma Mar 9, 2024
266ec61
Merge pull request #11 from tomaspalma/fix/improve-overlap-checking
tomaspalma Mar 9, 2024
7f7ea09
api for students enrolled in a curricular unit
Mar 15, 2024
e94b139
fix: semester weeks are not hardcoded anymore
joaonevesf Mar 14, 2024
1eb2f04
Merge pull request #12 from tomaspalma/fix/get-current-semester
joaonevesf Mar 15, 2024
6fed241
Merge pull request #14 from tomaspalma/feature/apply-student-to-all
eduardooliveiraps Mar 31, 2024
b1b44ab
fix: models.py now being correctly generated automatically
tomaspalma Mar 31, 2024
8d933ae
Merge pull request #20 from tomaspalma/fix/entrypoint-model-generation
tomaspalma Mar 31, 2024
53c7876
feat: schema to support marketplace exchange insertions
tomaspalma Mar 31, 2024
2b67a43
started making marketplace exchange submission
tomaspalma Apr 1, 2024
f2a11a1
feat: extra returned schedule info to student_schedule endpoint
tomaspalma Mar 24, 2024
1a3d90f
Merge branch 'feature/preview-student-schedule' into feature/marketplace
tomaspalma Apr 1, 2024
9f1116e
fix: after being verified, the jwt is blacklisted for duration of ali…
tomaspalma Mar 25, 2024
6929893
Merge pull request #17 from tomaspalma/fix/exchange-confirmation-repl…
tomaspalma Apr 5, 2024
0c34798
Merge pull request #18 from tomaspalma/feature/preview-student-schedule
tomaspalma Apr 5, 2024
7b89bf0
feature: schedule is returning more info and abstracted from sigarra …
tomaspalma Apr 6, 2024
44def84
merged with main
joaonevesf Apr 7, 2024
e8d48c4
separated logic and added to get_student_schedule
joaonevesf Apr 4, 2024
5c27c5c
added update_schedule
joaonevesf Apr 9, 2024
648920e
Merge pull request #21 from tomaspalma/feature/better-schedule-info
tomaspalma Apr 10, 2024
d47420b
merged develop into update-schedule-changes
joaonevesf Apr 10, 2024
9a5dd09
update added to submit schedules
joaonevesf Apr 10, 2024
a2fa49e
moved call from build_dicts to submit_exchanges and removed unecessary Q
joaonevesf Apr 11, 2024
d9b414e
Merge pull request #22 from tomaspalma/feature/update-schedule-changes
joaonevesf Apr 11, 2024
7162074
Merge branch 'develop' into feature/marketplace
tomaspalma Apr 23, 2024
f7b9052
submitting marketplace request working
tomaspalma Apr 26, 2024
2294e93
fix: changes need to be fetched chronologically
joaonevesf Apr 26, 2024
7dcd7d1
marketplace models
Apr 27, 2024
17387d6
Merge pull request #26 from tomaspalma/fix/update-changes-by-date
joaonevesf Apr 28, 2024
c7039cb
marketplace backend
Apr 28, 2024
89fca39
Resolved merge conflicts
Apr 28, 2024
1c7dd52
fix: marketplace submission working
tomaspalma Apr 30, 2024
264127c
Implemented backend logic for fetching marketplace exchange data - ma…
May 1, 2024
b39e6f5
Able to see exchange history. (#24)
pfpo May 17, 2024
52f0073
Some changes commited before change to branch develop
May 27, 2024
526ff62
feat: storing unit id on direct exchanges
tomaspalma May 30, 2024
e968a0e
Merge pull request #28 from tomaspalma/feature/store-unit-id-on-excha…
tomaspalma May 31, 2024
7826646
Merge branch 'develop' into feature/marketplace
tomaspalma May 31, 2024
78aec27
Merge branch 'feature/marketplace' of github.com:tomaspalma/tts-be-ex…
May 31, 2024
a1532ab
allowing course_unit_id on marketplace exchange request on database
tomaspalma May 31, 2024
0051316
fixed marketplace submission issue
tomaspalma Jun 3, 2024
c9126e5
fix: some bugs related to exchange overlap
tomaspalma Jun 4, 2024
2ea78ac
added popup warning when the schedule is different from sigarra (#25)
joaonevesf Jun 4, 2024
09dd1cc
setup mailtrap email sending for demo purposes
tomaspalma May 27, 2024
3b8eb63
Merge branch 'develop' into feature/send-email
tomaspalma Jun 5, 2024
6d3e631
Merge pull request #31 from tomaspalma/feature/send-email
tomaspalma Jun 5, 2024
378560e
added export button to export all accepted direct exchanges (#29)
joaonevesf Jun 5, 2024
1b2d66c
feat: own marketplace requests do not appear
tomaspalma Jun 5, 2024
047f96c
added models for admin role (#33)
pfpo Jun 6, 2024
0fce4ef
added authentication middleware (#32)
joaonevesf Jun 6, 2024
0195180
Merge branch 'develop' into feature/marketplace
tomaspalma Jun 6, 2024
3b8f7c5
Merge pull request #30 from tomaspalma/feature/marketplace
tomaspalma Jun 6, 2024
85a576f
fix: marketplace exchange using acronyms now
tomaspalma Jun 6, 2024
0ce77b5
fixed bug in middleware (#34)
joaonevesf Jun 6, 2024
77a1ecb
Fix/auth middleware (#35)
joaonevesf Jun 6, 2024
0d0879b
Feature/marketplace exchange not deleting (#37)
joaonevesf Jun 6, 2024
59cc3f8
changed to use course unit id instead of name and added TODO (#36)
joaonevesf Jun 6, 2024
f96da38
fix: ocorr_id already has class and schedule, last pr inserted this b…
joaonevesf Jun 6, 2024
c28114d
changed email text
tomaspalma Jun 6, 2024
02757f1
Feature/history to all (#39)
pfpo Jun 19, 2024
c6050dd
fix: delete marketplace when accepting direct exchange (#40)
joaonevesf Jun 20, 2024
6b64ccc
chore: changed gitignore
tomaspalma Aug 11, 2024
572c9ab
Merge branch 'develop' of github.com:tomaspalma/tts-be-exchange into …
tomaspalma Aug 11, 2024
f94f098
Merge branch 'develop' into feature/exchange
tomaspalma Aug 11, 2024
5fdf328
started basic saml2 configuration
tomaspalma Mar 18, 2024
da3ed90
add: endpoint to get csrf token
tomaspalma Aug 13, 2024
f1210a9
Merge branch 'develop' into feature/exchange
tomaspalma Aug 15, 2024
4e202b4
chore: change exchange schema from mysql to postgres
tomaspalma Aug 15, 2024
bd33463
Merge branch 'develop' into feature/exchange
tomaspalma Aug 18, 2024
3b90f5e
feat: started pagination on marketplace exchanges
tomaspalma Aug 21, 2024
3b0063a
Merge branch 'develop' into feature/exchange
tomaspalma Aug 26, 2024
4aea39d
feat: endpoint for getting marketplace exchanges
tomaspalma Sep 5, 2024
ed07d18
refactor: improvements in marketplace exchange requests pagination
tomaspalma Sep 7, 2024
fc24172
feat: returnig schedule
tomaspalma Sep 11, 2024
7443098
feat: openidconnect federated authentication
tomaspalma Sep 5, 2024
bc87ef6
feat: exchange marketplace requests filter
tomaspalma Sep 12, 2024
e40ec71
feat: send schedule along with marketplace exchange requests
tomaspalma Sep 15, 2024
2bc887b
chore: nginx for development purposes
tomaspalma Sep 18, 2024
98d0ef4
chore: add scripts to populate marketplace with mock data
tomaspalma Sep 19, 2024
8634cfa
chore: add nginx folder
tomaspalma Sep 20, 2024
1758d7b
feat: user's number is now the nmec number
tomaspalma Sep 20, 2024
e1ae7be
refactor: added filter map to marketplace exchange view
tomaspalma Sep 21, 2024
b117627
refactor: remove unused function that before retrieved the marketplac…
tomaspalma Sep 24, 2024
995813c
feat: vite web socket communication working
tomaspalma Sep 28, 2024
1ae5a2f
refactor: direct exchange submission changed to DirectExchangeView class
tomaspalma Sep 28, 2024
a0327e6
Auto stash before merge of "feature/exchange" and "origin/feature/exc…
jose-carlos-sousa Sep 29, 2024
dc3e026
chore : changed exchange/marketplace endpoint so that classes are ins…
jose-carlos-sousa Sep 29, 2024
92188f6
refactor: sigarra dependency moved to sigarra controller
tomaspalma Sep 29, 2024
b2fc661
Merge pull request #111 from NIAEFEUP/fix/OptionClasses
jose-carlos-sousa Oct 1, 2024
386751d
feat: returning if exchange is accepted or not
tomaspalma Oct 1, 2024
21c1ec1
Merge branch 'feature/exchange' of github.com:NIAEFEUP/tts-be into fe…
tomaspalma Oct 3, 2024
e4d8ae5
feat: initial version of student only seeing requests where dest clas…
tomaspalma Oct 6, 2024
522056c
feat: class name filtering
tomaspalma Oct 12, 2024
ad9a470
feat: endpoint to retrieve student images
tomaspalma Oct 13, 2024
7d0606a
fix: class filtering had a wrong parameter
tomaspalma Oct 14, 2024
a3071dc
refactor: request metadata gives slots with classes
tomaspalma Oct 14, 2024
dcb35a1
feat: added eligible course units mechanism
tomaspalma Oct 19, 2024
5858af1
feat: /auth/info gives information if user is enrolled in course unit…
tomaspalma Oct 19, 2024
e9ff1f7
chore: update schema
tomaspalma Oct 19, 2024
328cb1c
Merge branch 'develop' into feature/exchange
tomaspalma Oct 19, 2024
35f9c63
feat: student received requests endpoint working
tomaspalma Oct 22, 2024
37fc5ba
refactor: returning more attributes in direct exchange
tomaspalma Oct 23, 2024
db89323
refactor: changed attribute name and added id to exchange request
tomaspalma Oct 24, 2024
081dd31
refactor: removed unusued endpoints from urls.py
tomaspalma Nov 1, 2024
5788dc8
feat: add way to determine pending motive of pending request
tomaspalma Nov 2, 2024
ce9a6f3
added more ucs to mock_data.sql
tomaspalma Nov 9, 2024
0aa1505
feat: student sent exchanges is agnostic of request type
tomaspalma Nov 17, 2024
0b7b8d1
chore: remove useless xml files
tomaspalma Nov 17, 2024
90b72da
feat: endpoint to accept direct exchange without jwt
tomaspalma Nov 22, 2024
37ae965
fix: migrations a are now run with docker compose up
tomaspalma Nov 27, 2024
6f70bcf
Merge branch 'develop' into feature/exchange
tomaspalma Nov 30, 2024
5311e2e
chore: removed merge conflicts
tomaspalma Dec 11, 2024
83cf28f
chore: removed dead and commented out code
tomaspalma Dec 13, 2024
2d4a187
fix: wrong documentation on course_unit_by_id method
tomaspalma Dec 17, 2024
ef74624
refactor: allowed hosts and cors allowed origins depending on DEBUG v…
tomaspalma Dec 18, 2024
7f520d1
chore: added email domains to .env.example
tomaspalma Dec 20, 2024
920744f
refactor: simplified statement checking if there are eligible exchang…
tomaspalma Dec 26, 2024
1436e3b
fix: add <a> to confirm exchange html email template
tomaspalma Dec 27, 2024
0e25eea
chore: add mailpit to test email sending
tomaspalma Dec 27, 2024
d76c486
refactor: cleaned schedule changes in build schedules method
tomaspalma Dec 27, 2024
bb25581
feat: store student enrolled course units without always having to go…
tomaspalma Dec 28, 2024
a45b5c0
refactor: cleaned student schedules swap code
tomaspalma Dec 29, 2024
1f79a9e
refactor: duplicated methods in marketplace exchange view and exchang…
tomaspalma Dec 29, 2024
2b01028
feat: storing classes of student
tomaspalma Dec 28, 2024
0b285c7
feat: showing only exchanges the auth user can satisfy (is in class t…
tomaspalma Dec 29, 2024
30a7f13
Merge branch 'develop' into feature/exchange
tomaspalma Dec 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ postgres/sql/01_data.sql
# django
django/**/migrations/**
django/university/models.py
django/.env.dev

nginx/certs/*.key

# celery
django/celerybeat-schedule

# stats related graphs
django/university/stats_graphs/*

httpd/shibboleth/*.pem

13 changes: 0 additions & 13 deletions django/.env.dev

This file was deleted.

28 changes: 28 additions & 0 deletions django/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
DEBUG=1
SECRET_KEY=foo

JWT_KEY=change_in_production

DOMAIN=http://localhost:3100/

POSTGRES_DB=tts
POSTGRES_USER=root
POSTGRES_PASSWORD=root
POSTGRES_HOST=db
POSTGRES_PORT=5432

TTS_REDIS_HOST=tts_redis
TTS_REDIS_PORT=6379
TTS_REDIS_USERNAME=
TTS_REDIS_PASSWORD=

SENDER_EMAIL_ADDRESS=
[email protected]

VERIFY_EXCHANGE_TOKEN_EXPIRATION_SECONDS=86400

OIDC_RP_CLIENT_ID=
OIDC_RP_CLIENT_SECRET=

SIGARRA_USERNAME=
SIGARRA_PASSWORD=
29 changes: 17 additions & 12 deletions django/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
#!/bin/sh
#!/bin/sh

# WARNING: The script will not work if formated with CRLF.
# WARNING: The script will not work if formated with CRLF.

# Configure the shell behaviour.
# Configure the shell behaviour.
set -e
if [[ "${DEBUG}" == 1 ]]
then set -x
fi
if [[ "${DEBUG}" == 1 ]]; then
set -x
fi

# Get parameters.
cmd="$@"

# Waits for PostgreSQL initialization.
# Waits for PostgreSQL initialization.
until PGPASSWORD="${POSTGRES_PASSWORD}" psql -h "${POSTGRES_HOST}" -U "${POSTGRES_USER}" "${POSTGRES_DB}" -c 'select 1'; do
>&2 echo "PostgreSQL is unavailable - sleeping"
sleep 4
>&2 echo "PostgreSQL is unavailable - sleeping"
sleep 4
done
>&2 echo "PostgreSQL is up - executing command"
>&2 echo "PostgreSQL is up - executing command"

echo "ENTRYPOINT RAN"

# Migrate the Django.
python manage.py inspectdb > university/models.py
python manage.py makemigrations
python manage.py migrate
python manage.py migrate --fake sessions zero
python manage.py migrate university --fake
python manage.py migrate --fake-initial
python manage.py inspectdb >university/models.py

# Initialize redis worker for celery and celery's beat scheduler in the background
celery -A tasks worker --loglevel=INFO &
celery -A tasks beat &

# Initializes the API.
# Initializes the API.
exec $cmd
1 change: 1 addition & 0 deletions django/entrypoint_prod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ done
# Migrate the Django.
python manage.py inspectdb >university/models.py
python manage.py makemigrations
python manage.py migrate
python manage.py migrate university --fake

python manage.py runserver 0.0.0.0:8000
3 changes: 3 additions & 0 deletions django/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ psycopg2==2.9.9
celery==5.2.7
redis==3.5.3
python-dotenv==1.0.1
requests==2.31.0
pyjwt==2.8.0
mozilla-django-oidc==4.0.1
channels==4.1.0
daphne==4.1.2
python-socketio==5.11.4
78 changes: 70 additions & 8 deletions django/tts_be/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@

from pathlib import Path
import os
from dotenv import dotenv_values


CONFIG={
**dotenv_values(".env"), # load variables
**os.environ, # override loaded values with environment variables
}

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -22,12 +27,21 @@
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/

SECRET_KEY = os.getenv('SECRET_KEY')
SECRET_KEY = CONFIG['SECRET_KEY']

JWT_KEY= CONFIG['JWT_KEY']

DEBUG = os.getenv('DEBUG')
DEBUG = int(DEBUG) != 0 if DEBUG else False

ALLOWED_HOSTS = ['0.0.0.0', 'localhost', 'tts.niaefeup.pt', 'tts-staging.niaefeup.pt']
DOMAIN = os.getenv('DOMAIN')
DEBUG = False if int(CONFIG['DEBUG']) == 0 else True

ALLOWED_HOSTS = ['tts.niaefeup.pt', 'tts-staging.niaefeup.pt']

if DEBUG:
ALLOWED_HOSTS.extend(['localhost', 'tts-dev.niaefeup.pt'])


# Application definition

Expand All @@ -37,10 +51,11 @@
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
#'django.contrib.sessions', # legacy
'django.contrib.sessions', # legacy
'django.contrib.messages',
'rest_framework',
'django.contrib.staticfiles',
'mozilla_django_oidc',
'university',
'channels',
]
Expand All @@ -51,18 +66,24 @@
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'university.auth_middleware.AuthMiddleware',
'mozilla_django_oidc.middleware.SessionRefresh',
'django.middleware.csrf.CsrfViewMiddleware'
]

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

ROOT_URLCONF = 'tts_be.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [
os.path.join(BASE_DIR, 'university/exchange/emails')
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand All @@ -75,10 +96,35 @@
},
]



WSGI_APPLICATION = 'tts_be.wsgi.application'

ASGI_APPLICATION = 'tts_be.asgi.application'
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'university.auth.CustomOIDCAuthentationBackend'
)

OIDC_RP_CLIENT_ID = os.environ['OIDC_RP_CLIENT_ID']
OIDC_RP_CLIENT_SECRET = os.environ['OIDC_RP_CLIENT_SECRET']
OIDC_RP_SIGN_ALGO = "RS256"

OIDC_STORE_ID_TOKEN = True
OIDC_STORE_ACCESS_TOKEN = True

OIDC_OP_AUTHORIZATION_ENDPOINT = "https://open-id.up.pt/realms/sigarra/protocol/openid-connect/auth"
OIDC_OP_TOKEN_ENDPOINT = "https://open-id.up.pt/realms/sigarra/protocol/openid-connect/token"
OIDC_OP_USER_ENDPOINT = "https://open-id.up.pt/realms/sigarra/protocol/openid-connect/userinfo"
OIDC_OP_JWKS_ENDPOINT = "https://open-id.up.pt/realms/sigarra/protocol/openid-connect/certs"
OIDC_OP_LOGOUT_ENDPOINT = "https://open-id.up.pt/realms/sigarra/protocol/openid-connect/logout"

OIDC_RP_SCOPES = "openid email profile uporto_data"

LOGIN_REDIRECT_URL = "/"

OIDC_RENEW_ID_TOKEN_EXPIRY_SECONDS = 3600 * 60

ASGI_APPLICATION = 'tts_be.asgi.application'

# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
Expand Down Expand Up @@ -125,7 +171,6 @@

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/

Expand All @@ -144,7 +189,24 @@
'rest_framework.renderers.JSONRenderer',
'rest_framework.renderers.BrowsableAPIRenderer',
]
}

CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.redis.RedisCache',
'LOCATION': f"redis://{CONFIG['TTS_REDIS_HOST']}:{CONFIG['TTS_REDIS_PORT']}//"
}
}

CORS_ORIGIN_ALLOW_ALL = True
CORS_ORIGIN_ALLOW_ALL = bool(DEBUG)
CORS_ALLOW_CREDENTIALS = True
CORS_ALLOW_HEADERS = [
"X-CSRFToken"
]

VERIFY_EXCHANGE_TOKEN_EXPIRATION_SECONDS = int(os.getenv("VERIFY_EXCHANGE_TOKEN_EXPIRATION_SECONDS", 3600 * 24))

EMAIL_HOST = os.getenv("EMAIL_HOST", "tts-mailpit")
EMAIL_PORT = os.getenv("EMAIL_PORT", 1025)
EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER", None)
EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD", None)
3 changes: 0 additions & 3 deletions django/university/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from django.contrib import admin

# Register your models here.
29 changes: 29 additions & 0 deletions django/university/auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from mozilla_django_oidc.auth import OIDCAuthenticationBackend
from university.controllers.SigarraController import SigarraController
from university.controllers.StudentController import StudentController
from university.models import UserCourseUnits, Class

class CustomOIDCAuthentationBackend(OIDCAuthenticationBackend):

def create_user(self, claims):
user = super(CustomOIDCAuthentationBackend, self).create_user(claims)

user.first_name = claims.get('given_name', '')
user.last_name = claims.get('family_name', '').split(' ')[-1]
user.username = claims.get('nmec', '')
user.password = "" # User does not have password
user.save()

StudentController.populate_user_course_unit_data(user.username)

return user

def update_user(self, user, claims):
user.first_name = claims.get('given_name', '')
user.last_name = claims.get('family_name', '').split(' ')[-1]
user.save()

StudentController.populate_user_course_unit_data(user.username, erase_previous=True)

return user

43 changes: 43 additions & 0 deletions django/university/auth_middleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import re

from django.http import HttpResponseForbidden

class AuthMiddleware:
def __init__(self, get_response):
self.get_response = get_response
self.auth_paths = [
'/logout/',
'/auth/info/',
'/student/schedule/',
re.compile(r'^/student/\w+/photo/$'),
re.compile(r'^/schedule_sigarra/\d+/$'),
re.compile(r'^/class_sigarra_schedule/\d+/.+/$'),
re.compile(r'^/exchange/marketplace/$'),
re.compile(r'^/exchange/direct/$'),
re.compile(r'^/exchange/options/$'),
'/is_admin/',
'/export/',
'/direct_exchange/history/',
'/marketplace_exchange/',
'/submit_marketplace_exchange/',
]

def __call__(self, request):
in_paths = False

for path in self.auth_paths:
if isinstance(path, str) and request.path == path:
in_paths = True
break
elif isinstance(path, re.Pattern) and path.match(request.path):
in_paths = True
break

if not in_paths:
return self.get_response(request)

if not request.user.is_authenticated:
return HttpResponseForbidden()

return self.get_response(request)

Loading