Commit dda876be authored by ibuler's avatar ibuler

[Update] Stash it

parent 51b0fee9
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.conf import settings
from common.fields import JsonListTextField from common.fields import JsonListTextField
from orgs.mixins import OrgModelMixin
class BaseRole(models.Model): class BaseRole(models.Model):
...@@ -13,38 +14,38 @@ class BaseRole(models.Model): ...@@ -13,38 +14,38 @@ class BaseRole(models.Model):
class Meta: class Meta:
abstract = True abstract = True
def __str__(self):
return self.name
class Role(BaseRole):
org_id = models.CharField(max_length=36, blank=True, default='', class Role(OrgModelMixin, BaseRole):
verbose_name=_("Organization"), db_index=True) pass
class ClusterRole(BaseRole): class ClusterRole(BaseRole):
non_resource_urls = JsonListTextField() pass
class Rule(models.Model): class Rule(models.Model):
VERBOSE_CHOICES = [
('list', 'List'),
('retrieve', 'Retrieve'),
('create', 'Create'),
('update', 'Update'),
('patch', 'PartialUpdate'),
('delete', 'Delete'),
]
api_groups = JsonListTextField()
resources = JsonListTextField()
resourcesIDs = JsonListTextField()
verbs = JsonListTextField() verbs = JsonListTextField()
apps = JsonListTextField()
resources = JsonListTextField()
resources_ids = JsonListTextField()
non_resource_urls = JsonListTextField()
class BaseRoleBinding(models.Model): class BaseRoleBinding(models.Model):
role = models.ForeignKey('Role', on_delete=models.CASCADE)
users = models.ManyToManyField(settings.AUTH_USER_MODEL)
groups = models.ManyToManyField(settings.AUTH_GROUP_MODEL)
date_created = models.DateTimeField(auto_now_add=True)
created_by = models.CharField(max_length=128, blank=True, default='')
class Meta: class Meta:
abstract = True abstract = True
class RoleBinding(BaseRoleBinding): class RoleBinding(OrgModelMixin, BaseRoleBinding):
pass pass
......
...@@ -8,7 +8,7 @@ from ..utils import get_signer ...@@ -8,7 +8,7 @@ from ..utils import get_signer
__all__ = [ __all__ = [
'JsonMixin', 'JsonDictMixin', 'JsonListMix', 'JsonTypeMixin', 'JsonMixin', 'JsonDictMixin', 'JsonListMixin', 'JsonTypeMixin',
'JsonCharField', 'JsonTextField', 'JsonListCharField', 'JsonListTextField', 'JsonCharField', 'JsonTextField', 'JsonListCharField', 'JsonListTextField',
'JsonDictCharField', 'JsonDictTextField', 'EncryptCharField', 'JsonDictCharField', 'JsonDictTextField', 'EncryptCharField',
'EncryptTextField', 'EncryptMixin', 'EncryptTextField', 'EncryptMixin',
...@@ -83,18 +83,30 @@ class JsonDictTextField(JsonDictMixin, models.TextField): ...@@ -83,18 +83,30 @@ class JsonDictTextField(JsonDictMixin, models.TextField):
description = _("Marshal dict data to text field") description = _("Marshal dict data to text field")
class JsonListMix(JsonTypeMixin): class JsonListMixin(JsonTypeMixin):
tp = list tp = list
class JsonListCharField(JsonListMix, models.CharField): class JsonStrListMixin(JsonListMixin):
pass
class JsonListCharField(JsonListMixin, models.CharField):
description = _("Marshal list data to char field") description = _("Marshal list data to char field")
class JsonListTextField(JsonListMix, models.TextField): class JsonListTextField(JsonListMixin, models.TextField):
description = _("Marshal list data to text field") description = _("Marshal list data to text field")
class JsonCharField(JsonMixin, models.CharField):
description = _("Marshal data to char field")
class JsonTextField(JsonMixin, models.TextField):
description = _("Marshal data to text field")
class EncryptMixin: class EncryptMixin:
def from_db_value(self, value, expression, connection, context): def from_db_value(self, value, expression, connection, context):
if value is not None: if value is not None:
...@@ -117,9 +129,4 @@ class EncryptCharField(EncryptMixin, models.CharField): ...@@ -117,9 +129,4 @@ class EncryptCharField(EncryptMixin, models.CharField):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
class JsonCharField(JsonMixin, models.CharField):
description = _("Marshal data to char field")
class JsonTextField(JsonMixin, models.TextField):
description = _("Marshal data to text field")
...@@ -64,6 +64,7 @@ INSTALLED_APPS = [ ...@@ -64,6 +64,7 @@ INSTALLED_APPS = [
'terminal.apps.TerminalConfig', 'terminal.apps.TerminalConfig',
'audits.apps.AuditsConfig', 'audits.apps.AuditsConfig',
'authentication.apps.AuthenticationConfig', # authentication 'authentication.apps.AuthenticationConfig', # authentication
'authorization.apps.AuthorizationConfig',
'rest_framework', 'rest_framework',
'rest_framework_swagger', 'rest_framework_swagger',
'drf_yasg', 'drf_yasg',
...@@ -367,6 +368,7 @@ AUTHENTICATION_BACKENDS = [ ...@@ -367,6 +368,7 @@ AUTHENTICATION_BACKENDS = [
# Custom User Auth model # Custom User Auth model
AUTH_USER_MODEL = 'users.User' AUTH_USER_MODEL = 'users.User'
AUTH_GROUP_MODEL = 'users.UserGroup'
# File Upload Permissions # File Upload Permissions
FILE_UPLOAD_PERMISSIONS = 0o644 FILE_UPLOAD_PERMISSIONS = 0o644
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment