Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add permission functions, fix admin page. #97

Merged
merged 2 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading