Add document requests app

This commit is contained in:
Keannu Christian Bernasol 2024-11-24 02:20:18 +08:00
parent bb9fcc3d7c
commit ba19412d31
23 changed files with 484 additions and 53 deletions

View file

@ -1,4 +1,4 @@
# Generated by Django 5.1.3 on 2024-11-23 13:04
# Generated by Django 5.1.3 on 2024-11-23 17:01
import django.contrib.auth.models
import django.contrib.auth.validators
@ -69,12 +69,6 @@ class Migration(migrations.Migration):
blank=True, max_length=150, verbose_name="last name"
),
),
(
"email",
models.EmailField(
blank=True, max_length=254, verbose_name="email address"
),
),
(
"is_staff",
models.BooleanField(
@ -91,6 +85,7 @@ class Migration(migrations.Migration):
verbose_name="active",
),
),
("email", models.EmailField(max_length=254, unique=True)),
(
"role",
models.CharField(

View file

@ -1,18 +0,0 @@
# Generated by Django 5.1.3 on 2024-11-23 13:36
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("accounts", "0001_initial"),
]
operations = [
migrations.AlterField(
model_name="customuser",
name="email",
field=models.EmailField(max_length=254, unique=True),
),
]

View file

@ -32,8 +32,4 @@ class CustomUser(AbstractUser):
def save(self, **kwargs):
self.username = self.email
if self.is_staff:
self.role = "staff"
elif self.is_superuser:
self.role = "admin"
super().save(**kwargs)

View file

@ -0,0 +1,22 @@
from rest_framework.permissions import BasePermission
class IsStaff(BasePermission):
"""
Allows access only to users with staff role
"""
def has_permission(self, request, view):
return bool(
request.user and request.user.role in ("head", "admin", "planning", "staff")
)
class IsHead(BasePermission):
"""
Allows access only to users with staff role
"""
def has_permission(self, request, view):
print(request.user.role)
return bool(request.user and request.user.role == "head")