1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Introduce proxy models for User and Group to organize admin UI

This commit is contained in:
Jeremy Stretch
2020-05-29 10:31:34 -04:00
parent f65b2278f0
commit 90828cedae
4 changed files with 81 additions and 39 deletions

View File

@@ -1,18 +1,16 @@
import binascii
import os
from django.contrib.auth.models import Group, User
from django.contrib.auth.models import Group as Group_, User as User_
from django.contrib.contenttypes.models import ContentType
from django.contrib.postgres.fields import JSONField
from django.core.exceptions import FieldError, ValidationError
from django.core.validators import MinLengthValidator
from django.db import models
from django.db.models import Q
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.utils import timezone
from utilities.permissions import resolve_permission
from utilities.utils import flatten_dict
@@ -23,6 +21,30 @@ __all__ = (
)
#
# Proxy models for admin
#
class Group(Group_):
"""
Proxy contrib.auth.models.Group for the admin UI
"""
class Meta:
proxy = True
class User(User_):
"""
Proxy contrib.auth.models.User for the admin UI
"""
class Meta:
proxy = True
#
# User preferences
#
class UserConfig(models.Model):
"""
This model stores arbitrary user-specific preferences in a JSON data structure.
@@ -143,6 +165,10 @@ def create_userconfig(instance, created, **kwargs):
UserConfig(user=instance).save()
#
# REST API
#
class Token(models.Model):
"""
An API token used for user authentication. This extends the stock model to allow each user to have multiple tokens.
@@ -197,6 +223,10 @@ class Token(models.Model):
return True
#
# Permissions
#
class ObjectPermission(models.Model):
"""
A mapping of view, add, change, and/or delete permission for users and/or groups to an arbitrary set of objects