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
02087e00
Unverified
Commit
02087e00
authored
Sep 24, 2019
by
BaiJiangJie
Committed by
GitHub
Sep 24, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3267 from jumpserver/dev_ra
[Update] 优化用户授权 RemoteApp API 逻辑
parents
ffb4a262
e805e9ce
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
43 deletions
+7
-43
user_remote_app_list.html
...ications/templates/applications/user_remote_app_list.html
+1
-1
user_remote_app_permission.py
apps/perms/api/user_remote_app_permission.py
+5
-6
mixins.py
apps/perms/mixins.py
+1
-36
No files found.
apps/applications/templates/applications/user_remote_app_list.html
View file @
02087e00
...
...
@@ -49,7 +49,7 @@ function initTable() {
$
(
td
).
html
(
hostname
);
}},
{
targets
:
5
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
conn_btn
=
'<a href="{% url "luna-view" %}?login_to='
+
cellData
+
'" class="btn btn-xs btn-primary">{% trans "Connect" %}</a>'
.
replace
(
"{{ DEFAULT_PK }}"
,
cellData
);
var
conn_btn
=
'<a href="{% url "luna-view" %}?
type=remote_app&
login_to='
+
cellData
+
'" class="btn btn-xs btn-primary">{% trans "Connect" %}</a>'
.
replace
(
"{{ DEFAULT_PK }}"
,
cellData
);
$
(
td
).
html
(
conn_btn
)
}}
],
...
...
apps/perms/api/user_remote_app_permission.py
View file @
02087e00
...
...
@@ -14,7 +14,6 @@ from ..utils import (
parse_remote_app_to_tree_node
,
)
from
..hands
import
User
,
RemoteApp
,
RemoteAppSerializer
,
UserGroup
,
SystemUser
from
..mixins
import
RemoteAppFilterMixin
from
.mixin
import
UserPermissionMixin
from
..
import
serializers
...
...
@@ -26,10 +25,11 @@ __all__ = [
]
class
UserGrantedRemoteAppsApi
(
RemoteAppFilterMixin
,
ListAPIView
):
class
UserGrantedRemoteAppsApi
(
ListAPIView
):
permission_classes
=
(
IsOrgAdminOrAppUser
,)
serializer_class
=
RemoteAppSerializer
filter_fields
=
[
'id'
]
filter_fields
=
[
'name'
,
'id'
]
search_fields
=
[
'name'
]
def
get_object
(
self
):
user_id
=
self
.
kwargs
.
get
(
'pk'
,
''
)
...
...
@@ -54,15 +54,14 @@ class UserGrantedRemoteAppsAsTreeApi(UserGrantedRemoteAppsApi):
serializer_class
=
TreeNodeSerializer
permission_classes
=
(
IsOrgAdminOrAppUser
,)
def
get_serializer
(
self
,
*
args
,
**
kwargs
):
def
get_serializer
(
self
,
remote_apps
=
None
,
*
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
:
for
remote_app
in
remote_apps
:
node
=
parse_remote_app_to_tree_node
(
tree_root
,
remote_app
)
data
.
append
(
node
)
data
.
sort
()
...
...
apps/perms/mixins.py
View file @
02087e00
...
...
@@ -4,7 +4,7 @@
from
orgs.utils
import
set_to_root_org
__all__
=
[
'AssetsFilterMixin'
,
'
RemoteAppFilterMixin'
,
'
ChangeOrgIfNeedMixin'
,
'AssetsFilterMixin'
,
'ChangeOrgIfNeedMixin'
,
]
...
...
@@ -68,41 +68,6 @@ class AssetsFilterMixin(object):
return
_queryset
class
RemoteAppFilterMixin
(
object
):
"""
对RemoteApp进行过滤(查询,排序)
"""
def
filter_queryset
(
self
,
queryset
):
queryset
=
self
.
search_remote_apps
(
queryset
)
queryset
=
self
.
sort_remote_apps
(
queryset
)
return
queryset
def
search_remote_apps
(
self
,
queryset
):
value
=
self
.
request
.
query_params
.
get
(
'search'
)
if
not
value
:
return
queryset
queryset
=
[
remote_app
for
remote_app
in
queryset
if
value
in
remote_app
.
name
]
return
queryset
def
sort_remote_apps
(
self
,
queryset
):
order_by
=
self
.
request
.
query_params
.
get
(
'order'
)
if
not
order_by
:
order_by
=
'name'
if
order_by
.
startswith
(
'-'
):
order_by
=
order_by
.
lstrip
(
'-'
)
reverse
=
True
else
:
reverse
=
False
queryset
=
sorted
(
queryset
,
key
=
lambda
x
:
getattr
(
x
,
order_by
),
reverse
=
reverse
)
return
queryset
class
ChangeOrgIfNeedMixin
(
object
):
@staticmethod
...
...
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