From 790652ff4ddef8e5bd08b78246981157756645f2 Mon Sep 17 00:00:00 2001 From: ibuler Date: Tue, 17 Jul 2018 17:09:36 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E4=BF=AE=E6=94=B9=E5=8D=8F=E8=AE=AE?= =?UTF-8?q?=E5=B0=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/forms/domain.py | 3 ++- apps/assets/models/base.py | 2 +- apps/assets/models/domain.py | 4 +++- apps/assets/models/node.py | 7 ------- apps/assets/models/user.py | 2 ++ 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/apps/assets/forms/domain.py b/apps/assets/forms/domain.py index ec3af8f2e..1b005ec2f 100644 --- a/apps/assets/forms/domain.py +++ b/apps/assets/forms/domain.py @@ -3,6 +3,7 @@ from django import forms from django.utils.translation import gettext_lazy as _ +from orgs.mixins import OrgModelForm from ..models import Domain, Asset, Gateway from .user import PasswordAndKeyAuthForm @@ -34,7 +35,7 @@ class DomainForm(forms.ModelForm): return instance -class GatewayForm(PasswordAndKeyAuthForm): +class GatewayForm(PasswordAndKeyAuthForm, OrgModelForm): def save(self, commit=True): # Because we define custom field, so we need rewrite :method: `save` diff --git a/apps/assets/models/base.py b/apps/assets/models/base.py index 3698f3a05..b03010905 100644 --- a/apps/assets/models/base.py +++ b/apps/assets/models/base.py @@ -19,7 +19,7 @@ signer = get_signer() class AssetUser(OrgModelMixin): id = models.UUIDField(default=uuid.uuid4, primary_key=True) - name = models.CharField(max_length=128, unique=True, verbose_name=_('Name')) + name = models.CharField(max_length=128, verbose_name=_('Name')) username = models.CharField(max_length=32, blank=True, verbose_name=_('Username'), validators=[alphanumeric]) _password = models.CharField(max_length=256, blank=True, null=True, verbose_name=_('Password')) _private_key = models.TextField(max_length=4096, blank=True, null=True, verbose_name=_('SSH private key'), validators=[private_key_validator, ]) diff --git a/apps/assets/models/domain.py b/apps/assets/models/domain.py index 67283bd80..8a25cb69e 100644 --- a/apps/assets/models/domain.py +++ b/apps/assets/models/domain.py @@ -34,7 +34,7 @@ class Domain(OrgModelMixin): return random.choice(self.gateways) -class Gateway(AssetUser): +class Gateway(AssetUser, OrgModelMixin): SSH_PROTOCOL = 'ssh' RDP_PROTOCOL = 'rdp' PROTOCOL_CHOICES = ( @@ -51,3 +51,5 @@ class Gateway(AssetUser): def __str__(self): return self.name + class Meta: + unique_together = ['name', 'org'] diff --git a/apps/assets/models/node.py b/apps/assets/models/node.py index b75bea863..34fc20680 100644 --- a/apps/assets/models/node.py +++ b/apps/assets/models/node.py @@ -64,9 +64,6 @@ class Node(OrgModelMixin): def create_child(self, value): with transaction.atomic(): child_key = self.get_next_child_key() - print("Create child") - print(self.key) - print(child_key) child = self.__class__.objects.create(key=child_key, value=value) return child @@ -123,8 +120,6 @@ class Node(OrgModelMixin): return self.get_all_assets().valid() def is_root(self): - print(type(self.key)) - print(self.key) if self.key.isdigit(): return True else: @@ -159,7 +154,6 @@ class Node(OrgModelMixin): if self.is_root(): root = self.__class__.root() return [root] - print(self.key) _key = self.key.split(':') if not with_self: _key.pop() @@ -187,7 +181,6 @@ class Node(OrgModelMixin): @classmethod def root(cls): root = cls.objects.filter(key__regex=r'^[0-9]+$') - print("GET ROOT NODE") if len(root) == 1: return root.get() else: diff --git a/apps/assets/models/user.py b/apps/assets/models/user.py index 5faca5da8..ffe5cc44d 100644 --- a/apps/assets/models/user.py +++ b/apps/assets/models/user.py @@ -69,6 +69,7 @@ class AdminUser(AssetUser): class Meta: ordering = ['name'] + unique_together = ['name', 'org'] verbose_name = _("Admin user") @classmethod @@ -156,6 +157,7 @@ class SystemUser(AssetUser): class Meta: ordering = ['name'] + unique_together = ['name', 'org'] verbose_name = _("System user") @classmethod