Skip to content

Commit

Permalink
Merge pull request #97 from SmoFlaDru/dev-benno
Browse files Browse the repository at this point in the history
Add permission functions, fix admin page.
  • Loading branch information
Bensge authored Jan 28, 2024
2 parents 5015897 + a77391a commit 306e09e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
20 changes: 20 additions & 0 deletions spybot/migrations/0020_mergeduser_is_superuser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.3 on 2024-01-28 16:47

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('spybot', '0019_mergeduser_last_login_mergeduser_password_loginlink'),
]

operations = [
migrations.AddField(
model_name='mergeduser',
name='is_superuser',
field=models.BooleanField(default=False),
),
migrations.RunSQL("UPDATE spybot_mergeduser SET is_superuser=true WHERE id=657;"),
migrations.RunSQL("UPDATE spybot_mergeduser SET is_superuser=true WHERE id=641;"),
]
39 changes: 38 additions & 1 deletion spybot/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# * Make sure each ForeignKey and OneToOneField has `on_delete` set to the desired behavior
# * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
from django.contrib.auth.base_user import AbstractBaseUser
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
from django.db import models
from django.db.models.fields import AutoFieldMixin, PositiveIntegerField, AutoField
from django.utils import timezone
Expand Down Expand Up @@ -53,12 +53,49 @@ def rel_db_type(self, connection):
return PositiveIntegerField().db_type(connection=connection)


class MergedUserManager(BaseUserManager):
def create_user(self, email, date_of_birth, password=None):
return None

def create_superuser(self, email, date_of_birth, password=None):
return None


class MergedUser(DebuggableModel, AbstractBaseUser):
name = models.CharField(max_length=128, blank=False, null=False)
obsolete = models.BooleanField(default=False)

is_superuser = models.BooleanField(default=False)

USERNAME_FIELD = 'id'

objects = MergedUserManager()

@property
def is_staff(self):
return self.is_superuser

def get_user_permissions(self, obj=None):
print('get_user_permissions: ', obj)
return None

def get_group_permissions(self, obj=None):
print('get_group_permissions: ', obj)
return None

def get_all_permissions(self, obj=None):
print('get_all_permissions: ', obj)
return None

def has_perm(self, perm, obj=None):
return self.is_superuser

def has_perms(self, perm_list, obj=None):
return self.is_superuser

def has_module_perms(self, package_name):
return self.is_superuser

def merged_user_names(self):
return list(TSUser.objects.values_list('name', flat=True).filter(merged_user=self))

Expand Down
2 changes: 1 addition & 1 deletion spybot/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.test import TestCase, override_settings

from spybot.models import TSUserActivity, TSUser
from spybot.models import TSUserActivity, TSUser, MergedUser

@override_settings(DEBUG=False)
class TSUserTestCase(TestCase):
Expand Down

0 comments on commit 306e09e

Please sign in to comment.