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
583214e9
Commit
583214e9
authored
Dec 18, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 优化获取授权资产api
parent
90b77fdb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
11 deletions
+25
-11
tree.py
apps/common/tree.py
+2
-5
api.py
apps/perms/api.py
+23
-6
No files found.
apps/common/tree.py
View file @
583214e9
...
...
@@ -47,16 +47,13 @@ class TreeNode:
def
__gt__
(
self
,
other
):
if
self
.
isParent
and
not
other
.
isParent
:
return
False
elif
not
self
.
isParent
and
other
.
isParent
:
return
True
return
self
.
id
>
other
.
id
def
__eq__
(
self
,
other
):
return
self
.
id
==
other
.
id
def
__lt__
(
self
,
other
):
if
self
.
isParent
and
not
other
.
isParent
:
return
True
return
self
.
id
<
other
.
id
class
Tree
:
def
__init__
(
self
):
...
...
apps/perms/api.py
View file @
583214e9
...
...
@@ -228,15 +228,22 @@ class UserGrantedNodesWithAssetsAsTreeApi(ListAPIView):
@staticmethod
def
parse_asset_to_tree_node
(
node
,
asset
,
system_users
):
system_users_protocol_matched
=
[
s
for
s
in
system_users
if
s
.
protocol
==
asset
.
protocol
]
system_user_serializer
=
serializers
.
GrantedSystemUserSerializer
(
system_users_protocol_matched
,
many
=
True
)
asset_serializer
=
serializers
.
GrantedAssetSerializer
(
asset
)
icon_skin
=
'file'
if
asset
.
platform
.
lower
()
==
'windows'
:
icon_skin
=
'windows'
elif
asset
.
platform
.
lower
()
==
'linux'
:
icon_skin
=
'linux'
system_users
=
[]
for
system_user
in
system_users_protocol_matched
:
system_users
.
append
({
'id'
:
system_user
.
id
,
'name'
:
system_user
.
name
,
'username'
:
system_user
.
username
,
'protocol'
:
system_user
.
protocol
,
'priority'
:
system_user
.
priority
,
'login_mode'
:
system_user
.
login_mode
,
'comment'
:
system_user
.
comment
,
})
data
=
{
'id'
:
str
(
asset
.
id
),
'name'
:
asset
.
hostname
,
...
...
@@ -246,9 +253,19 @@ class UserGrantedNodesWithAssetsAsTreeApi(ListAPIView):
'open'
:
False
,
'iconSkin'
:
icon_skin
,
'meta'
:
{
'system_users'
:
system_user
_serializer
.
data
,
'system_users'
:
system_user
s
,
'type'
:
'asset'
,
'asset'
:
asset_serializer
.
data
'asset'
:
{
'id'
:
asset
.
id
,
'hostname'
:
asset
.
hostname
,
'ip'
:
asset
.
ip
,
'port'
:
asset
.
port
,
'protocol'
:
asset
.
protocol
,
'platform'
:
asset
.
platform
,
'domain'
:
None
if
not
asset
.
domain
else
asset
.
domain
.
id
,
'is_active'
:
asset
.
is_active
,
'comment'
:
asset
.
comment
},
}
}
tree_node
=
TreeNode
(
**
data
)
...
...
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