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
d41d58e3
Commit
d41d58e3
authored
Jul 01, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改serializer
parent
ae690050
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
7 deletions
+11
-7
asset.py
apps/assets/serializers/asset.py
+1
-1
user_permission.py
apps/perms/api/user_permission.py
+2
-3
api_urls.py
apps/perms/urls/api_urls.py
+2
-0
asset_permission.py
apps/perms/utils/asset_permission.py
+6
-3
No files found.
apps/assets/serializers/asset.py
View file @
d41d58e3
...
...
@@ -161,7 +161,7 @@ class AssetGrantedSerializer(serializers.ModelSerializer):
class
Meta
:
model
=
Asset
fields
=
(
"id"
,
"hostname"
,
"ip"
,
"protocol
"
,
"port"
,
"protocol
s"
,
"id"
,
"hostname"
,
"ip"
,
"protocols"
,
"system_users_granted"
,
"is_active"
,
"system_users_join"
,
"os"
,
'domain'
,
"platform"
,
"comment"
,
"org_id"
,
"org_name"
,
)
...
...
apps/perms/api/user_permission.py
View file @
d41d58e3
...
...
@@ -207,8 +207,7 @@ class UserGrantedNodesWithAssetsApi(UserPermissionCacheMixin, AssetsFilterMixin,
for
node
,
_assets
in
nodes
.
items
():
assets
=
_assets
.
keys
()
for
k
,
v
in
_assets
.
items
():
system_users_granted
=
[
s
for
s
in
v
if
k
.
has_protocol
(
s
.
protocol
)]
k
.
system_users_granted
=
system_users_granted
k
.
system_users_granted
=
v
node
.
assets_granted
=
assets
queryset
.
append
(
node
)
return
queryset
...
...
@@ -298,6 +297,7 @@ class UserGrantedNodeAssetsApi(UserPermissionCacheMixin, AssetsFilterMixin, List
user
=
self
.
get_object
()
node_id
=
self
.
kwargs
.
get
(
'node_id'
)
util
=
AssetPermissionUtil
(
user
,
cache_policy
=
self
.
cache_policy
)
nodes
=
util
.
get_nodes_with_assets
()
if
str
(
node_id
)
==
const
.
UNGROUPED_NODE_ID
:
node
=
util
.
tree
.
ungrouped_node
else
:
...
...
@@ -305,7 +305,6 @@ class UserGrantedNodeAssetsApi(UserPermissionCacheMixin, AssetsFilterMixin, List
if
node
==
util
.
tree
.
root_node
:
assets
=
util
.
get_assets
()
else
:
nodes
=
util
.
get_nodes_with_assets
()
assets
=
nodes
.
get
(
node
,
[])
for
asset
,
system_users
in
assets
.
items
():
asset
.
system_users_granted
=
system_users
...
...
apps/perms/urls/api_urls.py
View file @
d41d58e3
...
...
@@ -13,6 +13,8 @@ router.register('remote-app-permissions', api.RemoteAppPermissionViewSet, 'remot
asset_permission_urlpatterns
=
[
# 查询某个用户授权的资产和资产组
path
(
'user/<uuid:pk>/assets/'
,
api
.
UserGrantedAssetsApi
.
as_view
()),
path
(
'users/<uuid:pk>/assets/'
,
api
.
UserGrantedAssetsApi
.
as_view
(),
name
=
'user-assets'
),
path
(
'user/assets/'
,
api
.
UserGrantedAssetsApi
.
as_view
(),
name
=
'my-assets'
),
...
...
apps/perms/utils/asset_permission.py
View file @
d41d58e3
...
...
@@ -373,6 +373,8 @@ class AssetPermissionUtil(AssetPermissionCacheMixin):
"Node"
:
get_node_permissions
,
"SystemUser"
:
get_system_user_permissions
,
}
assets_prefetch
=
(
'id'
,
'hostname'
,
'ip'
,
"platform"
,
"domain_id"
,
"comment"
,
"is_active"
,
"os"
,
"org_id"
)
def
__init__
(
self
,
obj
,
cache_policy
=
'0'
):
self
.
object
=
obj
...
...
@@ -432,7 +434,7 @@ class AssetPermissionUtil(AssetPermissionCacheMixin):
assets
=
defaultdict
(
lambda
:
defaultdict
(
int
))
for
perm
in
self
.
permissions
:
actions
=
[
perm
.
actions
]
_assets
=
perm
.
assets
.
all
()
.
prefetch_related
(
'nodes'
,
'protocols'
)
_assets
=
perm
.
assets
.
all
()
.
prefetch_related
(
*
self
.
assets_prefetch
)
system_users
=
perm
.
system_users
.
all
()
iterable
=
itertools
.
product
(
_assets
,
system_users
,
actions
)
for
asset
,
system_user
,
action
in
iterable
:
...
...
@@ -456,10 +458,11 @@ class AssetPermissionUtil(AssetPermissionCacheMixin):
print
(
"Get node assets start"
)
if
pattern
:
assets
=
Asset
.
objects
.
filter
(
nodes__key__regex
=
pattern
)
\
.
prefetch_related
(
'nodes'
,
"protocols"
)
.
only
(
'id'
,
'hostname'
,
'ip'
)
.
distinct
()
.
prefetch_related
(
'nodes'
,
"protocols"
)
\
.
only
(
*
self
.
assets_prefetch
)
\
.
distinct
()
else
:
assets
=
[]
assets
=
list
(
assets
)
print
(
"Get node assets end, using: {}"
.
format
(
time
.
time
()
-
now
))
self
.
tree
.
add_assets_without_system_users
(
assets
)
assets
=
self
.
tree
.
get_assets
()
...
...
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