Skip to content

Commit

Permalink
Merge pull request #108 from SELab-2/develop
Browse files Browse the repository at this point in the history
Milestone 2
  • Loading branch information
robinpdev authored Apr 18, 2024
2 parents 0e143c5 + 55c3451 commit c4497f8
Show file tree
Hide file tree
Showing 199 changed files with 21,807 additions and 1,180 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Analysing the code with flake8
working-directory: ./backend
run: |
flake8 pigeonhole/
flake8 .
ESLint:
runs-on: self-hosted
Expand Down
19 changes: 17 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Backend test CI
name: Test CI

on:
- pull_request
Expand All @@ -19,4 +19,19 @@ jobs:
pip install -r ./backend/requirements.txt
- name: Running Django tests
run: |
sh ./backend/runtests.sh
sh ./backend/runtests.sh
frontend-test:
runs-on: self-hosted
steps:
- uses: actions/checkout@v3
- name: Set up Node.js v18.
uses: actions/setup-node@v3
with:
node-version: 18.17.0
- name: Install your dependencies
working-directory: ./frontend
run: npm ci
- name: Run Fronted tests
working-directory: ./frontend
run: npx jest --silent
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
django/db.sqlite3
backend/db.sqlite3
backend/uploads
backend/downloads/*
!backend/downloads/__init__.py
venv/
.venv/

Expand All @@ -13,3 +15,6 @@ venv/
#deploy
letsencrypt
.env.prod
node_modules
/node_modules/
backend/static/*
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ lint:
superuser:
docker exec -it pigeonhole-backend python manage.py createsuperuser

mockdata:
docker exec -it pigeonhole-backend python manage.py runscript mockdata

reset:
docker image prune -af
docker system prune
Expand All @@ -22,4 +25,10 @@ backendshell:
docker exec -it pigeonhole-backend sh

frontshell:
docker exec -it pigeonhole-frontend sh
docker exec -it pigeonhole-frontend sh

componenttest:
docker exec -it pigeonhole-frontend npx jest

silentcomponenttest:
docker exec -it pigeonhole-frontend npx jest --silent
Empty file added backend/downloads/__init__.py
Empty file.
45 changes: 45 additions & 0 deletions backend/pigeonhole/apps/courses/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from django.contrib import admin

from backend.pigeonhole.apps.courses.models import Course


class CourseAdmin(admin.ModelAdmin):
list_display = (
'name',
'course_id',
)
search_fields = (
'name',
'course_id',
'description',
)
ordering = (
'course_id',
)
readonly_fields = (
'invite_token',
)

fieldsets = (
(
None,
{
'fields': (
'name',
'description',
)
}
),
(
'Invites',
{
'fields': (
'invite_token',
'open_course',
)
}
)
)


admin.site.register(Course, CourseAdmin)
4 changes: 3 additions & 1 deletion backend/pigeonhole/apps/courses/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0.3 on 2024-03-12 22:52
# Generated by Django 5.0.2 on 2024-04-13 11:12

from django.db import migrations, models

Expand All @@ -17,6 +17,8 @@ class Migration(migrations.Migration):
('course_id', models.BigAutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=256)),
('description', models.TextField()),
('open_course', models.BooleanField(default=False)),
('invite_token', models.CharField(blank=True, max_length=20, null=True)),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.11 on 2024-04-17 14:59

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
('courses', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='course',
name='course_banner',
field=models.FileField(blank=True, default='course_banners/default.jpg', null=True,
upload_to='course_banners/'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.11 on 2024-04-17 15:00

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('courses', '0002_course_course_banner'),
]

operations = [
migrations.AlterField(
model_name='course',
name='course_banner',
field=models.FileField(blank=True, default='course_banners/default.jpg', upload_to='course_banners/'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.11 on 2024-04-17 15:01

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('courses', '0003_alter_course_course_banner'),
]

operations = [
migrations.RenameField(
model_name='course',
old_name='course_banner',
new_name='banner',
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.11 on 2024-04-17 15:09

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('courses', '0004_rename_course_banner_course_banner'),
]

operations = [
migrations.AlterField(
model_name='course',
name='banner',
field=models.FileField(blank=True, default='course_banners/ugent_banner.png', upload_to='course_banners/'),
),
]
31 changes: 30 additions & 1 deletion backend/pigeonhole/apps/courses/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db import models
from django.utils.crypto import get_random_string
from rest_framework import serializers


Expand All @@ -7,11 +8,39 @@ class Course(models.Model):
course_id = models.BigAutoField(primary_key=True)
name = models.CharField(max_length=256)
description = models.TextField()
open_course = models.BooleanField(default=False)
invite_token = models.CharField(max_length=20, blank=True, null=True)
banner = models.FileField(upload_to='course_banners/', blank=True, null=False,
default='course_banners/ugent_banner.png')

objects = models.Manager()

def generate_new_token(self):
# generate a new token (could be useful if you want to use a different invite token)
token = get_random_string(length=20)
self.invitation_token = token
self.save()
return token

def save(self, *args, **kwargs):
# generate new code on initialization of a new course
if not self.invite_token:
self.invite_token = get_random_string(length=20)
return super().save(*args, **kwargs)


class CourseSerializer(serializers.ModelSerializer):
invite_token = serializers.ReadOnlyField()

class Meta:
model = Course
fields = ['course_id', 'name', 'description']
fields = ['course_id', 'name', 'open_course', 'description', 'invite_token', 'banner']

def to_representation(self, instance):
data = super().to_representation(instance)
request = self.context.get('request')

if request and request.user.is_student:
if 'invite_token' in data:
del data['invite_token']
return data
32 changes: 22 additions & 10 deletions backend/pigeonhole/apps/courses/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,33 @@ def has_permission(self, request, view):
if request.user.is_admin or request.user.is_superuser:
return True

if view.action in ['join_course', 'get_selected_courses']:
if view.action in [
"join_course",
"get_selected_courses",
"join_course_with_token",
"leave_course",
"get_teachers",
"get_students",
]:
return True

if request.user.is_teacher:
if view.action in ['create', 'list', 'retrieve']:
if view.action in ["create", "list", "retrieve"]:
return True
elif view.action in ['update', 'partial_update', 'destroy', 'get_projects'] and User.objects.filter(
id=request.user.id,
course=view.kwargs[
'pk']).exists():
elif (
view.action in ["update", "partial_update", "destroy",
"get_projects"]
and User.objects.filter(
id=request.user.id, course=view.kwargs["pk"]
).exists()
):
return True
return
return False

if request.user.is_student:
if view.action == 'get_projects':
return Course.objects.filter(course_id=view.kwargs['pk'], user=request.user).exists()
return view.action in ['list', 'retrieve']
if view.action == "get_projects":
return Course.objects.filter(
course_id=view.kwargs["pk"], user=request.user
).exists()
return view.action in ["list", "retrieve"]
return False
Loading

0 comments on commit c4497f8

Please sign in to comment.