From 5b53cfb4dd2dcf02b0ab9777d43da741505644a0 Mon Sep 17 00:00:00 2001 From: BaiJiangJie Date: Tue, 29 May 2018 11:50:09 +0800 Subject: [PATCH 1/4] =?UTF-8?q?[Update]=20=E4=BF=AE=E6=94=B9=E8=B5=84?= =?UTF-8?q?=E4=BA=A7=E6=A0=91=E8=8A=82=E7=82=B9(=E6=95=B0=E9=87=8F)?= =?UTF-8?q?=E6=80=BB=E6=98=BE=E7=A4=BA=E6=AD=A4=E8=8A=82=E7=82=B9=E4=B8=8B?= =?UTF-8?q?=E7=9A=84=E8=B5=84=E4=BA=A7=E6=80=BB=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/api/node.py | 9 +-------- apps/assets/serializers/node.py | 8 +------- apps/assets/templates/assets/_asset_list_modal.html | 2 +- apps/assets/templates/assets/asset_list.html | 7 +++---- 4 files changed, 6 insertions(+), 20 deletions(-) diff --git a/apps/assets/api/node.py b/apps/assets/api/node.py index b0e974f5c..11f45cc8d 100644 --- a/apps/assets/api/node.py +++ b/apps/assets/api/node.py @@ -42,14 +42,7 @@ __all__ = [ class NodeViewSet(BulkModelViewSet): queryset = Node.objects.all() permission_classes = (IsSuperUser,) - # serializer_class = serializers.NodeSerializer - - def get_serializer_class(self): - show_current_asset = self.request.query_params.get('show_current_asset') - if show_current_asset: - return serializers.NodeCurrentSerializer - else: - return serializers.NodeSerializer + serializer_class = serializers.NodeSerializer def perform_create(self, serializer): child_key = Node.root().get_next_child_key() diff --git a/apps/assets/serializers/node.py b/apps/assets/serializers/node.py index 73639a100..6683a3027 100644 --- a/apps/assets/serializers/node.py +++ b/apps/assets/serializers/node.py @@ -9,7 +9,7 @@ from .asset import AssetGrantedSerializer __all__ = [ 'NodeSerializer', "NodeGrantedSerializer", "NodeAddChildrenSerializer", - "NodeAssetsSerializer", "NodeCurrentSerializer", + "NodeAssetsSerializer", ] @@ -77,12 +77,6 @@ class NodeSerializer(serializers.ModelSerializer): return fields -class NodeCurrentSerializer(NodeSerializer): - @staticmethod - def get_assets_amount(obj): - return obj.get_assets().count() - - class NodeAssetsSerializer(serializers.ModelSerializer): assets = serializers.PrimaryKeyRelatedField(many=True, queryset=Asset.objects.all()) diff --git a/apps/assets/templates/assets/_asset_list_modal.html b/apps/assets/templates/assets/_asset_list_modal.html index a0d96a7ef..faf569137 100644 --- a/apps/assets/templates/assets/_asset_list_modal.html +++ b/apps/assets/templates/assets/_asset_list_modal.html @@ -95,7 +95,7 @@ function initTree2() { }; var zNodes = []; - $.get("{% url 'api-assets:node-list' %}?show_current_asset=1", function(data, status){ + $.get("{% url 'api-assets:node-list' %}", function(data, status){ $.each(data, function (index, value) { value["pId"] = value["parent"]; {#value["open"] = true;#} diff --git a/apps/assets/templates/assets/asset_list.html b/apps/assets/templates/assets/asset_list.html index ab08f7b67..b5e53aaba 100644 --- a/apps/assets/templates/assets/asset_list.html +++ b/apps/assets/templates/assets/asset_list.html @@ -399,8 +399,7 @@ function initTree() { }; var zNodes = []; - var query_params = {'show_current_asset': getCookie('show_current_asset')}; - $.get("{% url 'api-assets:node-list' %}", query_params, function(data, status){ + $.get("{% url 'api-assets:node-list' %}", function(data, status){ $.each(data, function (index, value) { value["pId"] = value["parent"]; if (value["key"] === "0") { @@ -436,7 +435,7 @@ $(document).ready(function(){ initTable(); initTree(); - if(getCookie('show_current_asset') === 'yes'){ + if(getCookie('show_current_asset') === '1'){ $('#show_all_asset').css('display', 'inline-block'); } else{ @@ -564,7 +563,7 @@ $(document).ready(function(){ hideRMenu(); $(this).css('display', 'none'); $('#show_all_asset').css('display', 'inline-block'); - setCookie('show_current_asset', 'yes'); + setCookie('show_current_asset', '1'); location.reload(); }) .on('click', '.btn-show-all-asset', function(){ From 7c694c6885a2acf9c55d72bbdc0c94c2beb91724 Mon Sep 17 00:00:00 2001 From: BaiJiangJie Date: Tue, 29 May 2018 19:19:35 +0800 Subject: [PATCH 2/4] =?UTF-8?q?[Update]=20=E5=90=88=E5=B9=B6Node=E7=9A=84p?= =?UTF-8?q?arent.setter=E6=96=B9=E6=B3=95=EF=BC=8C=E4=BF=AE=E6=94=B9node?= =?UTF-8?q?=5Ffake=E7=9A=84parent=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/api/node.py | 60 ++++++++++++++++++-------------------- apps/assets/models/node.py | 22 +++++++------- 2 files changed, 40 insertions(+), 42 deletions(-) diff --git a/apps/assets/api/node.py b/apps/assets/api/node.py index 11f45cc8d..bb8cc719a 100644 --- a/apps/assets/api/node.py +++ b/apps/assets/api/node.py @@ -31,7 +31,7 @@ from .. import serializers logger = get_logger(__file__) __all__ = [ 'NodeViewSet', 'NodeChildrenApi', - 'NodeAssetsApi', 'NodeWithAssetsApi', + 'NodeAssetsApi', 'NodeAddAssetsApi', 'NodeRemoveAssetsApi', 'NodeReplaceAssetsApi', 'NodeAddChildrenApi', 'RefreshNodeHardwareInfoApi', @@ -50,32 +50,32 @@ class NodeViewSet(BulkModelViewSet): serializer.save() -class NodeWithAssetsApi(generics.ListAPIView): - permission_classes = (IsSuperUser,) - serializers = serializers.NodeSerializer - - def get_node(self): - pk = self.kwargs.get('pk') or self.request.query_params.get('node') - if not pk: - node = Node.root() - else: - node = get_object_or_404(Node, pk) - return node - - def get_queryset(self): - queryset = [] - node = self.get_node() - children = node.get_children() - assets = node.get_assets() - queryset.extend(list(children)) - - for asset in assets: - node = Node() - node.id = asset.id - node.parent = node.id - node.value = asset.hostname - queryset.append(node) - return queryset +# class NodeWithAssetsApi(generics.ListAPIView): +# permission_classes = (IsSuperUser,) +# serializers = serializers.NodeSerializer +# +# def get_node(self): +# pk = self.kwargs.get('pk') or self.request.query_params.get('node') +# if not pk: +# node = Node.root() +# else: +# node = get_object_or_404(Node, pk) +# return node +# +# def get_queryset(self): +# queryset = [] +# node = self.get_node() +# children = node.get_children() +# assets = node.get_assets() +# queryset.extend(list(children)) +# +# for asset in assets: +# node = Node() +# node.id = asset.id +# node.parent = node.id +# node.value = asset.hostname +# queryset.append(node) +# return queryset class NodeChildrenApi(mixins.ListModelMixin, generics.CreateAPIView): @@ -139,9 +139,9 @@ class NodeChildrenApi(mixins.ListModelMixin, generics.CreateAPIView): for asset in assets: node_fake = Node() node_fake.id = asset.id + node_fake.is_node = False node_fake.parent = node node_fake.value = asset.hostname - node_fake.is_node = False queryset.append(node_fake) queryset = sorted(queryset, key=lambda x: x.is_node, reverse=True) return queryset @@ -177,9 +177,7 @@ class NodeAddChildrenApi(generics.UpdateAPIView): for node in children: if not node: continue - # node.parent = instance - # node.save() - node.set_parent(instance) + node.parent = instance return Response("OK") diff --git a/apps/assets/models/node.py b/apps/assets/models/node.py index 784c8ae1b..7c2fe7dcc 100644 --- a/apps/assets/models/node.py +++ b/apps/assets/models/node.py @@ -40,16 +40,6 @@ class Node(models.Model): def level(self): return len(self.key.split(':')) - def set_parent(self, instance): - children = self.get_all_children() - old_key = self.key - with transaction.atomic(): - self.parent = instance - for child in children: - child.key = child.key.replace(old_key, self.key, 1) - child.save() - self.save() - def get_next_child_key(self): mark = self.child_mark self.child_mark += 1 @@ -128,7 +118,17 @@ class Node(models.Model): @parent.setter def parent(self, parent): - self.key = parent.get_next_child_key() + if self.is_node: + children = self.get_all_children() + old_key = self.key + with transaction.atomic(): + self.key = parent.get_next_child_key() + for child in children: + child.key = child.key.replace(old_key, self.key, 1) + child.save() + self.save() + else: + self.key = parent.key+':fake' @property def ancestor(self): From 6c384b49fe7da7d9f99d6bbd46484ab6b1b25feb Mon Sep 17 00:00:00 2001 From: wojiushixiaobai <296015668@qq.com> Date: Thu, 24 May 2018 13:02:38 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/upgrade.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/upgrade.sh b/utils/upgrade.sh index e1cdabb76..a39d1301f 100644 --- a/utils/upgrade.sh +++ b/utils/upgrade.sh @@ -40,5 +40,6 @@ git pull && pip install -r requirements/requirements.txt && cd utils && sh make_ cd .. && ./jms start all -d echo -e "\033[31m 请检查jumpserver是否启动成功 \033[0m" echo -e "\033[31m 备份文件存放于$jumpserver_backup目录 \033[0m" +stty erase ^? exit 0 From dbcad472140fb7c873ca7c13f9a540516c5f7c83 Mon Sep 17 00:00:00 2001 From: wojiushixiaobai <296015668@qq.com> Date: Wed, 30 May 2018 11:23:54 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/upgrade.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/upgrade.sh b/utils/upgrade.sh index a39d1301f..f700c9f7d 100644 --- a/utils/upgrade.sh +++ b/utils/upgrade.sh @@ -1,6 +1,6 @@ #!/bin/bash -if grep -q 'source ~/.autoenv/activate.sh' ~/.bashrc; then +if grep -q 'source /opt/autoenv/activate.sh' ~/.bashrc; then echo -e "\033[31m 正在自动载入 python 环境 \033[0m" else echo -e "\033[31m 不支持自动升级,请参考 http://docs.jumpserver.org/zh/docs/upgrade.html 手动升级 \033[0m"