permissions mixin for user model
This commit is contained in:
parent
dcfbc0ea66
commit
0e7ca80e92
@ -1,8 +1,6 @@
|
||||
# Generated by Django 5.0.1 on 2024-03-27 11:13
|
||||
# Generated by Django 5.0.4 on 2024-05-03 13:14
|
||||
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
@ -11,6 +9,7 @@ class Migration(migrations.Migration):
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('auth', '0012_alter_user_first_name_max_length'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
@ -27,20 +26,15 @@ class Migration(migrations.Migration):
|
||||
('mfa_enabled', models.BooleanField(help_text='whether the user has two factor enabled on their account', verbose_name='mfa enabled')),
|
||||
('last_login', models.DateTimeField(default=django.utils.timezone.now, help_text='datetime of the previous login', verbose_name='last login')),
|
||||
('access_token', models.CharField(help_text='token for the application to make api calls on behalf of the user.', max_length=100, verbose_name='access token')),
|
||||
('user_type', models.CharField(choices=[('D', 'discord'), ('A', 'automated')], default='D', help_text='What type of user is this?', max_length=32, verbose_name='user type')),
|
||||
('is_active', models.BooleanField(default=True, help_text='Use as a "soft delete" rather than deleting the user.', verbose_name='active status')),
|
||||
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
|
||||
('is_superuser', models.BooleanField(default=False, help_text='Designates whether the user has unrestricted site control.', verbose_name='superuser status')),
|
||||
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
|
||||
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='UserServerLink',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('server_id', models.PositiveBigIntegerField()),
|
||||
('name', models.CharField(max_length=64)),
|
||||
('permissions', models.IntegerField()),
|
||||
('icon', models.CharField(help_text="the guild's icon hash", max_length=64, verbose_name='icon')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
||||
|
@ -1,18 +0,0 @@
|
||||
# Generated by Django 5.0.1 on 2024-03-27 11:24
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('authentication', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='userserverlink',
|
||||
name='icon',
|
||||
field=models.CharField(blank=True, help_text="the guild's icon hash", max_length=64, null=True, verbose_name='icon'),
|
||||
),
|
||||
]
|
@ -1,16 +0,0 @@
|
||||
# Generated by Django 5.0.1 on 2024-04-25 16:46
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('authentication', '0002_alter_userserverlink_icon'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.DeleteModel(
|
||||
name='UserServerLink',
|
||||
),
|
||||
]
|
@ -3,12 +3,12 @@
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
# from django.contrib.auth.models import AbstractBaseUser
|
||||
from django.contrib.auth.models import PermissionsMixin
|
||||
|
||||
from .managers import DiscordUserOAuth2Manager
|
||||
|
||||
|
||||
class DiscordUser(models.Model):
|
||||
class DiscordUser(PermissionsMixin):
|
||||
"""
|
||||
Represents a User authenticated with Discord OAuth2.
|
||||
"""
|
||||
@ -68,6 +68,18 @@ class DiscordUser(models.Model):
|
||||
|
||||
# Custom Attributes
|
||||
|
||||
class USER_TYPES(models.TextChoices):
|
||||
DISCORD_USER = "D", _("discord")
|
||||
AUTOMATED_USER = "A", _("automated")
|
||||
|
||||
user_type = models.CharField(
|
||||
_("user type"),
|
||||
choices=USER_TYPES,
|
||||
default=USER_TYPES.DISCORD_USER,
|
||||
max_length=32,
|
||||
help_text=_("What type of user is this?")
|
||||
)
|
||||
|
||||
is_active = models.BooleanField(
|
||||
_("active status"),
|
||||
default=True,
|
||||
@ -112,9 +124,3 @@ class DiscordUser(models.Model):
|
||||
|
||||
def get_username(self):
|
||||
return self.username
|
||||
|
||||
def has_perm(self, perm, obj=None):
|
||||
return self.is_superuser
|
||||
|
||||
def has_module_perms(self, app_label):
|
||||
return self.is_superuser
|
||||
|
Loading…
x
Reference in New Issue
Block a user