This repository has been archived by the owner on Jan 22, 2025. It is now read-only.
-
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.
- Loading branch information
1 parent
2d00aab
commit a0f5a92
Showing
14 changed files
with
183 additions
and
122 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 |
---|---|---|
@@ -1,30 +1,30 @@ | ||
from rest_framework import permissions | ||
from backend.pigeonhole.apps.users.models import Student, Teacher | ||
from backend.pigeonhole.apps.users.models import User | ||
|
||
|
||
class CourseUserPermissions(permissions.BasePermission): | ||
def has_permission(self, request, view): | ||
if request.user.is_superuser: | ||
return True | ||
if isinstance(request.user, Teacher): | ||
return True | ||
|
||
if isinstance(request.user, Student): | ||
return view.action in ['list', 'retrieve'] | ||
# if isinstance(request.user, Teacher): | ||
# return True | ||
# | ||
# if isinstance(request.user, Student): | ||
# return view.action in ['list', 'retrieve'] | ||
|
||
return False | ||
|
||
def has_object_permission(self, request, view, obj): | ||
if request.user.is_superuser: | ||
return True | ||
if isinstance(request.user, Teacher): | ||
if request.user.is_admin: | ||
return True | ||
elif Teacher.objects.filter(id=request.user.id, course=obj).exists(): | ||
return True | ||
return view.action in ['list', 'retrieve'] | ||
|
||
if isinstance(request.user, Student): | ||
return view.action in ['list', 'retrieve'] | ||
# if isinstance(request.user, Teacher): | ||
# if request.user.is_admin: | ||
# return True | ||
# elif Teacher.objects.filter(id=request.user.id, course=obj).exists(): | ||
# return True | ||
# return view.action in ['list', 'retrieve'] | ||
# | ||
# if isinstance(request.user, Student): | ||
# return view.action in ['list', 'retrieve'] | ||
|
||
return False |
24 changes: 24 additions & 0 deletions
24
backend/pigeonhole/apps/groups/migrations/0005_remove_group_student_group_user.py
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,24 @@ | ||
# Generated by Django 5.0.2 on 2024-03-11 13:17 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('groups', '0004_alter_group_final_score'), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='group', | ||
name='student', | ||
), | ||
migrations.AddField( | ||
model_name='group', | ||
name='user', | ||
field=models.ManyToManyField(to=settings.AUTH_USER_MODEL), | ||
), | ||
] |
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
64 changes: 64 additions & 0 deletions
64
...pigeonhole/apps/users/migrations/0003_remove_teacher_course_remove_teacher_id_and_more.py
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,64 @@ | ||
# Generated by Django 5.0.2 on 2024-03-11 13:17 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('courses', '0001_initial'), | ||
('groups', '0005_remove_group_student_group_user'), | ||
('users', '0002_rename_is_assistent_teacher_is_assistant'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='teacher', | ||
name='course', | ||
), | ||
migrations.RemoveField( | ||
model_name='teacher', | ||
name='id', | ||
), | ||
migrations.AlterModelManagers( | ||
name='user', | ||
managers=[ | ||
], | ||
), | ||
migrations.AddField( | ||
model_name='user', | ||
name='course', | ||
field=models.ManyToManyField(to='courses.course'), | ||
), | ||
migrations.AddField( | ||
model_name='user', | ||
name='role', | ||
field=models.IntegerField(choices=[(1, 'Superuser'), (2, 'Teacher'), (3, 'Student')], default=3), | ||
), | ||
migrations.AlterField( | ||
model_name='user', | ||
name='email', | ||
field=models.EmailField(max_length=254, unique=True), | ||
), | ||
migrations.AlterField( | ||
model_name='user', | ||
name='first_name', | ||
field=models.CharField(max_length=30), | ||
), | ||
migrations.AlterField( | ||
model_name='user', | ||
name='id', | ||
field=models.BigAutoField(primary_key=True, serialize=False), | ||
), | ||
migrations.AlterField( | ||
model_name='user', | ||
name='last_name', | ||
field=models.CharField(max_length=150), | ||
), | ||
migrations.DeleteModel( | ||
name='Student', | ||
), | ||
migrations.DeleteModel( | ||
name='Teacher', | ||
), | ||
] |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from django.test import TestCase | ||
from backend.pigeonhole.apps.courses.models import Course | ||
from backend.pigeonhole.apps.users.models import User, Student, Teacher | ||
from backend.pigeonhole.apps.users.models import User | ||
from django.db.utils import DataError | ||
|
||
|
||
|
@@ -25,24 +25,24 @@ def setUp(self): | |
) | ||
|
||
# Create teacher and student using the created users | ||
teacher = Teacher.objects.create(id=teacher_user) | ||
student = Student.objects.create(id=student_user, number=1234) | ||
teacher = User.objects.create(id=teacher_user) | ||
student = User.objects.create(id=student_user, number=1234) | ||
|
||
# Create course | ||
course = Course.objects.create(name="Math", description="Mathematics") | ||
teacher.course.add(course) | ||
student.course.add(course) | ||
|
||
def test_course_teacher_relationship(self): | ||
teacher = Teacher.objects.get(id__email="[email protected]") | ||
teacher = User.objects.get(id__email="[email protected]") | ||
course = Course.objects.get(name="Math") | ||
self.assertIn(course, teacher.course.all()) | ||
course_alter_ego = teacher.course.get(name="Math") | ||
self.assertEqual(course, course_alter_ego) | ||
self.assertTrue(course_alter_ego, "Mathematics") | ||
|
||
def test_course_students_relationship(self): | ||
student = Student.objects.get(id__email="[email protected]") | ||
student = User.objects.get(id__email="[email protected]") | ||
course = Course.objects.get(name="Math") | ||
self.assertIn(course, student.course.all()) | ||
course_alter_ego = student.course.get(name="Math") | ||
|
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,6 +1,6 @@ | ||
from django.test import TestCase | ||
from backend.pigeonhole.apps.courses.models import Course | ||
from backend.pigeonhole.apps.users.models import User, Student, Teacher | ||
from backend.pigeonhole.apps.users.models import User | ||
from backend.pigeonhole.apps.groups.models import Group | ||
from backend.pigeonhole.apps.projects.models import Project | ||
|
||
|
@@ -34,9 +34,9 @@ def setUp(self): | |
) | ||
|
||
# Create teacher and student using the created users | ||
teacher = Teacher.objects.create(id=teacher_user) | ||
student = Student.objects.create(id=student_user, number=1234) | ||
student2 = Student.objects.create(id=student_user2, number=5678) | ||
teacher = User.objects.create(id=teacher_user) | ||
student = User.objects.create(id=student_user, number=1234) | ||
student2 = User.objects.create(id=student_user2, number=5678) | ||
|
||
# Create course | ||
course = Course.objects.create(name="Math", description="Mathematics") | ||
|
@@ -67,8 +67,8 @@ def test_group_project_relation(self): | |
|
||
def test_group_student_relation(self): | ||
group = Group.objects.get(group_nr=1) | ||
student = Student.objects.get(id__email="[email protected]") | ||
student2 = Student.objects.get(id__email="[email protected]") | ||
student = User.objects.get(id__email="[email protected]") | ||
student2 = User.objects.get(id__email="[email protected]") | ||
self.assertIn(student, group.student.all()) | ||
self.assertIn(student2, group.student.all()) | ||
|
||
|
Oops, something went wrong.