mirror of https://github.com/jumpserver/jumpserver
feat: node api 支持使用 full_value 递归创建
parent
b0932e5137
commit
dde7559f47
|
@ -17,7 +17,7 @@ from common.mixins.api import SuggestionMixin
|
||||||
from assets.models import Asset
|
from assets.models import Asset
|
||||||
from common.utils import get_logger, get_object_or_none
|
from common.utils import get_logger, get_object_or_none
|
||||||
from common.tree import TreeNodeSerializer
|
from common.tree import TreeNodeSerializer
|
||||||
from orgs.mixins.api import OrgModelViewSet
|
from orgs.mixins.api import OrgBulkModelViewSet
|
||||||
from orgs.mixins import generics
|
from orgs.mixins import generics
|
||||||
from orgs.utils import current_org
|
from orgs.utils import current_org
|
||||||
from ..hands import IsOrgAdmin
|
from ..hands import IsOrgAdmin
|
||||||
|
@ -42,19 +42,13 @@ __all__ = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class NodeViewSet(SuggestionMixin, OrgModelViewSet):
|
class NodeViewSet(SuggestionMixin, OrgBulkModelViewSet):
|
||||||
model = Node
|
model = Node
|
||||||
filterset_fields = ('value', 'key', 'id')
|
filterset_fields = ('value', 'key', 'id')
|
||||||
search_fields = ('value', )
|
search_fields = ('value', )
|
||||||
permission_classes = (IsOrgAdmin,)
|
permission_classes = (IsOrgAdmin,)
|
||||||
serializer_class = serializers.NodeSerializer
|
serializer_class = serializers.NodeSerializer
|
||||||
|
|
||||||
# 仅支持根节点指直接创建,子节点下的节点需要通过children接口创建
|
|
||||||
def perform_create(self, serializer):
|
|
||||||
child_key = Node.org_root().get_next_child_key()
|
|
||||||
serializer.validated_data["key"] = child_key
|
|
||||||
serializer.save()
|
|
||||||
|
|
||||||
@action(methods=[POST], detail=False, url_path='check_assets_amount_task')
|
@action(methods=[POST], detail=False, url_path='check_assets_amount_task')
|
||||||
def check_assets_amount_task(self, request):
|
def check_assets_amount_task(self, request):
|
||||||
task = check_node_assets_amount_task.delay(current_org.id)
|
task = check_node_assets_amount_task.delay(current_org.id)
|
||||||
|
|
|
@ -17,6 +17,9 @@ class NodeSerializer(BulkOrgResourceModelSerializer):
|
||||||
value = serializers.CharField(
|
value = serializers.CharField(
|
||||||
required=False, allow_blank=True, allow_null=True, label=_("value")
|
required=False, allow_blank=True, allow_null=True, label=_("value")
|
||||||
)
|
)
|
||||||
|
full_value = serializers.CharField(
|
||||||
|
required=False, allow_blank=True, allow_null=True, label=_("Full value")
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Node
|
model = Node
|
||||||
|
@ -40,6 +43,19 @@ class NodeSerializer(BulkOrgResourceModelSerializer):
|
||||||
)
|
)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
full_value = validated_data.get('full_value')
|
||||||
|
value = validated_data.get('value')
|
||||||
|
|
||||||
|
# 直接多层级创建
|
||||||
|
if full_value:
|
||||||
|
node = Node.create_node_by_full_value(full_value)
|
||||||
|
# 根据 value 在 root 下创建
|
||||||
|
else:
|
||||||
|
key = Node.org_root().get_next_child_key()
|
||||||
|
node = Node.objects.create(key=key, value=value)
|
||||||
|
return node
|
||||||
|
|
||||||
|
|
||||||
class NodeAssetsSerializer(BulkOrgResourceModelSerializer):
|
class NodeAssetsSerializer(BulkOrgResourceModelSerializer):
|
||||||
assets = serializers.PrimaryKeyRelatedField(
|
assets = serializers.PrimaryKeyRelatedField(
|
||||||
|
|
Loading…
Reference in New Issue