Skip to content

Commit

Permalink
restrict non-approved users from accessing dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
TareqMonwer committed Dec 31, 2024
1 parent 8ffc8fb commit 0666bc8
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions permission_handlers/basic.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,54 @@
"""
Handling permissions for users who are assigned
Handling permissions for users who are assigned
for basic level actions in the project. (view few data, modify some of their data etc).
UserTypes: Student, Teacher
"""

from django.http import HttpResponse
from django.contrib.auth.decorators import login_required

from django_school_management.accounts.constants import AccountTypesEnum
from django_school_management.accounts.constants import (
AccountTypesEnum,
ProfileApprovalStatusEnum,
)
from django_school_management.accounts.models import User


@login_required
def permission_error(request):
return HttpResponse('You don\'t have right permissio to access this page.')
return HttpResponse("You don't have right permission to access this page.")


def user_is_verified(user):
return user.approval_status == 'a' if user.is_authenticated else False
return (
user.approval_status == ProfileApprovalStatusEnum.approved.value
if user.is_authenticated
else False
)


def user_is_student(user):
return user_is_verified(user) and user.requested_role == 'student' \
if user.is_authenticated else False
return (
user_is_verified(user)
and user.requested_role == AccountTypesEnum.student.value
if user.is_authenticated
else False
)


def user_is_teacher(user):
return user_is_verified(user) and user.requested_role == 'teacher' \
if user.is_authenticated else False
return (
user_is_verified(user)
and user.requested_role == AccountTypesEnum.teacher.value
if user.is_authenticated
else False
)


def can_access_dashboard(user):
restricted_roles = [
AccountTypesEnum.subscriber.value
]
def can_access_dashboard(user: User):
restricted_roles = [AccountTypesEnum.subscriber.value]
if user.requested_role in restricted_roles:
return False
if user.approval_status != ProfileApprovalStatusEnum.approved.value:
return False
return True

0 comments on commit 0666bc8

Please sign in to comment.