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
79c8f227
Commit
79c8f227
authored
Nov 05, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update perm api
parent
5b0f8971
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
8 deletions
+42
-8
api.py
apps/perms/api.py
+36
-4
urls.py
apps/perms/urls.py
+6
-4
No files found.
apps/perms/api.py
View file @
79c8f227
...
...
@@ -15,7 +15,7 @@ class AssetPermissionListCreateApi(ListCreateAPIView):
permission_classes
=
(
IsSuperUser
,)
class
UserAssets
Granted
Api
(
APIView
):
class
UserAssetsApi
(
APIView
):
permission_classes
=
(
IsValidUser
,)
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
@@ -44,7 +44,7 @@ class UserAssetsGrantedApi(APIView):
return
Response
(
assets_json
,
status
=
200
)
class
UserAssetsGroups
Granted
Api
(
APIView
):
class
UserAssetsGroupsApi
(
APIView
):
permission_classes
=
(
IsValidUser
,)
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
@@ -61,8 +61,41 @@ class UserAssetsGroupsGrantedApi(APIView):
asset_groups
[
asset_group
.
id
]
=
{
'id'
:
asset_group
.
id
,
'name'
:
asset_group
.
name
,
'comment'
:
asset_group
.
comment
,
'asset_num'
:
1
}
asset_groups_json
=
asset_groups
.
values
()
return
Response
(
asset_groups_json
,
status
=
200
)
\ No newline at end of file
return
Response
(
asset_groups_json
,
status
=
200
)
class
UserAssetsGroupAssetsApi
(
APIView
):
permission_classes
=
(
IsValidUser
,)
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
# asset_group_id = request.query_params.get('asset_group_id', -1)
asset_group_id
=
kwargs
.
get
(
'pk'
,
-
1
)
# asset_group_name = request.query_params.get('asset_group_name', '')
user
=
request
.
user
assets_json
=
[]
if
user
:
assets
=
get_user_granted_assets
(
user
)
for
asset
,
system_users
in
assets
.
items
():
for
asset_group
in
asset
.
groups
.
all
():
if
str
(
asset_group
.
id
)
==
asset_group_id
:
# and asset_group.name == asset_group_name:
assets_json
.
append
({
'id'
:
asset
.
id
,
'hostname'
:
asset
.
hostname
,
'ip'
:
asset
.
ip
,
'port'
:
asset
.
port
,
'system_users'
:
[
{
'id'
:
system_user
.
id
,
'name'
:
system_user
.
name
,
'username'
:
system_user
.
username
,
}
for
system_user
in
system_users
],
'comment'
:
asset
.
comment
})
return
Response
(
assets_json
,
status
=
200
)
apps/perms/urls.py
View file @
79c8f227
...
...
@@ -24,9 +24,11 @@ urlpatterns = [
urlpatterns
+=
[
url
(
r'^v1/asset-permission/$'
,
api
.
AssetPermissionListCreateApi
.
as_view
(),
name
=
'asset-permission-list-create-api'
),
url
(
r'^v1/user/assets/granted/$'
,
api
.
UserAssetsGrantedApi
.
as_view
(),
name
=
'user-assets-granted'
),
url
(
r'^v1/user/asset-groups/granted/$'
,
api
.
UserAssetsGroupsGrantedApi
.
as_view
(),
name
=
'user-asset-groups-granted'
),
url
(
r'^v1/user/assets/$'
,
api
.
UserAssetsApi
.
as_view
(),
name
=
'user-assets'
),
url
(
r'^v1/user/asset-groups/$'
,
api
.
UserAssetsGroupsApi
.
as_view
(),
name
=
'user-asset-groups'
),
url
(
r'^v1/user/asset-groups/(?P<pk>[0-9]+)/assets/$'
,
api
.
UserAssetsGroupAssetsApi
.
as_view
(),
name
=
'user-asset-groups-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