UPDATE
This commit is contained in:
@@ -1,21 +1,60 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class PermissionToAction(BaseModel):
|
||||
name = models.CharField(max_length=200)
|
||||
code = models.CharField(max_length=100, unique=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name} - {self.code}"
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Harakatlar uchun ruxsatnoma')
|
||||
verbose_name_plural = _('Harakatlar uchun ruxsatnomalar')
|
||||
|
||||
|
||||
class PermissionToTab(BaseModel):
|
||||
name = models.CharField(max_length=200)
|
||||
code = models.CharField(max_length=100, unique=True)
|
||||
permission_to_actions = models.ManyToManyField(
|
||||
PermissionToAction, related_name='permission_to_tabs'
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.name} - {self.code}'
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("Bo'lim uchun ruxsatnoma")
|
||||
verbose_name_plural = _("Bo'lim uchun ruxsatnomalar")
|
||||
|
||||
|
||||
class Permission(BaseModel):
|
||||
name = models.CharField(max_length=200)
|
||||
code = models.CharField(max_length=100, unique=True)
|
||||
permission_tab = models.ManyToManyField(PermissionToTab, related_name='permissions')
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.name} - {self.code}'
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Sahifa uchun ruxsatnoma')
|
||||
verbose_name_plural = _('Sahifa uchun ruxsatnomalar')
|
||||
|
||||
class Role(models.Model):
|
||||
name = models.CharField(max_length=50)
|
||||
name = models.CharField(max_length=200, unique=True)
|
||||
permissions = models.ManyToManyField(Permission, related_name='roles', blank=True)
|
||||
permission_to_tabs = models.ManyToManyField(PermissionToTab, related_name='roles', blank=True)
|
||||
permission_to_actions = models.ManyToManyField(
|
||||
PermissionToAction, related_name='roles', blank=True
|
||||
)
|
||||
comment = models.CharField(max_length=200, null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Permission(models.Model):
|
||||
class Action(models.TextChoices):
|
||||
CREATE = "create_avto_valuation"
|
||||
CREATE_FAST = "create_fast_auto_valuation"
|
||||
CREATE_AVTO_APPEAL = "create_avto_appeal"
|
||||
class Meta:
|
||||
verbose_name = _('Rol')
|
||||
verbose_name_plural = _('Rollar')
|
||||
|
||||
page = models.CharField(max_length=100)
|
||||
section = models.CharField(max_length=100, null=True, blank=True)
|
||||
action = models.CharField(max_length=20, choices=Action.choices)
|
||||
|
||||
|
||||
class RolePermission(models.Model):
|
||||
role = models.ForeignKey(Role, on_delete=models.CASCADE)
|
||||
permission = models.ForeignKey(Permission, on_delete=models.CASCADE)
|
||||
|
||||
Reference in New Issue
Block a user