Unverified Commit ae564ed0 authored by 老广's avatar 老广 Committed by GitHub

Merge pull request #1670 from jumpserver/dev

Dev
parents fa0bd85f 05ecd749
......@@ -43,15 +43,23 @@ class NodeViewSet(viewsets.ModelViewSet):
permission_classes = (IsOrgAdmin,)
serializer_class = serializers.NodeSerializer
def get_queryset(self):
queryset = super().get_queryset().annotate(Count('assets'))
return queryset
def perform_create(self, serializer):
child_key = Node.root().get_next_child_key()
serializer.validated_data["key"] = child_key
serializer.save()
def update(self, request, *args, **kwargs):
node = self.get_object()
if node.is_root():
node_value = node.value
post_value = request.data.get('value')
if node_value != post_value:
return Response(
{"msg": _("You cant update the root node name")},
status=400
)
return super().update(request, *args, **kwargs)
class NodeChildrenApi(mixins.ListModelMixin, generics.CreateAPIView):
queryset = Node.objects.all()
......@@ -108,9 +116,9 @@ class NodeChildrenApi(mixins.ListModelMixin, generics.CreateAPIView):
queryset.append(node)
if query_all:
children = node.get_all_children().annotate(Count("assets"))
children = node.get_all_children()
else:
children = node.get_children().annotate(Count("assets"))
children = node.get_children()
queryset.extend(list(children))
if query_assets:
......
......@@ -199,6 +199,11 @@ class Node(OrgModelMixin):
else:
return cls.create_root_node()
@classmethod
def default_node(cls):
defaults = {'value': 'Default'}
return cls.objects.get_or_create(defaults=defaults, key='0')
@classmethod
def generate_fake(cls, count=100):
import random
......
......@@ -68,7 +68,7 @@ class NodeSerializer(serializers.ModelSerializer):
@staticmethod
def get_assets_amount(obj):
return obj.assets__count if hasattr(obj, 'assets__count') else 0
return obj.get_all_assets().count()
@staticmethod
def get_tree_id(obj):
......
......@@ -288,7 +288,9 @@ function onRename(event, treeId, treeNode, isCancel){
APIUpdateAttr({
url: url,
body: JSON.stringify(data),
method: "PATCH"
method: "PATCH",
success_message: "{% trans 'Rename success' %}",
fail_message: "{% trans 'Rename failed, do not change the root node name' %}"
})
}
......
......@@ -8,7 +8,6 @@ import codecs
import chardet
from io import StringIO
from django.conf import settings
from django.db import transaction
from django.utils.translation import ugettext_lazy as _
from django.views.generic import TemplateView, ListView, View
......@@ -25,11 +24,12 @@ from django.shortcuts import redirect
from django.contrib.messages.views import SuccessMessageMixin
from common.mixins import JSONResponseMixin
from common.utils import get_object_or_none, get_logger, is_uuid
from common.utils import get_object_or_none, get_logger
from common.permissions import AdminUserRequiredMixin
from common.const import create_success_msg, update_success_msg
from orgs.utils import current_org
from .. import forms
from ..models import Asset, AdminUser, SystemUser, Label, Node, Domain
from common.permissions import AdminUserRequiredMixin
__all__ = [
......@@ -44,6 +44,9 @@ class AssetListView(AdminUserRequiredMixin, TemplateView):
template_name = 'assets/asset_list.html'
def get_context_data(self, **kwargs):
if current_org.is_default():
Node.default_node()
else:
Node.root()
context = {
'app': _('Assets'),
......
This diff is collapsed.
......@@ -261,10 +261,10 @@ LOGGING = {
'handlers': ['console', 'file'],
'level': "INFO",
},
'django.db': {
'handlers': ['console', 'file'],
'level': 'DEBUG'
}
# 'django.db': {
# 'handlers': ['console', 'file'],
# 'level': 'DEBUG'
# }
}
}
......@@ -322,7 +322,7 @@ REST_FRAMEWORK = {
'common.permissions.IsOrgAdmin',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
# 'rest_framework.authentication.BasicAuthentication',
'users.authentication.AccessKeyAuthentication',
'users.authentication.AccessTokenAuthentication',
'users.authentication.PrivateTokenAuthentication',
......
......@@ -139,8 +139,6 @@ class AssetPermissionUtil:
for node, system_users in nodes.items():
_assets = node.get_all_assets().valid().prefetch_related('nodes')
for asset in _assets:
if isinstance(asset, Node):
print(_assets)
assets[asset].update(system_users)
self._assets = assets
return self._assets
......
......@@ -243,7 +243,6 @@ class CommandViewSet(viewsets.ViewSet):
def create(self, request, *args, **kwargs):
serializer = self.serializer_class(data=request.data, many=True)
if serializer.is_valid():
print(serializer.validated_data)
ok = self.command_store.bulk_save(serializer.validated_data)
if ok:
return Response("ok", status=201)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment