Unverified Commit 37be53f3 authored by 老广's avatar 老广 Committed by GitHub

Merge pull request #3004 from jumpserver/dev

修改显示节点下的所有资产
parents 277bbc07 5f59c729
......@@ -14,13 +14,14 @@ __all__ = [
class NodeSerializer(BulkOrgResourceModelSerializer):
assets_amount = serializers.IntegerField(read_only=True)
name = serializers.ReadOnlyField(source='value')
class Meta:
model = Node
only_fields = ['id', 'key', 'value', 'org_id']
fields = only_fields + ['assets_amount']
fields = only_fields + ['name', 'assets_amount']
read_only_fields = [
'key', 'assets_amount', 'org_id',
'key', 'name', 'assets_amount', 'org_id',
]
def validate_value(self, data):
......
......@@ -23,7 +23,7 @@
<script>
var treeUrl = "{% url 'api-perms:my-nodes-as-tree' %}?&cache_policy=1";
var assetTableUrl = "{% url 'api-perms:my-assets' %}?cache_policy=1";
var selectUrl = '{% url "api-perms:my-node-assets" node_id=DEFAULT_PK %}?cache_policy=1';
var selectUrl = '{% url "api-perms:my-node-assets" node_id=DEFAULT_PK %}?cache_policy=1&all=1';
var showAssetHref = false; // Need input default true
var actions = {
targets: 4, createdCell: function (td, cellData) {
......
......@@ -88,13 +88,18 @@ class UserGrantedNodeAssetsApi(UserPermissionCacheMixin, GrantAssetsMixin, ListA
def get_queryset(self):
user = self.get_object()
query_all = self.request.query_params.get("all", "0") == "1"
self.util = AssetPermissionUtil(user, cache_policy=self.cache_policy)
key = self.get_node_key()
nodes_items = self.util.get_nodes_with_assets()
assets_system_users = {}
if query_all:
k = "all_assets"
else:
k = "assets"
for item in nodes_items:
if item["key"] == key:
assets_system_users = item["assets"]
assets_system_users = item[k]
break
assets = []
for asset_id, system_users in assets_system_users.items():
......
......@@ -44,7 +44,7 @@ class AssetGrantedSerializer(serializers.ModelSerializer):
model = Asset
only_fields = [
"id", "hostname", "ip", "protocols", "os", 'domain',
"platform", "org_id",
"platform", "comment", "org_id",
]
fields = only_fields + ['system_users_granted', 'system_users_join', "org_name"]
read_only_fields = fields
......
......@@ -203,14 +203,16 @@ class GenerateTree:
nodes = []
for key, values in nodes_with_assets_amount.items():
assets = {asset_id: self.assets.get(asset_id) for asset_id in values["assets"]}
all_assets = {asset_id: self.assets.get(asset_id) for asset_id in values["all_assets"]}
nodes.append({
"key": key, "assets": assets,
"key": key, "assets": assets, "all_assets": all_assets,
"assets_amount": values["assets_amount"]
})
# 如果返回空节点,页面构造授权资产树报错
if not nodes:
nodes.append({
"key": const.EMPTY_NODE_KEY, "assets": {}, "assets_amount": 0
"key": const.EMPTY_NODE_KEY, "assets": {}, "assets_amount": 0,
"all_assets": {},
})
nodes.sort(key=lambda n: self.key_sort(n["key"]))
self._nodes_with_assets = nodes
......
......@@ -102,7 +102,8 @@ class PermAssetsAmountUtil(PermStackUtilMixin):
self.debug("出栈: {} 栈顶: {}".format(
_node['key'], self.stack.top['key'] if self.stack.top else None)
)
_node["assets_amount"] = len(_node["all_assets"] | _node["assets"])
_node["all_assets"] = _node["all_assets"] | _node["assets"]
_node["assets_amount"] = len(_node["all_assets"])
self._nodes[_node.pop("key")] = _node
if not self.stack.top:
......
......@@ -33,7 +33,7 @@
{% block custom_foot_js %}
<script>
var assetTableUrl = "{% url 'api-perms:user-assets' pk=object.id %}?cache_policy=1";
var selectUrl = '{% url "api-perms:user-node-assets" pk=object.id node_id=DEFAULT_PK %}?cache_policy=1';
var selectUrl = '{% url "api-perms:user-node-assets" pk=object.id node_id=DEFAULT_PK %}?cache_policy=1&all=1';
var treeUrl = "{% url 'api-perms:user-nodes-as-tree' pk=object.id %}?&cache_policy=1";
$(document).ready(function () {
......
......@@ -35,7 +35,7 @@
<script>
var treeUrl = "{% url 'api-perms:user-group-nodes-as-tree' pk=object.id %}?cache_policy=1";
var assetTableUrl = "{% url 'api-perms:user-group-assets' pk=object.id %}?cache_policy=1";
var selectUrl = '{% url "api-perms:user-group-node-assets" pk=object.id node_id=DEFAULT_PK %}?cache_policy=1';
var selectUrl = '{% url "api-perms:user-group-node-assets" pk=object.id node_id=DEFAULT_PK %}?cache_policy=1&all=1';
var showAssetHref = true; // Need input default true
......
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