-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from SELab-2/develop
Klaar voor release Milestone 2
- Loading branch information
Showing
132 changed files
with
15,207 additions
and
6,564 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[run] | ||
omit= | ||
*/tests/* | ||
*/migrations/* | ||
*/__init__.py | ||
*/__pycache__/* | ||
*/data/* | ||
*/frontend/* | ||
*/static/* | ||
*/.github/* | ||
*/usr/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM ubuntu:latest | ||
LABEL maintainer="Your Name <[email protected]>" | ||
RUN apt-get update -y && \ | ||
apt-get upgrade -y && \ | ||
apt-get dist-upgrade -y && \ | ||
apt-get -y autoremove && \ | ||
apt-get clean | ||
RUN apt-get install -y zip \ | ||
unzip \ | ||
python3 \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
# Copy the script to the container | ||
ADD ./api/docker/testing_entrypoint.sh / | ||
RUN chmod +x /testing_entrypoint.sh | ||
# Set the entrypoint to the script with CMD arguments | ||
ENTRYPOINT ["/testing_entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pexpect | ||
from dotenv import dotenv_values | ||
|
||
|
||
def run_tests_on(indiening_id, project_id): | ||
""" | ||
Voert tests uit op een specifieke indiening en project met behulp van Docker. | ||
Args: | ||
indiening_id (int): Het ID van de indiening. | ||
project_id (int): Het ID van het project. | ||
Returns: | ||
tuple: Een tuple (bool, string) die aangeeft of de tests zijn mislukt en de uitvoer van de tests. | ||
""" | ||
command = f"sudo bash api/docker/rundocker.sh {indiening_id} {project_id}" | ||
child = pexpect.spawn(command, timeout=None) | ||
index = child.expect([r"\[sudo\] password", pexpect.EOF, pexpect.TIMEOUT]) | ||
|
||
dot_env_values = dotenv_values("api/.env") | ||
if index == 0: | ||
child.sendline(dot_env_values.get("SUDO_PASSWORD")) | ||
output = child.read().decode("utf-8") | ||
child.close() | ||
return ": FAIL" in output, output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
yes | docker system prune -a >&2 | ||
docker build -t script-demo -f api/docker/Dockerfile . | ||
docker run --mount type=bind,source="$(pwd)"/data/restricties/project_$2,target=/data/restricties --mount type=bind,source="$(pwd)"/data/indieningen/indiening_$1,target=/data --name demo -d script-demo | ||
docker logs demo -f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
cd data | ||
|
||
for filename in ./restricties/*; do | ||
echo -n "Testing ${filename}: " | ||
|
||
if [[ "$filename" == *.sh ]] | ||
then | ||
bash $filename | ||
elif [[ "$filename" == *.py ]] | ||
then | ||
python3 $filename | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,71 @@ | ||
from django.conf import settings | ||
from django.shortcuts import redirect | ||
from django.contrib.auth.models import User | ||
from api.models.gebruiker import Gebruiker | ||
from api.serializers.gebruiker import GebruikerSerializer | ||
import requests | ||
|
||
URL = "https://graph.microsoft.com/v1.0/me" | ||
|
||
class RedirectAnonymousUserMiddleware: | ||
|
||
class AuthenticationUserMiddleware: | ||
""" | ||
Middleware die anonieme gebruikers omleidt naar de inlogpagina. | ||
Deze middleware controleert of de gebruiker anoniem is en of het huidige pad niet de inlogpagina is. | ||
Als dit het geval is, wordt de gebruiker omgeleid naar de inlogpagina die is geconfigureerd in de instellingen. | ||
Middleware voor authenticatie van gebruikers en het aanmaken van gebruikersindeling. | ||
Args: | ||
get_response (function): De functie die wordt aangeroepen om het verzoek te verwerken. | ||
get_response (callable): De volgende middleware in de keten. | ||
Returns: | ||
HttpResponse: Een HTTP-omleiding naar de inlogpagina als de gebruiker anoniem is | ||
en het huidige pad niet de inlogpagina is. | ||
Anders wordt het verzoek verder verwerkt door de volgende middleware of de weergavefunctie. | ||
HttpResponse: Een HTTP-response-object. | ||
Raises: | ||
Redirect: Redirect naar de inlog-URL als er geen autorisatiegegevens zijn. | ||
""" | ||
|
||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
|
||
def __call__(self, request): | ||
# Check if the user is anonymous and the current path is not the login page | ||
if request.user.is_anonymous and request.path not in [ | ||
"/oauth2/login", | ||
"/oauth2/callback", | ||
]: | ||
# Redirect to the login page | ||
return redirect(settings.LOGIN_URL) | ||
if request.path in ["/oauth2/login", "/oauth2/callback"]: | ||
return self.get_response(request) | ||
|
||
if request.user.is_anonymous: | ||
authorization = request.headers.get("Authorization") | ||
if authorization: | ||
headers = { | ||
"Authorization": authorization, | ||
"Content-Type": "application/json", | ||
} | ||
|
||
response = requests.get(url=URL, headers=headers) | ||
json_data = response.json() | ||
mail = json_data.get("mail") | ||
first_name = json_data.get("givenName") | ||
last_name = json_data.get("surname") | ||
try: | ||
user = User.objects.get(username=mail) | ||
except User.DoesNotExist: | ||
user = User.objects.create_user( | ||
username=mail, | ||
email=mail, | ||
first_name=first_name, | ||
last_name=last_name, | ||
) | ||
|
||
request.user = user | ||
else: | ||
return redirect(settings.LOGIN_URL) | ||
|
||
try: | ||
Gebruiker.objects.get(pk=request.user.id) | ||
except Gebruiker.DoesNotExist: | ||
gebruiker_post_data = { | ||
"user": request.user.id, | ||
"subjects": [], | ||
"is_lesgever": False, | ||
} | ||
serializer = GebruikerSerializer(data=gebruiker_post_data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
|
||
return self.get_response(request) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.