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

Merge pull request #3093 from jumpserver/allow_show_all_nodes

[Update] 控制是否显示未分组节点
parents c3a206b2 6b56c43a
...@@ -7,7 +7,7 @@ from common.utils import get_ip_city, validate_ip ...@@ -7,7 +7,7 @@ from common.utils import get_ip_city, validate_ip
def write_login_log(*args, **kwargs): def write_login_log(*args, **kwargs):
from audits.models import UserLoginLog from audits.models import UserLoginLog
default_city = _("Unknown") default_city = _("Unknown")
ip = kwargs.get('ip', '') ip = kwargs.get('ip') or ''
if not (ip and validate_ip(ip)): if not (ip and validate_ip(ip)):
ip = ip[:15] ip = ip[:15]
city = default_city city = default_city
......
...@@ -379,6 +379,7 @@ defaults = { ...@@ -379,6 +379,7 @@ defaults = {
'ASSETS_PERM_CACHE_TIME': 3600*24, 'ASSETS_PERM_CACHE_TIME': 3600*24,
'SECURITY_MFA_VERIFY_TTL': 3600, 'SECURITY_MFA_VERIFY_TTL': 3600,
'ASSETS_PERM_CACHE_ENABLE': False, 'ASSETS_PERM_CACHE_ENABLE': False,
'PERM_SINGLE_ASSET_TO_UNGROUP_NODE': False,
} }
......
...@@ -615,3 +615,5 @@ ASSETS_PERM_CACHE_TIME = CONFIG.ASSETS_PERM_CACHE_TIME ...@@ -615,3 +615,5 @@ ASSETS_PERM_CACHE_TIME = CONFIG.ASSETS_PERM_CACHE_TIME
# Asset user auth external backend, default AuthBook backend # Asset user auth external backend, default AuthBook backend
BACKEND_ASSET_USER_AUTH_VAULT = False BACKEND_ASSET_USER_AUTH_VAULT = False
PERM_SINGLE_ASSET_TO_UNGROUP_NODE = CONFIG.PERM_SINGLE_ASSET_TO_UNGROUP_NODE
...@@ -180,6 +180,19 @@ class GenerateTree: ...@@ -180,6 +180,19 @@ class GenerateTree:
assets.append({"id": asset_id, "system_users": system_users}) assets.append({"id": asset_id, "system_users": system_users})
return assets return assets
def set_ungrouped_assets_nodes_if_need(self):
if settings.PERM_SINGLE_ASSET_TO_UNGROUP_NODE:
return
ungrouped_assets_ids = self.nodes[self.ungrouped_key]["assets"]
for asset_id in ungrouped_assets_ids:
in_nodes = self.all_assets_nodes_keys.get(asset_id, [])
for node_key in in_nodes:
parents_keys = self.node_util.get_nodes_parents_keys_by_key(node_key, with_self=False)
for parent_key in parents_keys:
n = self.nodes[parent_key]
self.nodes[node_key]["assets"].add(asset_id)
self.nodes.pop(self.ungrouped_key, None)
@timeit @timeit
def get_nodes_with_assets(self): def get_nodes_with_assets(self):
""" """
...@@ -198,6 +211,7 @@ class GenerateTree: ...@@ -198,6 +211,7 @@ class GenerateTree:
""" """
if self._nodes_with_assets: if self._nodes_with_assets:
return self._nodes_with_assets return self._nodes_with_assets
self.set_ungrouped_assets_nodes_if_need()
util = PermAssetsAmountUtil() util = PermAssetsAmountUtil()
nodes_with_assets_amount = util.compute_nodes_assets_amount(self.nodes) nodes_with_assets_amount = util.compute_nodes_assets_amount(self.nodes)
nodes = [] nodes = []
...@@ -219,6 +233,7 @@ class GenerateTree: ...@@ -219,6 +233,7 @@ class GenerateTree:
return nodes return nodes
def get_nodes(self): def get_nodes(self):
self.set_ungrouped_assets_nodes_if_need()
nodes = list(self.nodes.keys()) nodes = list(self.nodes.keys())
if not nodes: if not nodes:
nodes.append(const.EMPTY_NODE_KEY) nodes.append(const.EMPTY_NODE_KEY)
......
...@@ -76,3 +76,7 @@ REDIS_PORT: 6379 ...@@ -76,3 +76,7 @@ REDIS_PORT: 6379
# OTP/MFA 配置 # OTP/MFA 配置
# OTP_VALID_WINDOW: 0 # OTP_VALID_WINDOW: 0
# OTP_ISSUER_NAME: Jumpserver # OTP_ISSUER_NAME: Jumpserver
# Perm show single asset to ungrouped node
# 是否把未授权节点资产放入到 未分组 节点中
# PERM_SINGLE_ASSET_TO_UNGROUP_NODE: false
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