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
3639b190
Commit
3639b190
authored
Nov 01, 2017
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update perm api
parent
034f0a02
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
18 deletions
+29
-18
asset.py
apps/assets/models/asset.py
+1
-2
api.py
apps/perms/api.py
+23
-15
utils.py
apps/perms/utils.py
+5
-0
utils.py
apps/users/utils.py
+0
-1
No files found.
apps/assets/models/asset.py
View file @
3639b190
...
...
@@ -89,9 +89,8 @@ class Asset(models.Model):
date_created
=
models
.
DateTimeField
(
auto_now_add
=
True
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
'Date created'
))
comment
=
models
.
TextField
(
max_length
=
128
,
default
=
''
,
blank
=
True
,
verbose_name
=
_
(
'Comment'
))
def
__
unicode
__
(
self
):
def
__
str
__
(
self
):
return
'
%
s <
%
s:
%
s>'
%
(
self
.
hostname
,
self
.
ip
,
self
.
port
)
__str__
=
__unicode__
@property
def
is_valid
(
self
):
...
...
apps/perms/api.py
View file @
3639b190
...
...
@@ -140,11 +140,25 @@ class UserGrantedAssetGroupsApi(ListAPIView):
def
get_queryset
(
self
):
user_id
=
self
.
kwargs
.
get
(
'pk'
,
''
)
if
user_id
:
user
=
get_object_or_404
(
User
,
id
=
user_id
)
queryset
=
get_user_granted_asset_groups
(
user
)
else
:
queryset
=
[]
if
not
user_id
:
return
[]
user
=
get_object_or_404
(
User
,
id
=
user_id
)
if
user
:
asset_groups
=
{}
for
asset
,
system_
in
get_user_granted_assets
(
user
)
.
items
():
for
asset_group
in
asset
.
groups
.
all
():
if
asset_group
.
id
in
asset_groups
:
asset_groups
[
asset_group
.
id
][
'assets_amount'
]
+=
1
else
:
asset_groups
[
asset_group
.
id
]
=
{
'id'
:
asset_group
.
id
,
'name'
:
asset_group
.
name
,
'comment'
:
asset_group
.
comment
,
'assets_amount'
:
1
}
asset_groups_json
=
asset_groups
.
values
()
return
queryset
...
...
@@ -166,10 +180,11 @@ class MyGrantedAssetsApi(ListAPIView):
return
queryset
class
MyGrantedAssetsGroupsApi
(
APIView
):
"""授权给用户的资产组列表, 非直接通过授权规则授权的资产组列表, 而是授权资产的所有
资产组之和"""
"""
授权给用户的资产组列表, 非直接通过授权规则授权的资产组列表, 而是授权资产的所有
资产组之和
"""
permission_classes
=
(
IsValidUser
,)
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
@@ -201,13 +216,6 @@ class MyAssetGroupAssetsApi(ListAPIView):
asset_groups
[
0
]
=
{
'id'
:
0
,
'name'
:
'ungrouped'
,
'assets'
:
[]
}
# asset_group = {
# 1: {'id': 1, 'name': 'hello',
# 'assets': [{
# 'id': 'asset_id',
# 'system_users': [{'id': 'system_user_id',...},]
# }],
# 'assets_id': set()}, 2: {}}
user
=
request
.
user
if
user
:
...
...
apps/perms/utils.py
View file @
3639b190
...
...
@@ -190,6 +190,11 @@ def get_user_granted_assets(user):
return
assets
def
get_user_granted_asset_groups
(
user
):
pass
def
get_user_group_asset_permissions
(
user_group
):
permissions
=
user_group
.
asset_permissions
.
all
()
return
permissions
...
...
apps/users/utils.py
View file @
3639b190
...
...
@@ -167,7 +167,6 @@ def generate_token(request, user):
token
=
cache
.
get
(
'
%
s_
%
s'
%
(
user
.
id
,
remote_addr
))
if
not
token
:
token
=
uuid
.
uuid4
()
.
hex
print
(
'Set cache:
%
s'
%
token
)
cache
.
set
(
token
,
user
.
id
,
expiration
)
cache
.
set
(
'
%
s_
%
s'
%
(
user
.
id
,
remote_addr
),
token
,
expiration
)
return
token
...
...
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