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
37be53f3
Unverified
Commit
37be53f3
authored
Jul 22, 2019
by
老广
Committed by
GitHub
Jul 22, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3004 from jumpserver/dev
修改显示节点下的所有资产
parents
277bbc07
5f59c729
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
19 additions
and
10 deletions
+19
-10
node.py
apps/assets/serializers/node.py
+3
-2
user_asset_list.html
apps/assets/templates/assets/user_asset_list.html
+1
-1
user_permission.py
apps/perms/api/user_permission.py
+6
-1
user_permission.py
apps/perms/serializers/user_permission.py
+1
-1
asset_permission.py
apps/perms/utils/asset_permission.py
+4
-2
stack.py
apps/perms/utils/stack.py
+2
-1
user_granted_asset.html
apps/users/templates/users/user_granted_asset.html
+1
-1
user_group_granted_asset.html
apps/users/templates/users/user_group_granted_asset.html
+1
-1
No files found.
apps/assets/serializers/node.py
View file @
37be53f3
...
...
@@ -14,13 +14,14 @@ __all__ = [
class
NodeSerializer
(
BulkOrgResourceModelSerializer
):
assets_amount
=
serializers
.
IntegerField
(
read_only
=
True
)
name
=
serializers
.
ReadOnlyField
(
source
=
'value'
)
class
Meta
:
model
=
Node
only_fields
=
[
'id'
,
'key'
,
'value'
,
'org_id'
]
fields
=
only_fields
+
[
'assets_amount'
]
fields
=
only_fields
+
[
'
name'
,
'
assets_amount'
]
read_only_fields
=
[
'key'
,
'assets_amount'
,
'org_id'
,
'key'
,
'
name'
,
'
assets_amount'
,
'org_id'
,
]
def
validate_value
(
self
,
data
):
...
...
apps/assets/templates/assets/user_asset_list.html
View file @
37be53f3
...
...
@@ -23,7 +23,7 @@
<script>
var
treeUrl
=
"{% url 'api-perms:my-nodes-as-tree' %}?&cache_policy=1"
;
var
assetTableUrl
=
"{% url 'api-perms:my-assets' %}?cache_policy=1"
;
var
selectUrl
=
'{% url "api-perms:my-node-assets" node_id=DEFAULT_PK %}?cache_policy=1'
;
var
selectUrl
=
'{% url "api-perms:my-node-assets" node_id=DEFAULT_PK %}?cache_policy=1
&all=1
'
;
var
showAssetHref
=
false
;
// Need input default true
var
actions
=
{
targets
:
4
,
createdCell
:
function
(
td
,
cellData
)
{
...
...
apps/perms/api/user_permission.py
View file @
37be53f3
...
...
@@ -88,13 +88,18 @@ class UserGrantedNodeAssetsApi(UserPermissionCacheMixin, GrantAssetsMixin, ListA
def
get_queryset
(
self
):
user
=
self
.
get_object
()
query_all
=
self
.
request
.
query_params
.
get
(
"all"
,
"0"
)
==
"1"
self
.
util
=
AssetPermissionUtil
(
user
,
cache_policy
=
self
.
cache_policy
)
key
=
self
.
get_node_key
()
nodes_items
=
self
.
util
.
get_nodes_with_assets
()
assets_system_users
=
{}
if
query_all
:
k
=
"all_assets"
else
:
k
=
"assets"
for
item
in
nodes_items
:
if
item
[
"key"
]
==
key
:
assets_system_users
=
item
[
"assets"
]
assets_system_users
=
item
[
k
]
break
assets
=
[]
for
asset_id
,
system_users
in
assets_system_users
.
items
():
...
...
apps/perms/serializers/user_permission.py
View file @
37be53f3
...
...
@@ -44,7 +44,7 @@ class AssetGrantedSerializer(serializers.ModelSerializer):
model
=
Asset
only_fields
=
[
"id"
,
"hostname"
,
"ip"
,
"protocols"
,
"os"
,
'domain'
,
"platform"
,
"org_id"
,
"platform"
,
"
comment"
,
"
org_id"
,
]
fields
=
only_fields
+
[
'system_users_granted'
,
'system_users_join'
,
"org_name"
]
read_only_fields
=
fields
...
...
apps/perms/utils/asset_permission.py
View file @
37be53f3
...
...
@@ -203,14 +203,16 @@ class GenerateTree:
nodes
=
[]
for
key
,
values
in
nodes_with_assets_amount
.
items
():
assets
=
{
asset_id
:
self
.
assets
.
get
(
asset_id
)
for
asset_id
in
values
[
"assets"
]}
all_assets
=
{
asset_id
:
self
.
assets
.
get
(
asset_id
)
for
asset_id
in
values
[
"all_assets"
]}
nodes
.
append
({
"key"
:
key
,
"assets"
:
assets
,
"key"
:
key
,
"assets"
:
assets
,
"all_assets"
:
all_assets
,
"assets_amount"
:
values
[
"assets_amount"
]
})
# 如果返回空节点,页面构造授权资产树报错
if
not
nodes
:
nodes
.
append
({
"key"
:
const
.
EMPTY_NODE_KEY
,
"assets"
:
{},
"assets_amount"
:
0
"key"
:
const
.
EMPTY_NODE_KEY
,
"assets"
:
{},
"assets_amount"
:
0
,
"all_assets"
:
{},
})
nodes
.
sort
(
key
=
lambda
n
:
self
.
key_sort
(
n
[
"key"
]))
self
.
_nodes_with_assets
=
nodes
...
...
apps/perms/utils/stack.py
View file @
37be53f3
...
...
@@ -102,7 +102,8 @@ class PermAssetsAmountUtil(PermStackUtilMixin):
self
.
debug
(
"出栈: {} 栈顶: {}"
.
format
(
_node
[
'key'
],
self
.
stack
.
top
[
'key'
]
if
self
.
stack
.
top
else
None
)
)
_node
[
"assets_amount"
]
=
len
(
_node
[
"all_assets"
]
|
_node
[
"assets"
])
_node
[
"all_assets"
]
=
_node
[
"all_assets"
]
|
_node
[
"assets"
]
_node
[
"assets_amount"
]
=
len
(
_node
[
"all_assets"
])
self
.
_nodes
[
_node
.
pop
(
"key"
)]
=
_node
if
not
self
.
stack
.
top
:
...
...
apps/users/templates/users/user_granted_asset.html
View file @
37be53f3
...
...
@@ -33,7 +33,7 @@
{% block custom_foot_js %}
<script>
var
assetTableUrl
=
"{% url 'api-perms:user-assets' pk=object.id %}?cache_policy=1"
;
var
selectUrl
=
'{% url "api-perms:user-node-assets" pk=object.id node_id=DEFAULT_PK %}?cache_policy=1'
;
var
selectUrl
=
'{% url "api-perms:user-node-assets" pk=object.id node_id=DEFAULT_PK %}?cache_policy=1
&all=1
'
;
var
treeUrl
=
"{% url 'api-perms:user-nodes-as-tree' pk=object.id %}?&cache_policy=1"
;
$
(
document
).
ready
(
function
()
{
...
...
apps/users/templates/users/user_group_granted_asset.html
View file @
37be53f3
...
...
@@ -35,7 +35,7 @@
<script>
var
treeUrl
=
"{% url 'api-perms:user-group-nodes-as-tree' pk=object.id %}?cache_policy=1"
;
var
assetTableUrl
=
"{% url 'api-perms:user-group-assets' pk=object.id %}?cache_policy=1"
;
var
selectUrl
=
'{% url "api-perms:user-group-node-assets" pk=object.id node_id=DEFAULT_PK %}?cache_policy=1'
;
var
selectUrl
=
'{% url "api-perms:user-group-node-assets" pk=object.id node_id=DEFAULT_PK %}?cache_policy=1
&all=1
'
;
var
showAssetHref
=
true
;
// Need input default true
...
...
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