Commit e59b95e9 authored by ibuler's avatar ibuler

Merge remote-tracking branch 'github/dev' into dev

parents 3f049440 bb639415
......@@ -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
......
......@@ -20,7 +20,7 @@ class AssetSerializer(BulkSerializerMixin, serializers.ModelSerializer):
model = Asset
list_serializer_class = BulkListSerializer
fields = '__all__'
# validators = [] # If not set to [], partial bulk update will be error
validators = []
def get_field_names(self, declared_fields, info):
fields = super().get_field_names(declared_fields, info)
......
......@@ -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):
......
......@@ -194,9 +194,10 @@ function addTreeNode() {
$.post(url, {}, function (data, status){
if (status === "success") {
var newNode = {
id: data["key"],
name: data["value"],
id: data["id"],
pId: parentNode.node_id
node_id: data["id"],
pId: parentNode.id
};
newNode.checked = zTree.getSelectedNodes()[0].checked;
zTree.addNodes(parentNode, 0, newNode);
......@@ -287,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.
......@@ -322,6 +322,7 @@ REST_FRAMEWORK = {
'common.permissions.IsOrgAdmin',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
# 'rest_framework.authentication.BasicAuthentication',
'users.authentication.AccessKeyAuthentication',
'users.authentication.AccessTokenAuthentication',
'users.authentication.PrivateTokenAuthentication',
......
......@@ -5,7 +5,6 @@ from django.shortcuts import get_object_or_404
from rest_framework.views import APIView, Response
from rest_framework.generics import ListAPIView, get_object_or_404, RetrieveUpdateAPIView
from rest_framework import viewsets
from rest_framework.pagination import LimitOffsetPagination
from common.utils import set_or_append_attr_bulk, get_object_or_none
from common.permissions import IsValidUser, IsOrgAdmin, IsOrgAdminOrAppUser
......
......@@ -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)
......
......@@ -23,6 +23,7 @@ class UserSerializer(BulkSerializerMixin, serializers.ModelSerializer):
'first_name', 'last_name', 'password', '_private_key',
'_public_key', '_otp_secret_key', 'user_permissions'
]
# validators = []
def get_field_names(self, declared_fields, info):
fields = super(UserSerializer, self).get_field_names(declared_fields, info)
......@@ -71,7 +72,7 @@ class UserGroupSerializer(BulkSerializerMixin, serializers.ModelSerializer):
class UserGroupUpdateMemeberSerializer(serializers.ModelSerializer):
users = serializers.PrimaryKeyRelatedField(many=True, queryset = User.objects.all())
users = serializers.PrimaryKeyRelatedField(many=True, queryset=User.objects.all())
class Meta:
model = UserGroup
......
......@@ -14,11 +14,11 @@ coreapi==2.3.3
coreschema==0.0.4
cryptography==2.1.4
decorator==4.1.2
Django==2.0.7
Django==2.1.0
django-auth-ldap==1.3.0
django-bootstrap3==9.1.0
django-celery-beat==1.1.1
django-filter==1.1.0
django-filter==2.0.0
django-formtools==2.1
django-ranged-response==0.2.0
django-redis-cache==1.7.1
......
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