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
6104acae
Commit
6104acae
authored
Feb 07, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 资产列表选中和移除资产
parent
bd4768c1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
111 additions
and
17 deletions
+111
-17
asset.py
apps/assets/api/asset.py
+1
-1
tree.py
apps/assets/api/tree.py
+28
-1
serializers.py
apps/assets/serializers.py
+8
-0
_asset_list_modal.html
apps/assets/templates/assets/_asset_list_modal.html
+13
-0
tree.html
apps/assets/templates/assets/tree.html
+44
-8
api_urls.py
apps/assets/urls/api_urls.py
+2
-0
asset_permission_list.html
apps/perms/templates/perms/asset_permission_list.html
+15
-6
jumpserver.js
apps/static/js/jumpserver.js
+0
-1
No files found.
apps/assets/api/asset.py
View file @
6104acae
...
...
@@ -62,7 +62,7 @@ class AssetViewSet(IDInFilterMixin, LabelFilter, BulkModelViewSet):
queryset
=
queryset
.
filter
(
cluster__in
=
clusters
)
if
node_id
:
node
=
get_object_or_404
(
Node
,
id
=
node_id
)
queryset
=
queryset
.
filter
(
nodes__key__startswith
=
node
.
key
)
queryset
=
queryset
.
filter
(
nodes__key__startswith
=
node
.
key
)
.
distinct
()
return
queryset
...
...
apps/assets/api/tree.py
View file @
6104acae
...
...
@@ -14,6 +14,7 @@
# limitations under the License.
from
rest_framework
import
generics
,
mixins
from
rest_framework.views
import
APIView
from
rest_framework.response
import
Response
from
rest_framework_bulk
import
BulkModelViewSet
from
django.utils.translation
import
ugettext_lazy
as
_
...
...
@@ -25,7 +26,10 @@ from .. import serializers
logger
=
get_logger
(
__file__
)
__all__
=
[
'NodeViewSet'
,
'NodeChildrenApi'
]
__all__
=
[
'NodeViewSet'
,
'NodeChildrenApi'
,
'NodeAddAssetsApi'
,
'NodeRemoveAssetsApi'
,
]
class
NodeViewSet
(
BulkModelViewSet
):
...
...
@@ -70,3 +74,26 @@ class NodeChildrenApi(mixins.ListModelMixin, generics.CreateAPIView):
response
=
[{
"id"
:
node
.
id
,
"key"
:
node
.
key
,
"value"
:
node
.
value
}
for
node
in
children
]
return
Response
(
response
,
status
=
200
)
class
NodeAddAssetsApi
(
generics
.
UpdateAPIView
):
serializer_class
=
serializers
.
NodeAssetsSerializer
queryset
=
Node
.
objects
.
all
()
permission_classes
=
(
IsSuperUser
,)
instance
=
None
def
perform_update
(
self
,
serializer
):
assets
=
serializer
.
validated_data
.
get
(
'assets'
)
instance
=
self
.
get_object
()
instance
.
assets
.
add
(
*
tuple
(
assets
))
class
NodeRemoveAssetsApi
(
generics
.
UpdateAPIView
):
serializer_class
=
serializers
.
NodeAssetsSerializer
queryset
=
Node
.
objects
.
all
()
permission_classes
=
(
IsSuperUser
,)
instance
=
None
def
perform_update
(
self
,
serializer
):
assets
=
serializer
.
validated_data
.
get
(
'assets'
)
instance
=
self
.
get_object
()
instance
.
assets
.
remove
(
*
tuple
(
assets
))
apps/assets/serializers.py
View file @
6104acae
...
...
@@ -335,3 +335,11 @@ class NodeSerializer(serializers.ModelSerializer):
field
=
fields
[
"key"
]
field
.
required
=
False
return
fields
class
NodeAssetsSerializer
(
serializers
.
ModelSerializer
):
assets
=
serializers
.
PrimaryKeyRelatedField
(
many
=
True
,
queryset
=
Asset
.
objects
.
all
())
class
Meta
:
model
=
Node
fields
=
[
'assets'
]
apps/assets/templates/assets/_asset_list_modal.html
View file @
6104acae
...
...
@@ -109,7 +109,20 @@ $(document).ready(function(){
return
}
var
data
=
{
'assets'
:
id_list
};
var
success
=
function
()
{
modal_table
.
ajax
.
reload
()
};
APIUpdateAttr
({
'url'
:
'/api/assets/v1/nodes/'
+
current_node
.
id
+
'/assets/add/'
,
'method'
:
'PUT'
,
'body'
:
JSON
.
stringify
(
data
),
'success'
:
success
})
})
</script>
...
...
apps/assets/templates/assets/tree.html
View file @
6104acae
...
...
@@ -88,6 +88,7 @@
<select
class=
"form-control m-b"
style=
"width: auto"
id=
"slct_bulk_update"
>
<option
value=
"delete"
>
{% trans 'Delete selected' %}
</option>
<option
value=
"update"
>
{% trans 'Update selected' %}
</option>
<option
value=
"remove"
>
{% trans 'Remove from this node' %}
</option>
<option
value=
"deactive"
>
{% trans 'Deactive selected' %}
</option>
<option
value=
"active"
>
{% trans 'Active selected' %}
</option>
</select>
...
...
@@ -169,8 +170,6 @@ function initTable() {
}
function
addTreeNode
()
{
hideRMenu
();
var
parentNode
=
zTree
.
getSelectedNodes
()[
0
];
...
...
@@ -281,17 +280,26 @@ function onRename(event, treeId, treeNode, isCancel){
function
onSelected
(
event
,
treeNode
)
{
var
url
=
asset_table
.
ajax
.
url
();
url
=
setUrlParam
(
url
,
"node_id"
,
treeNode
.
id
);
setCookie
(
'node_selected'
,
treeNode
.
id
);
asset_table
.
ajax
.
url
(
url
);
asset_table
.
ajax
.
reload
();
}
function
selectQueryNode
()
{
var
node_id
=
$
.
getUrlParam
(
"node"
);
if
(
node_id
!==
null
)
{
var
node
=
zTree
.
getNodesByParam
(
"id"
,
node_id
,
null
);
if
(
node
){
zTree
.
selectNode
(
node
[
0
]);
}
var
query_node_id
=
$
.
getUrlParam
(
"node"
);
var
cookie_node_id
=
getCookie
(
'node_selected'
);
var
node
;
var
node_id
;
if
(
query_node_id
!==
null
)
{
node_id
=
query_node_id
}
else
if
(
cookie_node_id
!==
null
)
{
node_id
=
cookie_node_id
;
}
node
=
zTree
.
getNodesByParam
(
"id"
,
node_id
,
null
);
if
(
node
){
zTree
.
selectNode
(
node
[
0
]);
}
}
...
...
@@ -479,6 +487,31 @@ $(document).ready(function(){
var
url
=
"{% url 'assets:asset-bulk-update' %}?assets_id="
+
id_list_string
;
location
.
href
=
url
}
function
doRemove
()
{
var
current_node
;
var
nodes
=
zTree
.
getSelectedNodes
();
if
(
nodes
&&
nodes
.
length
===
1
)
{
current_node
=
nodes
[
0
]
}
else
{
return
}
var
data
=
{
'assets'
:
id_list
};
var
success
=
function
()
{
asset_table
.
ajax
.
reload
()
};
APIUpdateAttr
({
'url'
:
'/api/assets/v1/nodes/'
+
current_node
.
id
+
'/assets/remove/'
,
'method'
:
'PUT'
,
'body'
:
JSON
.
stringify
(
data
),
'success'
:
success
})
}
switch
(
action
)
{
case
'deactive'
:
doDeactive
();
...
...
@@ -492,6 +525,9 @@ $(document).ready(function(){
case
'active'
:
doActive
();
break
;
case
'remove'
:
doRemove
();
break
;
default
:
break
;
}
...
...
apps/assets/urls/api_urls.py
View file @
6104acae
...
...
@@ -44,6 +44,8 @@ urlpatterns = [
url
(
r'^v1/system-user/(?P<pk>[0-9a-zA-Z\-]{36})/connective/$'
,
api
.
SystemUserTestConnectiveApi
.
as_view
(),
name
=
'system-user-connective'
),
url
(
r'^v1/nodes/(?P<pk>[0-9a-zA-Z\-]{36})/children/$'
,
api
.
NodeChildrenApi
.
as_view
(),
name
=
'node-children'
),
url
(
r'^v1/nodes/(?P<pk>[0-9a-zA-Z\-]{36})/assets/add/$'
,
api
.
NodeAddAssetsApi
.
as_view
(),
name
=
'node-add-assets'
),
url
(
r'^v1/nodes/(?P<pk>[0-9a-zA-Z\-]{36})/assets/remove/$'
,
api
.
NodeRemoveAssetsApi
.
as_view
(),
name
=
'node-remove-assets'
),
]
urlpatterns
+=
router
.
urls
...
...
apps/perms/templates/perms/asset_permission_list.html
View file @
6104acae
...
...
@@ -135,17 +135,26 @@ function initTable() {
function
onSelected
(
event
,
treeNode
)
{
var
url
=
table
.
ajax
.
url
();
url
=
setUrlParam
(
url
,
"node_id"
,
treeNode
.
id
);
setCookie
(
'node_selected'
,
treeNode
.
id
);
table
.
ajax
.
url
(
url
);
table
.
ajax
.
reload
();
}
function
selectQueryNode
()
{
var
node_id
=
$
.
getUrlParam
(
"node"
);
if
(
node_id
!==
null
)
{
var
node
=
zTree
.
getNodesByParam
(
"id"
,
node_id
,
null
);
if
(
node
)
{
zTree
.
selectNode
(
node
[
0
]);
}
var
query_node_id
=
$
.
getUrlParam
(
"node"
);
var
cookie_node_id
=
getCookie
(
'node_selected'
);
var
node
;
var
node_id
;
if
(
query_node_id
!==
null
)
{
node_id
=
query_node_id
}
else
if
(
cookie_node_id
!==
null
)
{
node_id
=
cookie_node_id
;
}
node
=
zTree
.
getNodesByParam
(
"id"
,
node_id
,
null
);
if
(
node
){
zTree
.
selectNode
(
node
[
0
]);
}
}
...
...
apps/static/js/jumpserver.js
View file @
6104acae
...
...
@@ -562,7 +562,6 @@ function setUrlParam(url, name, value) {
url
=
urlArray
[
0
]
+
"?"
;
var
newParam
=
[];
$
.
each
(
oriParamMap
,
function
(
index
,
value
)
{
console
.
log
(
index
,
value
);
newParam
.
push
(
index
+
"="
+
value
);
});
url
+=
newParam
.
join
(
"&"
)
...
...
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