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
0a13b4bb
Commit
0a13b4bb
authored
Sep 24, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修复密码匣子的bug
parent
dea9151a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
3 deletions
+26
-3
asset_user.py
apps/assets/api/asset_user.py
+1
-1
asset_user.py
apps/assets/backends/asset_user.py
+20
-2
base.py
apps/assets/backends/base.py
+5
-0
No files found.
apps/assets/api/asset_user.py
View file @
0a13b4bb
...
@@ -49,7 +49,7 @@ class AssetUserSearchBackend(filters.BaseFilterBackend):
...
@@ -49,7 +49,7 @@ class AssetUserSearchBackend(filters.BaseFilterBackend):
if
field
in
(
"node_id"
,
"system_user_id"
,
"admin_user_id"
):
if
field
in
(
"node_id"
,
"system_user_id"
,
"admin_user_id"
):
continue
continue
_queryset
|=
queryset
.
filter
(
**
{
field
:
value
})
_queryset
|=
queryset
.
filter
(
**
{
field
:
value
})
return
_queryset
return
_queryset
.
distinct
()
class
AssetUserViewSet
(
IDInCacheFilterMixin
,
BulkModelViewSet
):
class
AssetUserViewSet
(
IDInCacheFilterMixin
,
BulkModelViewSet
):
...
...
apps/assets/backends/asset_user.py
View file @
0a13b4bb
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
#
#
from
collections
import
defaultdict
from
.base
import
BaseBackend
from
.base
import
BaseBackend
...
@@ -23,6 +24,7 @@ class AssetUserBackend(BaseBackend):
...
@@ -23,6 +24,7 @@ class AssetUserBackend(BaseBackend):
queryset
=
queryset
.
filter
(
username
=
username
)
queryset
=
queryset
.
filter
(
username
=
username
)
if
assets
:
if
assets
:
queryset
=
queryset
.
filter
(
assets__in
=
assets
)
.
distinct
()
queryset
=
queryset
.
filter
(
assets__in
=
assets
)
.
distinct
()
queryset
=
cls
.
filter_queryset_more
(
queryset
)
queryset
=
cls
.
filter_queryset_more
(
queryset
)
instances
=
cls
.
construct_authbook_objects
(
queryset
,
assets
)
instances
=
cls
.
construct_authbook_objects
(
queryset
,
assets
)
return
instances
return
instances
...
@@ -30,10 +32,26 @@ class AssetUserBackend(BaseBackend):
...
@@ -30,10 +32,26 @@ class AssetUserBackend(BaseBackend):
@classmethod
@classmethod
def
construct_authbook_objects
(
cls
,
asset_users
,
assets
):
def
construct_authbook_objects
(
cls
,
asset_users
,
assets
):
instances
=
[]
instances
=
[]
assets_user_assets_map
=
defaultdict
(
set
)
if
isinstance
(
asset_users
,
list
):
assets_user_assets_map
=
{
asset_user
.
id
:
asset_user
.
assets
.
values_list
(
'id'
,
flat
=
True
)
for
asset_user
in
asset_users
}
else
:
assets_user_assets
=
asset_users
.
values_list
(
'id'
,
'assets'
)
for
i
,
asset_id
in
assets_user_assets
:
assets_user_assets_map
[
i
]
.
add
(
asset_id
)
for
asset_user
in
asset_users
:
for
asset_user
in
asset_users
:
if
not
assets
:
if
not
assets
:
assets
=
asset_user
.
assets
.
all
()
related_assets
=
asset_user
.
assets
.
all
()
for
asset
in
assets
:
else
:
assets_map
=
{
a
.
id
:
a
for
a
in
assets
}
related_assets
=
[
assets_map
.
get
(
i
)
for
i
in
assets_user_assets_map
.
get
(
asset_user
.
id
)
if
i
in
assets_map
]
for
asset
in
related_assets
:
instance
=
asset_user
.
construct_to_authbook
(
asset
)
instance
=
asset_user
.
construct_to_authbook
(
asset
)
instance
.
backend
=
cls
.
backend
instance
.
backend
=
cls
.
backend
instances
.
append
(
instance
)
instances
.
append
(
instance
)
...
...
apps/assets/backends/base.py
View file @
0a13b4bb
...
@@ -81,6 +81,11 @@ class AssetUserQuerySet(list):
...
@@ -81,6 +81,11 @@ class AssetUserQuerySet(list):
queryset
=
self
.
filter_in
(
kwargs
)
.
filter_equal
(
kwargs
)
queryset
=
self
.
filter_in
(
kwargs
)
.
filter_equal
(
kwargs
)
return
queryset
return
queryset
def
distinct
(
self
):
items
=
list
(
set
(
self
))
self
[:]
=
items
return
self
def
__or__
(
self
,
other
):
def
__or__
(
self
,
other
):
self
.
extend
(
other
)
self
.
extend
(
other
)
return
self
return
self
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