Add IntelliJ IDEA project configuration files
This commit adds IntelliJ IDEA-specific configuration files for the project, including module setup, version control integration, inspection profiles, and workspace settings. These files facilitate development environment configuration for contributors using IntelliJ IDEA.
This commit is contained in:
+66
-6
@@ -1,3 +1,4 @@
|
||||
from django.contrib.auth.base_user import BaseUserManager
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from django.db import models
|
||||
|
||||
@@ -13,11 +14,69 @@ class ClientPermission(models.Model):
|
||||
('can_view_bookings', 'Can view bookings'),
|
||||
('can_manage_company_users', 'Can manage company users'),
|
||||
)
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class EmployeePermission(models.Model):
|
||||
codename = models.CharField(max_length=100, default='')
|
||||
name = models.CharField(max_length=255, default='')
|
||||
|
||||
class Meta:
|
||||
managed = True
|
||||
default_permissions = ()
|
||||
permissions = (
|
||||
('can_manage_containers', 'Can manage containers'),
|
||||
('can_view_reports', 'Can view reports'),
|
||||
('can_handle_operations', 'Can handle operations'),
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class CustomUserManager(BaseUserManager):
|
||||
def create_user(self, email, password=None, **extra_fields):
|
||||
if not email:
|
||||
raise ValueError('Users must have an email address')
|
||||
email = self.normalize_email(email)
|
||||
user = self.model(email=email, **extra_fields)
|
||||
user.set_password(password)
|
||||
user.save(using=self._db)
|
||||
return user
|
||||
|
||||
def create_superuser(self, email, password=None, **extra_fields):
|
||||
extra_fields.setdefault('is_staff', True)
|
||||
extra_fields.setdefault('is_superuser', True)
|
||||
extra_fields.setdefault('is_active', True)
|
||||
extra_fields.setdefault('user_type', 'AD') # Set user_type to admin
|
||||
|
||||
if extra_fields.get('is_staff') is not True:
|
||||
raise ValueError('Superuser must have is_staff=True.')
|
||||
if extra_fields.get('is_superuser') is not True:
|
||||
raise ValueError('Superuser must have is_superuser=True.')
|
||||
|
||||
return self.create_user(email, password, **extra_fields)
|
||||
|
||||
|
||||
class DepotUser(AbstractUser):
|
||||
|
||||
class UserType(models.TextChoices):
|
||||
BARRIER_STAFF = 'BS', 'Barrier Staff'
|
||||
COMPANY_ADMIN = 'CA', 'Company Admin'
|
||||
EMPLOYEE = 'EM', 'Employee'
|
||||
CLIENT = 'CL', 'Client',
|
||||
ADMIN = 'AD', 'Admin'
|
||||
|
||||
objects = CustomUserManager()
|
||||
|
||||
user_type = models.CharField(
|
||||
max_length=2,
|
||||
choices=UserType.choices,
|
||||
default=UserType.CLIENT
|
||||
)
|
||||
|
||||
phone_number = models.CharField(max_length=15, blank=True, null=True)
|
||||
email = models.EmailField(unique=True, blank=False, null=False)
|
||||
company = models.ForeignKey(
|
||||
@@ -36,13 +95,14 @@ class DepotUser(AbstractUser):
|
||||
)
|
||||
|
||||
company_permissions = models.ManyToManyField('ClientPermission')
|
||||
new_field1 = models.BooleanField(default=False)
|
||||
is_company_admin = models.BooleanField(default=False)
|
||||
employee_permissions = models.ManyToManyField('EmployeePermission', blank=True)
|
||||
|
||||
def has_company_perm(self, perm_codename):
|
||||
if self.is_superuser:
|
||||
return True
|
||||
return self.company_permissions.filter(
|
||||
codename=perm_codename,
|
||||
is_client_permission=self.company
|
||||
).exists()
|
||||
return self.company_permissions.filter(codename=perm_codename).exists()
|
||||
|
||||
def has_employee_perm(self, perm_codename):
|
||||
if self.is_superuser:
|
||||
return True
|
||||
return self.employee_permissions.filter(codename=perm_codename).exists()
|
||||
Reference in New Issue
Block a user