mirror of https://github.com/jumpserver/jumpserver
				
				
				
			[Bugfix] 修复节点前面有个空目录
							parent
							
								
									7e3cf908a1
								
							
						
					
					
						commit
						eca245fdd5
					
				| 
						 | 
				
			
			@ -42,13 +42,6 @@ class NodeViewSet(viewsets.ModelViewSet):
 | 
			
		|||
    permission_classes = (IsOrgAdmin,)
 | 
			
		||||
    serializer_class = serializers.NodeSerializer
 | 
			
		||||
 | 
			
		||||
    def get_queryset(self):
 | 
			
		||||
        # queryset = super(NodeViewSet, self).get_queryset()
 | 
			
		||||
        print("API GET QUWRYSET")
 | 
			
		||||
        # print(get_current_org())
 | 
			
		||||
        # print(queryset)
 | 
			
		||||
        return Node.objects.all()
 | 
			
		||||
 | 
			
		||||
    def perform_create(self, serializer):
 | 
			
		||||
        child_key = Node.root().get_next_child_key()
 | 
			
		||||
        serializer.validated_data["key"] = child_key
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -178,12 +178,15 @@ class Node(OrgModelMixin):
 | 
			
		|||
        # 如果使用current_org 在set_current_org时会死循环
 | 
			
		||||
        _current_org = get_current_org()
 | 
			
		||||
        with transaction.atomic():
 | 
			
		||||
            set_current_org(Organization.root())
 | 
			
		||||
            org_nodes_roots = cls.objects.filter(key__regex=r'^[0-9]+$')
 | 
			
		||||
            org_nodes_roots_keys = org_nodes_roots.values_list('key', flat=True)
 | 
			
		||||
            max_value = max([int(k) for k in org_nodes_roots_keys]) if org_nodes_roots_keys else -1
 | 
			
		||||
            set_current_org(_current_org)
 | 
			
		||||
            root = cls.objects.create(key=str(max_value+1), value=_current_org.name)
 | 
			
		||||
            if _current_org.is_default():
 | 
			
		||||
                key = '0'
 | 
			
		||||
            else:
 | 
			
		||||
                set_current_org(Organization.root())
 | 
			
		||||
                org_nodes_roots = cls.objects.filter(key__regex=r'^[0-9]+$')
 | 
			
		||||
                org_nodes_roots_keys = org_nodes_roots.values_list('key', flat=True)
 | 
			
		||||
                key = max([int(k) for k in org_nodes_roots_keys]) + 1
 | 
			
		||||
                set_current_org(_current_org)
 | 
			
		||||
            root = cls.objects.create(key=key, value=_current_org.name)
 | 
			
		||||
            return root
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,7 +26,7 @@ class NodeGrantedSerializer(BulkSerializerMixin, serializers.ModelSerializer):
 | 
			
		|||
        model = Node
 | 
			
		||||
        fields = [
 | 
			
		||||
            'id', 'key', 'name', 'value', 'parent',
 | 
			
		||||
            'assets_granted', 'assets_amount',
 | 
			
		||||
            'assets_granted', 'assets_amount', 'org_id',
 | 
			
		||||
        ]
 | 
			
		||||
 | 
			
		||||
    @staticmethod
 | 
			
		||||
| 
						 | 
				
			
			@ -48,7 +48,10 @@ class NodeSerializer(serializers.ModelSerializer):
 | 
			
		|||
 | 
			
		||||
    class Meta:
 | 
			
		||||
        model = Node
 | 
			
		||||
        fields = ['id', 'key', 'value', 'parent', 'assets_amount', 'is_node']
 | 
			
		||||
        fields = [
 | 
			
		||||
            'id', 'key', 'value', 'parent', 'assets_amount',
 | 
			
		||||
            'is_node', 'org_id',
 | 
			
		||||
        ]
 | 
			
		||||
        list_serializer_class = BulkListSerializer
 | 
			
		||||
 | 
			
		||||
    def validate(self, data):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -406,10 +406,11 @@ function initTree() {
 | 
			
		|||
    var zNodes = [];
 | 
			
		||||
    $.get("{% url 'api-assets:node-list' %}", function(data, status){
 | 
			
		||||
        $.each(data, function (index, value) {
 | 
			
		||||
            value["pId"] = value["parent"];
 | 
			
		||||
            if (value["key"] === "0") {
 | 
			
		||||
                value["open"] = true;
 | 
			
		||||
             }
 | 
			
		||||
            if (value["parent"] !== value["id"]){
 | 
			
		||||
                value["pId"] = value["parent"];
 | 
			
		||||
            } else {
 | 
			
		||||
                value["isParent"] = true;
 | 
			
		||||
            }
 | 
			
		||||
            value["name"] = value["value"] + ' (' + value['assets_amount'] + ')';
 | 
			
		||||
            value['value'] = value['value'];
 | 
			
		||||
        });
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -240,9 +240,12 @@ function initTree() {
 | 
			
		|||
    var zNodes = [];
 | 
			
		||||
    $.get("{% url 'api-assets:node-children-2' %}?assets=1&all=", function(data, status){
 | 
			
		||||
        $.each(data, function (index, value) {
 | 
			
		||||
            value["pId"] = value["parent"];
 | 
			
		||||
             if (value["parent"] !== value["id"]){
 | 
			
		||||
                value["pId"] = value["parent"];
 | 
			
		||||
            } else {
 | 
			
		||||
                value["isParent"] = true;
 | 
			
		||||
            }
 | 
			
		||||
            value["name"] = value["value"];
 | 
			
		||||
            value["open"] = value["key"] === "0";
 | 
			
		||||
            value["isParent"] = value["is_node"];
 | 
			
		||||
            value["iconSkin"] = value["is_node"] ? null : 'file';
 | 
			
		||||
        });
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,7 +15,7 @@
 | 
			
		|||
        <a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false" style="display: block; background-color: transparent; color: #8095a8; padding: 14px 20px 14px 25px">
 | 
			
		||||
            <i class="fa fa-bookmark" style="width: 14px; "></i>
 | 
			
		||||
            <span class="nav-label" style="padding-left: 7px">
 | 
			
		||||
                {% trans 'Org' %} - {{ CURRENT_ORG.name }}
 | 
			
		||||
                {{ CURRENT_ORG.name }}
 | 
			
		||||
            </span>
 | 
			
		||||
            <span class="fa fa-sort-desc pull-right"></span>
 | 
			
		||||
        </a>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue