Skip to content

Commit

Permalink
update role check in dashboard access view
Browse files Browse the repository at this point in the history
  • Loading branch information
TareqMonwer committed Nov 1, 2024
1 parent dfbd590 commit c7a8ea4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions django_school_management/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from permission_handlers.administrative import (
user_is_admin_or_su, user_is_teacher_or_administrative
)
from permission_handlers.basic import user_is_verified
from permission_handlers.basic import user_is_verified, can_access_dashboard
from .services.profile_complete import ProfileCompleteService


Expand Down Expand Up @@ -65,7 +65,7 @@ def profile_complete(request):


@user_passes_test(
user_is_teacher_or_administrative,
can_access_dashboard,
login_url='account:profile_complete')
def dashboard(request):
total_students = Student.objects.count()
Expand Down
11 changes: 11 additions & 0 deletions permission_handlers/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from django.http import HttpResponse
from django.contrib.auth.decorators import login_required

from permission_handlers.role_enums import RoleEnums


@login_required
def permission_error(request):
return HttpResponse('You don\'t have right permissio to access this page.')
Expand All @@ -20,3 +23,11 @@ def user_is_student(user):
def user_is_teacher(user):
return user_is_verified(user) and user.requested_role == 'teacher' \
if user.is_authenticated else False

def can_access_dashboard(user):
restricted_roles = [
RoleEnums.subscriber.value
]
if user.requested_role in restricted_roles:
return False
return True
10 changes: 10 additions & 0 deletions permission_handlers/role_enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from enum import Enum


class RoleEnums(Enum):
subscriber = 'subscriber'
student = 'student'
teacher = 'teacher'
editor = 'editor'
academic_officer = 'academic_officer'
admin = 'admin'

0 comments on commit c7a8ea4

Please sign in to comment.