Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gjl2004yn
jumpserver
提交
6fc666e6
J
jumpserver
项目概览
gjl2004yn
/
jumpserver
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jumpserver
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6fc666e6
编写于
9月 19, 2019
作者:
baltery
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Update] 优化获取系统用户
上级
89fa0658
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
10 addition
and
35 deletion
+10
-35
apps/assets/models/node.py
apps/assets/models/node.py
+3
-2
apps/perms/api/user_permission/user_permission_assets.py
apps/perms/api/user_permission/user_permission_assets.py
+1
-1
apps/perms/utils/asset_permission.py
apps/perms/utils/asset_permission.py
+6
-32
未找到文件。
apps/assets/models/node.py
浏览文件 @
6fc666e6
...
...
@@ -298,14 +298,15 @@ class NodeAssetsMixin:
return
self
.
get_all_assets
().
valid
()
@
classmethod
@
timeit
def
get_nodes_all_assets
(
cls
,
nodes_keys
):
def
get_nodes_all_assets
(
cls
,
nodes_keys
,
extra_assets_ids
=
None
):
from
.asset
import
Asset
nodes_keys
=
cls
.
clean_children_keys
(
nodes_keys
)
assets_ids
=
set
()
for
key
in
nodes_keys
:
node_assets_ids
=
cls
.
tree
().
all_assets
(
key
)
assets_ids
.
update
(
set
(
node_assets_ids
))
if
extra_assets_ids
:
assets_ids
.
update
(
set
(
extra_assets_ids
))
return
Asset
.
objects
.
filter
(
id__in
=
assets_ids
)
...
...
apps/perms/api/user_permission/user_permission_assets.py
浏览文件 @
6fc666e6
...
...
@@ -7,7 +7,7 @@ from rest_framework.generics import (
)
from
common.permissions
import
IsOrgAdminOrAppUser
from
common.utils
import
get_logger
from
common.utils
import
get_logger
,
timeit
from
...hands
import
Node
from
...
import
serializers
from
.mixin
import
UserAssetPermissionMixin
,
UserAssetTreeMixin
...
...
apps/perms/utils/asset_permission.py
浏览文件 @
6fc666e6
...
...
@@ -334,17 +334,13 @@ class AssetPermissionUtilV2(AssetPermissionUtilCacheMixin):
for
node
in
nodes
:
ancestor_keys
=
node
.
get_ancestor_keys
(
with_self
=
True
)
nodes_keys_related
.
update
(
set
(
ancestor_keys
))
pattern
=
[]
for
key
in
nodes_keys_related
:
pattern
.
append
(
r
'^{0}$|^{0}:'
.
format
(
key
))
pattern
=
'|'
.
join
(
list
(
pattern
))
kwargs
=
{
"assets"
:
asset
}
if
pattern
:
kwargs
[
"nodes__key__
regex"
]
=
pattern
if
nodes_keys_related
:
kwargs
[
"nodes__key__
in"
]
=
nodes_keys_related
queryset
=
self
.
permissions
if
len
(
kwargs
)
==
1
:
if
kwargs
==
1
:
queryset
=
queryset
.
filter
(
**
kwargs
)
elif
len
(
kwargs
)
>
1
:
kwargs
=
[{
k
:
v
}
for
k
,
v
in
kwargs
.
items
()]
...
...
@@ -378,33 +374,11 @@ class AssetPermissionUtilV2(AssetPermissionUtilCacheMixin):
nodes_keys
=
Node
.
clean_children_keys
(
nodes_keys
)
return
nodes_keys
,
assets_ids
@
staticmethod
def
filter_assets_by_or_kwargs
(
kwargs
):
if
len
(
kwargs
)
==
1
:
queryset
=
Asset
.
objects
.
filter
(
**
kwargs
)
elif
len
(
kwargs
)
>
1
:
kwargs
=
[{
k
:
v
}
for
k
,
v
in
kwargs
.
items
()]
args
=
[
Q
(
**
kw
)
for
kw
in
kwargs
]
args
=
reduce
(
lambda
x
,
y
:
x
|
y
,
args
)
queryset
=
Asset
.
objects
.
filter
(
args
)
else
:
queryset
=
Asset
.
objects
.
none
()
return
queryset
@
timeit
def
get_assets
(
self
):
nodes_keys
,
assets_ids
=
self
.
get_permissions_nodes_and_assets
()
pattern
=
set
()
for
key
in
nodes_keys
:
pattern
.
add
(
r
'^{0}$|^{0}:'
.
format
(
key
))
pattern
=
'|'
.
join
(
list
(
pattern
))
kwargs
=
{}
if
assets_ids
:
kwargs
[
"id__in"
]
=
assets_ids
if
pattern
:
kwargs
[
"nodes__key__regex"
]
=
pattern
queryset
=
self
.
filter_assets_by_or_kwargs
(
kwargs
)
return
queryset
.
valid
().
distinct
()
queryset
=
Node
.
get_nodes_all_assets
(
nodes_keys
,
extra_assets_ids
=
assets_ids
)
return
queryset
.
valid
()
def
get_nodes_assets
(
self
,
node
,
deep
=
False
):
if
deep
:
...
...
@@ -412,7 +386,7 @@ class AssetPermissionUtilV2(AssetPermissionUtilCacheMixin):
else
:
assets_ids
=
self
.
user_tree
.
assets
(
node
.
key
)
queryset
=
Asset
.
objects
.
filter
(
id__in
=
assets_ids
)
return
queryset
.
valid
()
.
distinct
()
return
queryset
.
valid
()
def
get_nodes
(
self
):
return
[
n
.
identifier
for
n
in
self
.
user_tree
.
all_nodes_itr
()]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录