Debian Codegraph @

tests/auth_tests/models/custom_permissions.py

raw
1 """
2 The CustomPermissionsUser users email as the identifier, but uses the normal
3 Django permissions model. This allows us to check that the PermissionsMixin
4 includes everything that is needed to interact with the ModelBackend.
5 """
6
7 from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
8 from django.db import models
9
10 from .custom_user import CustomUserManager, RemoveGroupsAndPermissions
11
12
13 class CustomPermissionsUserManager(CustomUserManager):
14 def create_superuser(self, email, password, date_of_birth):
15 u = self.create_user(email, password=password, date_of_birth=date_of_birth)
16 u.is_superuser = True
17 u.save(using=self._db)
18 return u
19
20
21 with RemoveGroupsAndPermissions():
22
23 class CustomPermissionsUser(AbstractBaseUser, PermissionsMixin):
24 email = models.EmailField(
25 verbose_name="email address", max_length=255, unique=True
26 )
27 date_of_birth = models.DateField()
28
29 custom_objects = CustomPermissionsUserManager()
30
31 USERNAME_FIELD = "email"
32 REQUIRED_FIELDS = ["date_of_birth"]
33
34 def __str__(self):
35 return self.email