Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
6fc666e6
Commit
6fc666e6
authored
Sep 19, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 优化获取系统用户
parent
89fa0658
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
35 deletions
+10
-35
node.py
apps/assets/models/node.py
+3
-2
user_permission_assets.py
apps/perms/api/user_permission/user_permission_assets.py
+1
-1
asset_permission.py
apps/perms/utils/asset_permission.py
+6
-32
No files found.
apps/assets/models/node.py
View file @
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
View file @
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
View file @
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
()]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment