From 6f570bcbf1726fe1b3139c00212d90dd01eeb579 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 4 Jul 2019 17:20:42 +0800 Subject: [PATCH] =?UTF-8?q?[update]=20=E4=BF=AE=E6=94=B9Node=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=A2=AB=E5=88=A0=E9=99=A4=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/models/node.py | 14 +++++++++++++- apps/jumpserver/settings.py | 8 ++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/apps/assets/models/node.py b/apps/assets/models/node.py index bdb12fa6f..97b2d4ded 100644 --- a/apps/assets/models/node.py +++ b/apps/assets/models/node.py @@ -9,13 +9,18 @@ from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext from django.core.cache import cache -from orgs.mixins import OrgModelMixin +from orgs.mixins import OrgModelMixin, OrgManager from orgs.utils import set_current_org, get_current_org from orgs.models import Organization __all__ = ['Node'] +class NodeQuerySet(models.QuerySet): + def delete(self): + raise PermissionError("Bulk delete node deny") + + class FamilyMixin: _parents = None _children = None @@ -242,6 +247,7 @@ class Node(OrgModelMixin, FamilyMixin, FullValueMixin, AssetsAmountMixin): child_mark = models.IntegerField(default=0) date_create = models.DateTimeField(auto_now_add=True) + objects = OrgManager.from_queryset(NodeQuerySet)() is_node = True _parents = None @@ -391,6 +397,7 @@ class Node(OrgModelMixin, FamilyMixin, FullValueMixin, AssetsAmountMixin): "name": self.name, "value": self.value, "key": self.key, + "assets_amount": self.assets_amount, }, 'type': 'node' } @@ -398,6 +405,11 @@ class Node(OrgModelMixin, FamilyMixin, FullValueMixin, AssetsAmountMixin): tree_node = TreeNode(**data) return tree_node + def delete(self, using=None, keep_parents=False): + if self.children or self.assets.get_assets(): + return + return super().delete(using=using, keep_parents=keep_parents) + @classmethod def get_queryset(cls): from ..utils import NodeUtil diff --git a/apps/jumpserver/settings.py b/apps/jumpserver/settings.py index 0f9f7df55..0ca68d947 100644 --- a/apps/jumpserver/settings.py +++ b/apps/jumpserver/settings.py @@ -301,10 +301,10 @@ LOGGING = { 'handlers': ['gunicorn_console', 'gunicorn_file'], 'level': 'INFO', }, - 'django.db': { - 'handlers': ['console', 'file'], - 'level': 'DEBUG' - } + # 'django.db': { + # 'handlers': ['console', 'file'], + # 'level': 'DEBUG' + # } } }