Skip to content

Commit

Permalink
naming change, permission for project api
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderVanOyen committed Mar 11, 2024
1 parent 2bd063a commit 68fc4c1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
22 changes: 9 additions & 13 deletions backend/pigeonhole/apps/projects/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@ class CanAccessProject(permissions.BasePermission):
# to the project data.
def has_permission(self, request, view):
user = request.user
subject_id = view.kwargs.get('course_id')
# If the user is a teacher, grant access.
# if isinstance(user, Teacher):
# if user.course.filter(id=subject_id).exists():
# return True
# elif isinstance(user, Teacher) and user.is_admin:
# return True
# # If the user is a student, grant access only to their own projects.
# elif isinstance(user, Student):
# if user.course.filter(id=subject_id).exists():
# return True
# elif request.user.is_superuser:
# return True
course_id = view.kwargs.get('course_id')
if user.is_student:
if user.course.filter(course_id=course_id).exists():
return True
elif user.is_teacher:
if user.course.filter(course_id=course_id).exists():
return True
elif user.is_admin or user.is_superuser:
return True
return False
6 changes: 3 additions & 3 deletions backend/pigeonhole/apps/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class Roles(models.IntegerChoices):
SUPERUSER = 1
ADMIN = 1
TEACHER = 2
STUDENT = 3

Expand All @@ -29,8 +29,8 @@ def name(self):
return f"{self.first_name.strip()} {self.last_name.strip()}"

@property
def is_super(self):
return self.role == Roles.SUPERUSER
def is_admin(self):
return self.role == Roles.ADMIN

@property
def is_teacher(self):
Expand Down

0 comments on commit 68fc4c1

Please sign in to comment.