From ed117ceac3b4ba18d3093c4dd219135568bd53e1 Mon Sep 17 00:00:00 2001 From: Bai Date: Thu, 1 Jun 2023 16:22:17 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E6=97=B6=E6=A0=A1=E9=AA=8C=E5=90=8C=E7=BA=A7?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E5=90=8D=E7=A7=B0=E4=B8=8D=E5=85=81=E8=AE=B8?= =?UTF-8?q?=E9=87=8D=E5=A4=8D(API=E6=96=B9=E5=BC=8F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/api/tree.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/assets/api/tree.py b/apps/assets/api/tree.py index f27afd019..794e093b7 100644 --- a/apps/assets/api/tree.py +++ b/apps/assets/api/tree.py @@ -3,10 +3,12 @@ from django.db.models import Q from rest_framework.generics import get_object_or_404 from rest_framework.response import Response +from django.utils.translation import gettext_lazy as _ from assets.locks import NodeAddChildrenLock from common.tree import TreeNodeSerializer from common.utils import get_logger +from common.exceptions import JMSException from orgs.mixins import generics from orgs.utils import current_org from .mixin import SerializeToTreeNodeMixin @@ -41,7 +43,11 @@ class NodeChildrenApi(generics.ListCreateAPIView): data = serializer.validated_data _id = data.get("id") value = data.get("value") - if not value: + if value: + children = self.instance.get_children() + if children.filter(value=value).exists(): + raise JMSException(_('The same level node name cannot be the same')) + else: value = self.instance.get_next_child_preset_name() node = self.instance.create_child(value=value, _id=_id) # 避免查询 full value