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): ...@@ -43,15 +43,23 @@ class NodeViewSet(viewsets.ModelViewSet):
permission_classes = (IsOrgAdmin,) permission_classes = (IsOrgAdmin,)
serializer_class = serializers.NodeSerializer serializer_class = serializers.NodeSerializer
def get_queryset(self):
queryset = super().get_queryset().annotate(Count('assets'))
return queryset
def perform_create(self, serializer): def perform_create(self, serializer):
child_key = Node.root().get_next_child_key() child_key = Node.root().get_next_child_key()
serializer.validated_data["key"] = child_key serializer.validated_data["key"] = child_key
serializer.save() 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): class NodeChildrenApi(mixins.ListModelMixin, generics.CreateAPIView):
queryset = Node.objects.all() queryset = Node.objects.all()
...@@ -108,9 +116,9 @@ class NodeChildrenApi(mixins.ListModelMixin, generics.CreateAPIView): ...@@ -108,9 +116,9 @@ class NodeChildrenApi(mixins.ListModelMixin, generics.CreateAPIView):
queryset.append(node) queryset.append(node)
if query_all: if query_all:
children = node.get_all_children().annotate(Count("assets")) children = node.get_all_children()
else: else:
children = node.get_children().annotate(Count("assets")) children = node.get_children()
queryset.extend(list(children)) queryset.extend(list(children))
if query_assets: if query_assets:
......
...@@ -199,6 +199,11 @@ class Node(OrgModelMixin): ...@@ -199,6 +199,11 @@ class Node(OrgModelMixin):
else: else:
return cls.create_root_node() return cls.create_root_node()
@classmethod
def default_node(cls):
defaults = {'value': 'Default'}
return cls.objects.get_or_create(defaults=defaults, key='0')
@classmethod @classmethod
def generate_fake(cls, count=100): def generate_fake(cls, count=100):
import random import random
......
...@@ -20,7 +20,7 @@ class AssetSerializer(BulkSerializerMixin, serializers.ModelSerializer): ...@@ -20,7 +20,7 @@ class AssetSerializer(BulkSerializerMixin, serializers.ModelSerializer):
model = Asset model = Asset
list_serializer_class = BulkListSerializer list_serializer_class = BulkListSerializer
fields = '__all__' fields = '__all__'
# validators = [] # If not set to [], partial bulk update will be error validators = []
def get_field_names(self, declared_fields, info): def get_field_names(self, declared_fields, info):
fields = super().get_field_names(declared_fields, info) fields = super().get_field_names(declared_fields, info)
......
...@@ -68,7 +68,7 @@ class NodeSerializer(serializers.ModelSerializer): ...@@ -68,7 +68,7 @@ class NodeSerializer(serializers.ModelSerializer):
@staticmethod @staticmethod
def get_assets_amount(obj): def get_assets_amount(obj):
return obj.assets__count if hasattr(obj, 'assets__count') else 0 return obj.get_all_assets().count()
@staticmethod @staticmethod
def get_tree_id(obj): def get_tree_id(obj):
......
...@@ -194,9 +194,10 @@ function addTreeNode() { ...@@ -194,9 +194,10 @@ function addTreeNode() {
$.post(url, {}, function (data, status){ $.post(url, {}, function (data, status){
if (status === "success") { if (status === "success") {
var newNode = { var newNode = {
id: data["key"],
name: data["value"], name: data["value"],
id: data["id"], node_id: data["id"],
pId: parentNode.node_id pId: parentNode.id
}; };
newNode.checked = zTree.getSelectedNodes()[0].checked; newNode.checked = zTree.getSelectedNodes()[0].checked;
zTree.addNodes(parentNode, 0, newNode); zTree.addNodes(parentNode, 0, newNode);
...@@ -287,7 +288,9 @@ function onRename(event, treeId, treeNode, isCancel){ ...@@ -287,7 +288,9 @@ function onRename(event, treeId, treeNode, isCancel){
APIUpdateAttr({ APIUpdateAttr({
url: url, url: url,
body: JSON.stringify(data), 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 ...@@ -8,7 +8,6 @@ import codecs
import chardet import chardet
from io import StringIO from io import StringIO
from django.conf import settings
from django.db import transaction from django.db import transaction
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.views.generic import TemplateView, ListView, View from django.views.generic import TemplateView, ListView, View
...@@ -25,11 +24,12 @@ from django.shortcuts import redirect ...@@ -25,11 +24,12 @@ from django.shortcuts import redirect
from django.contrib.messages.views import SuccessMessageMixin from django.contrib.messages.views import SuccessMessageMixin
from common.mixins import JSONResponseMixin 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 common.const import create_success_msg, update_success_msg
from orgs.utils import current_org
from .. import forms from .. import forms
from ..models import Asset, AdminUser, SystemUser, Label, Node, Domain from ..models import Asset, AdminUser, SystemUser, Label, Node, Domain
from common.permissions import AdminUserRequiredMixin
__all__ = [ __all__ = [
...@@ -44,6 +44,9 @@ class AssetListView(AdminUserRequiredMixin, TemplateView): ...@@ -44,6 +44,9 @@ class AssetListView(AdminUserRequiredMixin, TemplateView):
template_name = 'assets/asset_list.html' template_name = 'assets/asset_list.html'
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
if current_org.is_default():
Node.default_node()
else:
Node.root() Node.root()
context = { context = {
'app': _('Assets'), 'app': _('Assets'),
......
This diff is collapsed.
...@@ -322,6 +322,7 @@ REST_FRAMEWORK = { ...@@ -322,6 +322,7 @@ REST_FRAMEWORK = {
'common.permissions.IsOrgAdmin', 'common.permissions.IsOrgAdmin',
), ),
'DEFAULT_AUTHENTICATION_CLASSES': ( 'DEFAULT_AUTHENTICATION_CLASSES': (
# 'rest_framework.authentication.BasicAuthentication',
'users.authentication.AccessKeyAuthentication', 'users.authentication.AccessKeyAuthentication',
'users.authentication.AccessTokenAuthentication', 'users.authentication.AccessTokenAuthentication',
'users.authentication.PrivateTokenAuthentication', 'users.authentication.PrivateTokenAuthentication',
......
...@@ -5,7 +5,6 @@ from django.shortcuts import get_object_or_404 ...@@ -5,7 +5,6 @@ from django.shortcuts import get_object_or_404
from rest_framework.views import APIView, Response from rest_framework.views import APIView, Response
from rest_framework.generics import ListAPIView, get_object_or_404, RetrieveUpdateAPIView from rest_framework.generics import ListAPIView, get_object_or_404, RetrieveUpdateAPIView
from rest_framework import viewsets 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.utils import set_or_append_attr_bulk, get_object_or_none
from common.permissions import IsValidUser, IsOrgAdmin, IsOrgAdminOrAppUser from common.permissions import IsValidUser, IsOrgAdmin, IsOrgAdminOrAppUser
......
...@@ -139,8 +139,6 @@ class AssetPermissionUtil: ...@@ -139,8 +139,6 @@ class AssetPermissionUtil:
for node, system_users in nodes.items(): for node, system_users in nodes.items():
_assets = node.get_all_assets().valid().prefetch_related('nodes') _assets = node.get_all_assets().valid().prefetch_related('nodes')
for asset in _assets: for asset in _assets:
if isinstance(asset, Node):
print(_assets)
assets[asset].update(system_users) assets[asset].update(system_users)
self._assets = assets self._assets = assets
return self._assets return self._assets
......
...@@ -243,7 +243,6 @@ class CommandViewSet(viewsets.ViewSet): ...@@ -243,7 +243,6 @@ class CommandViewSet(viewsets.ViewSet):
def create(self, request, *args, **kwargs): def create(self, request, *args, **kwargs):
serializer = self.serializer_class(data=request.data, many=True) serializer = self.serializer_class(data=request.data, many=True)
if serializer.is_valid(): if serializer.is_valid():
print(serializer.validated_data)
ok = self.command_store.bulk_save(serializer.validated_data) ok = self.command_store.bulk_save(serializer.validated_data)
if ok: if ok:
return Response("ok", status=201) return Response("ok", status=201)
......
...@@ -23,6 +23,7 @@ class UserSerializer(BulkSerializerMixin, serializers.ModelSerializer): ...@@ -23,6 +23,7 @@ class UserSerializer(BulkSerializerMixin, serializers.ModelSerializer):
'first_name', 'last_name', 'password', '_private_key', 'first_name', 'last_name', 'password', '_private_key',
'_public_key', '_otp_secret_key', 'user_permissions' '_public_key', '_otp_secret_key', 'user_permissions'
] ]
# validators = []
def get_field_names(self, declared_fields, info): def get_field_names(self, declared_fields, info):
fields = super(UserSerializer, self).get_field_names(declared_fields, info) fields = super(UserSerializer, self).get_field_names(declared_fields, info)
...@@ -71,7 +72,7 @@ class UserGroupSerializer(BulkSerializerMixin, serializers.ModelSerializer): ...@@ -71,7 +72,7 @@ class UserGroupSerializer(BulkSerializerMixin, serializers.ModelSerializer):
class UserGroupUpdateMemeberSerializer(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: class Meta:
model = UserGroup model = UserGroup
......
...@@ -14,11 +14,11 @@ coreapi==2.3.3 ...@@ -14,11 +14,11 @@ coreapi==2.3.3
coreschema==0.0.4 coreschema==0.0.4
cryptography==2.1.4 cryptography==2.1.4
decorator==4.1.2 decorator==4.1.2
Django==2.0.7 Django==2.1.0
django-auth-ldap==1.3.0 django-auth-ldap==1.3.0
django-bootstrap3==9.1.0 django-bootstrap3==9.1.0
django-celery-beat==1.1.1 django-celery-beat==1.1.1
django-filter==1.1.0 django-filter==2.0.0
django-formtools==2.1 django-formtools==2.1
django-ranged-response==0.2.0 django-ranged-response==0.2.0
django-redis-cache==1.7.1 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