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
482d1bb2
Commit
482d1bb2
authored
Jun 01, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改permisstion util
parent
e7c7c3a7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
9 deletions
+26
-9
node.py
apps/assets/api/node.py
+1
-1
node.py
apps/assets/models/node.py
+2
-2
node.py
apps/assets/serializers/node.py
+2
-5
utils.py
apps/common/utils.py
+15
-0
utils.py
apps/perms/utils.py
+6
-1
No files found.
apps/assets/api/node.py
View file @
482d1bb2
...
...
@@ -140,7 +140,7 @@ class NodeChildrenApi(mixins.ListModelMixin, generics.CreateAPIView):
node_fake
=
Node
()
node_fake
.
id
=
asset
.
id
node_fake
.
is_node
=
False
node_fake
.
parent
=
node
node_fake
.
parent
_id
=
node
.
id
node_fake
.
value
=
asset
.
hostname
queryset
.
append
(
node_fake
)
queryset
=
sorted
(
queryset
,
key
=
lambda
x
:
x
.
is_node
,
reverse
=
True
)
...
...
apps/assets/models/node.py
View file @
482d1bb2
...
...
@@ -5,7 +5,7 @@ import uuid
from
django.db
import
models
,
transaction
from
django.db.models
import
Q
from
django.utils.translation
import
ugettext_lazy
as
_
from
common.utils
import
with_cache
__all__
=
[
'Node'
]
...
...
@@ -166,6 +166,6 @@ class Node(models.Model):
obj
,
created
=
cls
.
objects
.
get_or_create
(
key
=
'0'
,
defaults
=
{
"key"
:
'0'
,
'value'
:
"ROOT"
}
)
print
(
obj
)
return
obj
apps/assets/serializers/node.py
View file @
482d1bb2
...
...
@@ -64,14 +64,11 @@ class NodeSerializer(serializers.ModelSerializer):
@staticmethod
def
get_parent
(
obj
):
return
obj
.
parent
.
id
return
obj
.
parent
.
id
if
obj
.
is_node
else
obj
.
parent_id
@staticmethod
def
get_assets_amount
(
obj
):
if
obj
.
is_node
:
return
obj
.
get_all_assets
()
.
count
()
else
:
return
0
return
obj
.
get_all_assets
()
.
count
()
if
obj
.
is_node
else
0
def
get_fields
(
self
):
fields
=
super
()
.
get_fields
()
...
...
apps/common/utils.py
View file @
482d1bb2
...
...
@@ -16,6 +16,7 @@ import calendar
import
threading
from
io
import
StringIO
import
uuid
from
functools
import
wraps
import
paramiko
import
sshpubkeys
...
...
@@ -395,3 +396,17 @@ class TeeObj:
def
close
(
self
):
self
.
file_obj
.
close
()
def
with_cache
(
func
):
cache
=
{}
key
=
"_{}.{}"
.
format
(
func
.
__module__
,
func
.
__name__
)
@wraps
(
func
)
def
wrapper
(
*
args
,
**
kwargs
):
cached
=
cache
.
get
(
key
)
if
cached
:
return
cached
res
=
func
(
*
args
,
**
kwargs
)
cache
[
key
]
=
res
return
res
return
wrapper
apps/perms/utils.py
View file @
482d1bb2
...
...
@@ -104,6 +104,11 @@ class AssetPermissionUtil:
return
assets
def
get_nodes_with_assets
(
self
):
"""
返回节点并且包含资产
{"node": {"assets": set("system_user")}}
:return:
"""
assets
=
self
.
get_assets
()
nodes
=
defaultdict
(
dict
)
for
asset
,
system_users
in
assets
.
items
():
...
...
@@ -112,7 +117,7 @@ class AssetPermissionUtil:
if
asset
in
nodes
[
node
]:
nodes
[
node
][
asset
]
.
update
(
system_users
)
else
:
nodes
[
node
]
=
{
asset
:
system_users
}
nodes
[
node
]
[
asset
]
=
system_users
return
nodes
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