mirror of https://github.com/jumpserver/jumpserver
[Bugfix] 资产树节点Node Value值校验修改异常抛出为400
parent
4c53eebdbe
commit
cbc4a0a97b
|
@ -14,6 +14,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
from rest_framework import generics, mixins
|
||||
from rest_framework.serializers import ValidationError
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework_bulk import BulkModelViewSet
|
||||
|
@ -110,7 +111,9 @@ class NodeChildrenApi(mixins.ListModelMixin, generics.CreateAPIView):
|
|||
value = request.data.get("value")
|
||||
values = [child.value for child in instance.get_children()]
|
||||
if value in values:
|
||||
raise AssertionError('The same level node name cannot be the same')
|
||||
raise ValidationError(
|
||||
'The same level node name cannot be the same'
|
||||
)
|
||||
node = instance.create_child(value=value)
|
||||
return Response(
|
||||
{"id": node.id, "key": node.key, "value": node.value},
|
||||
|
|
|
@ -51,14 +51,17 @@ class NodeSerializer(serializers.ModelSerializer):
|
|||
fields = ['id', 'key', 'value', 'parent', 'assets_amount', 'is_node']
|
||||
list_serializer_class = BulkListSerializer
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
value = validated_data.get('value')
|
||||
def validate(self, data):
|
||||
value = data.get('value')
|
||||
instance = self.instance
|
||||
if not instance.is_root():
|
||||
children = instance.parent.get_children().exclude(key=instance.key)
|
||||
values = [child.value for child in children]
|
||||
if value in values:
|
||||
raise AssertionError('The same level node name cannot be the same')
|
||||
return super().update(instance, validated_data)
|
||||
raise serializers.ValidationError(
|
||||
'The same level node name cannot be the same'
|
||||
)
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
def get_parent(obj):
|
||||
|
|
Loading…
Reference in New Issue