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
d1f37d4b
Commit
d1f37d4b
authored
Sep 10, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改 remote app api
parent
6cb9ae69
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
38 deletions
+26
-38
user_remote_app_permission.py
apps/perms/api/user_remote_app_permission.py
+20
-34
remote_app_permission.py
apps/perms/utils/remote_app_permission.py
+6
-4
No files found.
apps/perms/api/user_remote_app_permission.py
View file @
d1f37d4b
...
...
@@ -12,7 +12,7 @@ from ..utils import (
RemoteAppPermissionUtil
,
construct_remote_apps_tree_root
,
parse_remote_app_to_tree_node
,
)
from
..hands
import
User
,
RemoteApp
,
RemoteApp
Serializer
,
UserGroup
from
..hands
import
User
,
RemoteAppSerializer
,
UserGroup
from
..mixins
import
RemoteAppFilterMixin
...
...
@@ -25,6 +25,7 @@ __all__ = [
class
UserGrantedRemoteAppsApi
(
RemoteAppFilterMixin
,
ListAPIView
):
permission_classes
=
(
IsOrgAdminOrAppUser
,)
serializer_class
=
RemoteAppSerializer
filter_fields
=
[
'id'
]
def
get_object
(
self
):
user_id
=
self
.
kwargs
.
get
(
'pk'
,
''
)
...
...
@@ -37,7 +38,6 @@ class UserGrantedRemoteAppsApi(RemoteAppFilterMixin, ListAPIView):
def
get_queryset
(
self
):
util
=
RemoteAppPermissionUtil
(
self
.
get_object
())
queryset
=
util
.
get_remote_apps
()
queryset
=
list
(
queryset
)
return
queryset
def
get_permissions
(
self
):
...
...
@@ -46,36 +46,23 @@ class UserGrantedRemoteAppsApi(RemoteAppFilterMixin, ListAPIView):
return
super
()
.
get_permissions
()
class
UserGrantedRemoteAppsAsTreeApi
(
ListAPIView
):
class
UserGrantedRemoteAppsAsTreeApi
(
UserGrantedRemoteAppsApi
):
serializer_class
=
TreeNodeSerializer
permission_classes
=
(
IsOrgAdminOrAppUser
,)
def
get_object
(
self
):
user_id
=
self
.
kwargs
.
get
(
'pk'
,
''
)
if
not
user_id
:
user
=
self
.
request
.
user
else
:
user
=
get_object_or_404
(
User
,
id
=
user_id
)
return
user
def
get_queryset
(
self
):
queryset
=
[]
tree_root
=
construct_remote_apps_tree_root
()
queryset
.
append
(
tree_root
)
util
=
RemoteAppPermissionUtil
(
self
.
get_object
())
remote_apps
=
util
.
get_remote_apps
()
for
remote_app
in
remote_apps
:
def
get_serializer
(
self
,
*
args
,
**
kwargs
):
only_remote_app
=
self
.
request
.
query_params
.
get
(
'only'
,
'0'
)
==
'1'
tree_root
=
None
data
=
[]
if
not
only_remote_app
:
tree_root
=
construct_remote_apps_tree_root
()
data
.
append
(
tree_root
)
queryset
=
super
()
.
get_queryset
()
for
remote_app
in
queryset
:
node
=
parse_remote_app_to_tree_node
(
tree_root
,
remote_app
)
queryset
.
append
(
node
)
queryset
=
sorted
(
queryset
)
return
queryset
def
get_permissions
(
self
):
if
self
.
kwargs
.
get
(
'pk'
)
is
None
:
self
.
permission_classes
=
(
IsValidUser
,)
return
super
()
.
get_permissions
()
data
.
append
(
node
)
data
.
sort
()
return
super
()
.
get_serializer
(
data
,
many
=
True
)
class
ValidateUserRemoteAppPermissionApi
(
APIView
):
...
...
@@ -84,14 +71,13 @@ class ValidateUserRemoteAppPermissionApi(APIView):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
user_id
=
request
.
query_params
.
get
(
'user_id'
,
''
)
remote_app_id
=
request
.
query_params
.
get
(
'remote_app_id'
,
''
)
user
=
get_object_or_404
(
User
,
id
=
user_id
)
remote_app
=
get_object_or_404
(
RemoteApp
,
id
=
remote_app_id
)
user
=
get_object_or_404
(
User
,
id
=
user_id
)
util
=
RemoteAppPermissionUtil
(
user
)
remote_app
s
=
util
.
get_remote_app
s
()
if
remote_app
not
in
remote_apps
:
return
Response
({
'msg'
:
False
},
status
=
403
)
return
Response
({
'msg'
:
True
},
status
=
200
)
remote_app
=
util
.
get_remote_apps
()
.
filter
(
id
=
remote_app_id
)
.
exist
s
()
if
remote_app
:
return
Response
({
'msg'
:
True
},
status
=
200
)
return
Response
({
'msg'
:
False
},
status
=
403
)
# RemoteApp permission
...
...
apps/perms/utils/remote_app_permission.py
View file @
d1f37d4b
...
...
@@ -7,6 +7,7 @@ from common.tree import TreeNode
from
orgs.utils
import
set_to_root_org
from
..models
import
RemoteAppPermission
from
..hands
import
RemoteApp
__all__
=
[
...
...
@@ -53,9 +54,9 @@ class RemoteAppPermissionUtil:
return
_permissions
def
get_remote_apps
(
self
):
remote_apps
=
set
()
for
perm
in
self
.
permissions
:
remote_apps
.
update
(
list
(
perm
.
remote_apps
.
all
())
)
remote_apps
=
RemoteApp
.
objects
.
filter
(
granted_by_permissions__in
=
self
.
permissions
)
return
remote_apps
...
...
@@ -82,11 +83,12 @@ def parse_remote_app_to_tree_node(parent, remote_app):
'protocol'
:
system_user
.
protocol
,
'login_mode'
:
system_user
.
login_mode
,
}
pid
=
parent
.
id
if
parent
else
''
tree_node
=
{
'id'
:
remote_app
.
id
,
'name'
:
remote_app
.
name
,
'title'
:
remote_app
.
name
,
'pId'
:
p
arent
.
id
,
'pId'
:
pid
,
'open'
:
False
,
'isParent'
:
False
,
'iconSkin'
:
'file'
,
...
...
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