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
b4e1ac19
Commit
b4e1ac19
authored
Dec 18, 2017
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Bugfix] 修复资产模块中一些bug
parent
a308000d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
185 additions
and
344 deletions
+185
-344
api.py
apps/assets/api.py
+50
-65
forms.py
apps/assets/forms.py
+23
-9
serializers.py
apps/assets/serializers.py
+9
-31
admin_user_detail.html
apps/assets/templates/assets/admin_user_detail.html
+51
-70
asset_detail.html
apps/assets/templates/assets/asset_detail.html
+0
-1
asset_group_detail.html
apps/assets/templates/assets/asset_group_detail.html
+24
-39
asset_group_list.html
apps/assets/templates/assets/asset_group_list.html
+0
-13
cluster_assets.html
apps/assets/templates/assets/cluster_assets.html
+0
-0
cluster_list.html
apps/assets/templates/assets/cluster_list.html
+0
-12
api_urls.py
apps/assets/urls/api_urls.py
+7
-22
asset.py
apps/assets/views/asset.py
+7
-13
utils.py
apps/common/utils.py
+9
-1
django.mo
apps/locale/zh/LC_MESSAGES/django.mo
+0
-0
django.po
apps/locale/zh/LC_MESSAGES/django.po
+1
-1
utils.py
apps/ops/utils.py
+0
-49
user_group_detail.html
apps/users/templates/users/user_group_detail.html
+1
-2
user.py
apps/users/views/user.py
+3
-16
No files found.
apps/assets/api.py
View file @
b4e1ac19
...
@@ -74,23 +74,30 @@ class AssetUpdateGroupApi(generics.RetrieveUpdateAPIView):
...
@@ -74,23 +74,30 @@ class AssetUpdateGroupApi(generics.RetrieveUpdateAPIView):
permission_classes
=
(
IsSuperUser
,)
permission_classes
=
(
IsSuperUser
,)
class
AssetGroupUpdate
Api
(
generics
.
RetrieveUpdateAPIView
):
class
GroupUpdateAssets
Api
(
generics
.
RetrieveUpdateAPIView
):
"""
"""
Asset group, update it's asset member
Asset group, update it's asset member
"""
"""
queryset
=
AssetGroup
.
objects
.
all
()
queryset
=
AssetGroup
.
objects
.
all
()
serializer_class
=
serializers
.
AssetGroupUpdate
Serializer
serializer_class
=
serializers
.
GroupUpdateAssets
Serializer
permission_classes
=
(
IsSuperUser
,)
permission_classes
=
(
IsSuperUser
,)
class
AssetGroupUpdateSystemUserApi
(
generics
.
RetrieveUpdateAPIView
):
class
GroupAddAssetsApi
(
generics
.
UpdateAPIView
):
"""
Asset group push system user
"""
queryset
=
AssetGroup
.
objects
.
all
()
queryset
=
AssetGroup
.
objects
.
all
()
serializer_class
=
serializers
.
AssetGroupUpdateSystemUser
Serializer
serializer_class
=
serializers
.
GroupUpdateAssets
Serializer
permission_classes
=
(
IsSuperUser
,)
permission_classes
=
(
IsSuperUser
,)
def
update
(
self
,
request
,
*
args
,
**
kwargs
):
group
=
self
.
get_object
()
serializer
=
self
.
serializer_class
(
data
=
request
.
data
)
if
serializer
.
is_valid
():
assets
=
serializer
.
validated_data
[
'assets'
]
group
.
assets
.
add
(
*
tuple
(
assets
))
return
Response
({
"msg"
:
"ok"
})
else
:
return
Response
({
'error'
:
serializer
.
errors
},
status
=
400
)
class
ClusterUpdateAssetsApi
(
generics
.
RetrieveUpdateAPIView
):
class
ClusterUpdateAssetsApi
(
generics
.
RetrieveUpdateAPIView
):
"""
"""
...
@@ -110,6 +117,24 @@ class ClusterViewSet(IDInFilterMixin, BulkModelViewSet):
...
@@ -110,6 +117,24 @@ class ClusterViewSet(IDInFilterMixin, BulkModelViewSet):
permission_classes
=
(
IsSuperUser
,)
permission_classes
=
(
IsSuperUser
,)
class
ClusterAddAssetsApi
(
generics
.
UpdateAPIView
):
queryset
=
Cluster
.
objects
.
all
()
serializer_class
=
serializers
.
ClusterUpdateAssetsSerializer
permission_classes
=
(
IsSuperUser
,)
def
update
(
self
,
request
,
*
args
,
**
kwargs
):
cluster
=
self
.
get_object
()
serializer
=
self
.
serializer_class
(
data
=
request
.
data
)
if
serializer
.
is_valid
():
assets
=
serializer
.
validated_data
[
'assets'
]
for
asset
in
assets
:
asset
.
cluster
=
cluster
asset
.
save
()
return
Response
({
"msg"
:
"ok"
})
else
:
return
Response
({
'error'
:
serializer
.
errors
},
status
=
400
)
class
AdminUserViewSet
(
IDInFilterMixin
,
BulkModelViewSet
):
class
AdminUserViewSet
(
IDInFilterMixin
,
BulkModelViewSet
):
"""
"""
Admin user api set, for add,delete,update,list,retrieve resource
Admin user api set, for add,delete,update,list,retrieve resource
...
@@ -119,52 +144,31 @@ class AdminUserViewSet(IDInFilterMixin, BulkModelViewSet):
...
@@ -119,52 +144,31 @@ class AdminUserViewSet(IDInFilterMixin, BulkModelViewSet):
permission_classes
=
(
IsSuperUser
,)
permission_classes
=
(
IsSuperUser
,)
class
SystemUserViewSet
(
IDInFilterMixin
,
BulkModelViewSet
):
class
AdminUserAddClustersApi
(
generics
.
UpdateAPIView
):
"""
queryset
=
AdminUser
.
objects
.
all
()
System user api set, for add,delete,update,list,retrieve resource
serializer_class
=
serializers
.
AdminUserUpdateClusterSerializer
"""
queryset
=
SystemUser
.
objects
.
all
()
serializer_class
=
serializers
.
SystemUserSerializer
permission_classes
=
(
IsSuperUserOrAppUser
,)
class
SystemUserUpdateApi
(
generics
.
RetrieveUpdateAPIView
):
"""
Asset update it's system user
when update then push system user to asset.
"""
queryset
=
Asset
.
objects
.
all
()
serializer_class
=
serializers
.
AssetUpdateSystemUserSerializer
permission_classes
=
(
IsSuperUser
,)
permission_classes
=
(
IsSuperUser
,)
def
patch
(
self
,
request
,
*
args
,
**
kwargs
):
def
update
(
self
,
request
,
*
args
,
**
kwargs
):
asset
=
self
.
get_object
()
admin_user
=
self
.
get_object
()
old_system_users
=
set
(
asset
.
system_users
.
all
())
serializer
=
self
.
serializer_class
(
data
=
request
.
data
)
response
=
super
(
SystemUserUpdateApi
,
self
)
.
patch
(
request
,
*
args
,
**
kwargs
)
if
serializer
.
is_valid
():
system_users_new
=
set
(
asset
.
system_users
.
all
())
clusters
=
serializer
.
validated_data
[
'clusters'
]
system_users
=
system_users_new
-
old_system_users
for
cluster
in
clusters
:
system_users
=
[
system_user
.
_to_secret_json
()
for
system_user
in
system_users
]
cluster
.
admin_user
=
admin_user
push_users
.
delay
([
asset
.
_to_secret_json
()],
system_users
)
cluster
.
save
()
return
response
return
Response
({
"msg"
:
"ok"
})
else
:
return
Response
({
'error'
:
serializer
.
errors
},
status
=
400
)
class
SystemUserUpdateAssetsApi
(
generics
.
RetrieveUpdateAPIView
):
"""
System user update it's assets
"""
queryset
=
SystemUser
.
objects
.
all
()
serializer_class
=
serializers
.
SystemUserUpdateAssetsSerializer
permission_classes
=
(
IsSuperUser
,)
class
SystemUser
UpdateAssetGroupApi
(
generics
.
RetrieveUpdateAPIView
):
class
SystemUser
ViewSet
(
IDInFilterMixin
,
BulkModelViewSet
):
"""
"""
System user
update asset group
System user
api set, for add,delete,update,list,retrieve resource
"""
"""
queryset
=
SystemUser
.
objects
.
all
()
queryset
=
SystemUser
.
objects
.
all
()
serializer_class
=
serializers
.
SystemUser
UpdateAssetGroup
Serializer
serializer_class
=
serializers
.
SystemUserSerializer
permission_classes
=
(
IsSuperUser
,)
permission_classes
=
(
IsSuperUser
OrAppUser
,)
class
AssetListUpdateApi
(
IDInFilterMixin
,
ListBulkCreateUpdateDestroyAPIView
):
class
AssetListUpdateApi
(
IDInFilterMixin
,
ListBulkCreateUpdateDestroyAPIView
):
...
@@ -229,22 +233,3 @@ class AssetAdminUserTestView(AssetRefreshHardwareView):
...
@@ -229,22 +233,3 @@ class AssetAdminUserTestView(AssetRefreshHardwareView):
else
:
else
:
return
Response
(
'0'
,
status
=
502
)
return
Response
(
'0'
,
status
=
502
)
class
AssetGroupPushSystemUserView
(
generics
.
UpdateAPIView
):
"""
Asset group push system user api
"""
queryset
=
AssetGroup
.
objects
.
all
()
permission_classes
=
(
IsSuperUser
,)
serializer_class
=
serializers
.
AssetSerializer
def
patch
(
self
,
request
,
*
args
,
**
kwargs
):
asset_group
=
self
.
get_object
()
assets
=
asset_group
.
assets
.
all
()
system_user_id
=
self
.
request
.
data
[
'system_user'
]
system_user
=
get_object_or_none
(
SystemUser
,
id
=
system_user_id
)
if
not
assets
or
not
system_user
:
return
Response
(
'Invalid system user id or asset group id'
,
status
=
404
)
task
=
push_users
.
delay
([
asset
.
_to_secret_json
()
for
asset
in
assets
],
system_user
.
_to_secret_json
())
return
Response
(
task
.
id
)
apps/assets/forms.py
View file @
b4e1ac19
...
@@ -61,6 +61,7 @@ class AssetBulkUpdateForm(forms.ModelForm):
...
@@ -61,6 +61,7 @@ class AssetBulkUpdateForm(forms.ModelForm):
required
=
True
,
required
=
True
,
help_text
=
'* required'
,
help_text
=
'* required'
,
label
=
_
(
'Select assets'
),
label
=
_
(
'Select assets'
),
choices
=
[(
asset
.
id
,
asset
.
hostname
)
for
asset
in
Asset
.
objects
.
all
()],
widget
=
forms
.
SelectMultiple
(
widget
=
forms
.
SelectMultiple
(
attrs
=
{
attrs
=
{
'class'
:
'select2'
,
'class'
:
'select2'
,
...
@@ -68,7 +69,12 @@ class AssetBulkUpdateForm(forms.ModelForm):
...
@@ -68,7 +69,12 @@ class AssetBulkUpdateForm(forms.ModelForm):
}
}
)
)
)
)
port
=
forms
.
IntegerField
(
min_value
=
1
,
max_value
=
65535
,
required
=
False
,
label
=
_
(
'Port'
))
port
=
forms
.
IntegerField
(
label
=
_
(
'Port'
),
required
=
False
,
min_value
=
1
,
max_value
=
65535
,
)
class
Meta
:
class
Meta
:
model
=
Asset
model
=
Asset
...
@@ -81,9 +87,16 @@ class AssetBulkUpdateForm(forms.ModelForm):
...
@@ -81,9 +87,16 @@ class AssetBulkUpdateForm(forms.ModelForm):
}
}
def
save
(
self
,
commit
=
True
):
def
save
(
self
,
commit
=
True
):
cleaned_data
=
{
k
:
v
for
k
,
v
in
self
.
cleaned_data
.
items
()
if
v
is
not
None
}
changed_fields
=
[]
for
field
in
self
.
_meta
.
fields
:
if
self
.
data
.
get
(
field
)
is
not
None
:
changed_fields
.
append
(
field
)
cleaned_data
=
{
k
:
v
for
k
,
v
in
self
.
cleaned_data
.
items
()
if
k
in
changed_fields
}
print
(
cleaned_data
)
assets_id
=
cleaned_data
.
pop
(
'assets'
)
assets_id
=
cleaned_data
.
pop
(
'assets'
)
groups
=
cleaned_data
.
pop
(
'groups'
)
groups
=
cleaned_data
.
pop
(
'groups'
,
[]
)
assets
=
Asset
.
objects
.
filter
(
id__in
=
assets_id
)
assets
=
Asset
.
objects
.
filter
(
id__in
=
assets_id
)
assets
.
update
(
**
cleaned_data
)
assets
.
update
(
**
cleaned_data
)
if
groups
:
if
groups
:
...
@@ -153,17 +166,18 @@ class AdminUserForm(forms.ModelForm):
...
@@ -153,17 +166,18 @@ class AdminUserForm(forms.ModelForm):
def
save
(
self
,
commit
=
True
):
def
save
(
self
,
commit
=
True
):
# Because we define custom field, so we need rewrite :method: `save`
# Because we define custom field, so we need rewrite :method: `save`
admin_user
=
super
(
AdminUserForm
,
self
)
.
save
(
commit
=
commit
)
admin_user
=
super
()
.
save
(
commit
=
commit
)
password
=
self
.
cleaned_data
[
'password'
]
password
=
self
.
cleaned_data
[
'password'
]
private_key
=
self
.
cleaned_data
[
'private_key_file'
]
private_key
=
self
.
cleaned_data
[
'private_key_file'
]
public_key
=
None
if
not
password
:
password
=
None
if
password
:
admin_user
.
password
=
password
if
private_key
:
if
private_key
:
public_key
=
ssh_pubkey_gen
(
private_key
)
public_key
=
ssh_pubkey_gen
(
private_key
)
admin_user
.
private_key
=
private_key
admin_user
.
public_key
=
public_key
admin_user
.
set_auth
(
password
=
password
,
public_key
=
public_key
,
private_key
=
private_key
)
admin_user
.
save
()
return
admin_user
return
admin_user
def
clean_private_key_file
(
self
):
def
clean_private_key_file
(
self
):
...
...
apps/assets/serializers.py
View file @
b4e1ac19
...
@@ -47,7 +47,7 @@ class AssetUpdateSystemUserSerializer(serializers.ModelSerializer):
...
@@ -47,7 +47,7 @@ class AssetUpdateSystemUserSerializer(serializers.ModelSerializer):
fields
=
[
'id'
,
'system_users'
]
fields
=
[
'id'
,
'system_users'
]
class
AssetGroupUpdate
Serializer
(
serializers
.
ModelSerializer
):
class
GroupUpdateAssets
Serializer
(
serializers
.
ModelSerializer
):
"""
"""
资产组更新需要的数据结构
资产组更新需要的数据结构
"""
"""
...
@@ -58,17 +58,6 @@ class AssetGroupUpdateSerializer(serializers.ModelSerializer):
...
@@ -58,17 +58,6 @@ class AssetGroupUpdateSerializer(serializers.ModelSerializer):
fields
=
[
'id'
,
'assets'
]
fields
=
[
'id'
,
'assets'
]
class
AssetGroupUpdateSystemUserSerializer
(
serializers
.
ModelSerializer
):
"""
资产组更新系统用户定义的数据结构
"""
system_users
=
serializers
.
PrimaryKeyRelatedField
(
many
=
True
,
queryset
=
SystemUser
.
objects
.
all
())
class
Meta
:
model
=
AssetGroup
fields
=
[
'id'
,
'system_users'
]
class
ClusterUpdateAssetsSerializer
(
serializers
.
ModelSerializer
):
class
ClusterUpdateAssetsSerializer
(
serializers
.
ModelSerializer
):
"""
"""
集群更新资产数据结构
集群更新资产数据结构
...
@@ -135,35 +124,24 @@ class SystemUserSerializer(serializers.ModelSerializer):
...
@@ -135,35 +124,24 @@ class SystemUserSerializer(serializers.ModelSerializer):
return
amount
return
amount
class
AssetSystemUserSerializer
(
serializers
.
ModelSerializer
):
class
AdminUserUpdateClusterSerializer
(
serializers
.
ModelSerializer
):
"""
查看授权的资产系统用户的数据结构,这个和AssetSerializer不同,字段少
"""
class
Meta
:
model
=
SystemUser
fields
=
(
'id'
,
'name'
,
'username'
,
'priority'
,
'protocol'
,
'comment'
,)
class
SystemUserUpdateAssetsSerializer
(
serializers
.
ModelSerializer
):
"""
"""
系统用户更新关联资产的数据结构
管理用户更新关联到的集群
"""
"""
assets
=
serializers
.
PrimaryKeyRelatedField
(
many
=
True
,
queryset
=
Asset
.
objects
.
all
())
clusters
=
serializers
.
PrimaryKeyRelatedField
(
many
=
True
,
queryset
=
Cluster
.
objects
.
all
())
class
Meta
:
class
Meta
:
model
=
System
User
model
=
Admin
User
fields
=
[
'id'
,
'
asset
s'
]
fields
=
[
'id'
,
'
cluster
s'
]
class
SystemUserUpdateAssetGroup
Serializer
(
serializers
.
ModelSerializer
):
class
AssetSystemUser
Serializer
(
serializers
.
ModelSerializer
):
"""
"""
系统用户更新资产组的api
查看授权的资产系统用户的数据结构,这个和AssetSerializer不同,字段少
"""
"""
asset_groups
=
serializers
.
PrimaryKeyRelatedField
(
many
=
True
,
queryset
=
AssetGroup
.
objects
.
all
())
class
Meta
:
class
Meta
:
model
=
SystemUser
model
=
SystemUser
fields
=
[
'id'
,
'asset_groups'
]
fields
=
(
'id'
,
'name'
,
'username'
,
'priority'
,
'protocol'
,
'comment'
,)
class
SystemUserSimpleSerializer
(
serializers
.
ModelSerializer
):
class
SystemUserSimpleSerializer
(
serializers
.
ModelSerializer
):
...
...
apps/assets/templates/assets/admin_user_detail.html
View file @
b4e1ac19
...
@@ -102,12 +102,12 @@
...
@@ -102,12 +102,12 @@
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Using this as cluster admin user' %}
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Using this as cluster admin user' %}
</div>
</div>
<div
class=
"panel-body"
>
<div
class=
"panel-body"
>
<table
class=
"table group_edit"
id=
"
add-asset2group
"
>
<table
class=
"table group_edit"
id=
"
table-clusters
"
>
<tbody>
<tbody>
<form>
<form>
<tr>
<tr>
<td
colspan=
"2"
class=
"no-borders"
>
<td
colspan=
"2"
class=
"no-borders"
>
<select
data-placeholder=
"{% trans 'Select cluster' %}"
class=
"select2"
style=
"width: 100%"
multiple=
""
tabindex=
"4"
>
<select
data-placeholder=
"{% trans 'Select cluster' %}"
id=
"cluster_selected"
class=
"select2"
style=
"width: 100%"
multiple=
""
tabindex=
"4"
>
{% for cluster in cluster_remain %}
{% for cluster in cluster_remain %}
<option
value=
"{{ cluster.id }}"
id=
"opt_{{ cluster.id }}"
>
{{ cluster.name }}
</option>
<option
value=
"{{ cluster.id }}"
id=
"opt_{{ cluster.id }}"
>
{{ cluster.name }}
</option>
{% endfor %}
{% endfor %}
...
@@ -116,17 +116,14 @@
...
@@ -116,17 +116,14 @@
</tr>
</tr>
<tr>
<tr>
<td
colspan=
"2"
class=
"no-borders"
>
<td
colspan=
"2"
class=
"no-borders"
>
<button
type=
"button"
class=
"btn btn-info btn-sm"
id=
"btn
_add_user_group
"
>
{% trans 'Confirm' %}
</button>
<button
type=
"button"
class=
"btn btn-info btn-sm"
id=
"btn
-add-cluster
"
>
{% trans 'Confirm' %}
</button>
</td>
</td>
</tr>
</tr>
</form>
</form>
{% for cluster in admin_user.cluster_set.all %}
{% for cluster in admin_user.cluster_set.all %}
<tr>
<tr>
<td
><b
class=
"bdg_group"
data-gid=
{{
cluster
.
id
}}
>
{{ cluster.name }}
</b></td>
<td
><b
class=
"bdg_cluster"
data-gid=
{{
cluster
.
id
}}
>
{{ cluster.name }}
</b></td>
<td>
<button
class=
"btn btn-danger pull-right btn-xs btn-leave-group"
type=
"button"
><i
class=
"fa fa-minus"
></i></button>
</td>
</tr>
</tr>
{% endfor %}
{% endfor %}
</tbody>
</tbody>
...
@@ -161,74 +158,48 @@ Array.prototype.unique = function(){
...
@@ -161,74 +158,48 @@ Array.prototype.unique = function(){
}
}
return
res
;
return
res
;
};
};
function
objectRemove
(
obj
,
name
,
url
,
data
)
{
function
doRemove
()
{
function
bindToCluster
(
clusters
)
{
var
body
=
data
;
var
the_url
=
"{% url 'api-assets:admin-user-add-clusters' pk=admin_user.id %}"
;
var
success
=
function
()
{
var
body
=
{
swal
(
'Remove!'
,
"[ "
+
name
+
"]"
+
" has been deleted "
,
"success"
);
clusters
:
clusters
$
(
obj
).
parent
().
parent
().
remove
();
};
};
var
success
=
function
(
data
)
{
var
fail
=
function
()
{
// remove all the selected groups from select > option and rendered ul element;
swal
(
"Failed"
,
"Remove"
+
"[ "
+
name
+
" ]"
+
"failed"
,
"error"
);
$
(
'.select2-selection__rendered'
).
empty
();
};
$
(
'#cluster_selected'
).
val
(
''
);
APIUpdateAttr
({
$
.
map
(
jumpserver
.
cluster_selected
,
function
(
cluster_name
,
index
)
{
url
:
url
,
console
.
log
(
index
);
body
:
JSON
.
stringify
(
body
),
$
(
'#opt_'
+
index
).
remove
();
method
:
'PATCH'
,
// change tr html of user groups.
success
:
success
,
$
(
'#table-clusters tbody'
).
append
(
error
:
fail
'<tr>'
+
'<td><b class="bdg_cluster" data-gid="'
+
index
+
'">'
+
cluster_name
+
'</b></td>'
+
'</tr>'
)
});
});
}
$
.
map
(
jumpserver
.
cluster_selected
,
function
(
value
,
index
)
{
swal
({
$
(
'#opt_'
+
index
).
remove
();
title
:
'Are you sure remove ?'
,
});
text
:
" ["
+
name
+
"] "
,
// clear jumpserver.groups_selected
type
:
"warning"
,
jumpserver
.
cluster_selected
=
{};
showCancelButton
:
true
,
};
cancelButtonText
:
'Cancel'
,
APIUpdateAttr
({
confirmButtonColor
:
"#DD6B55"
,
url
:
the_url
,
confirmButtonText
:
'Confirm'
,
body
:
JSON
.
stringify
(
body
),
closeOnConfirm
:
false
success
:
success
},
function
()
{
doRemove
()
});
});
}
}
function
adminUserDelete
(
name
,
url
)
{
jumpserver
.
cluster_selected
=
{};
function
doDelete
()
{
var
body
=
{};
var
success
=
function
()
{
swal
(
'Deleted!'
,
"[ "
+
name
+
"]"
+
" has been deleted "
,
"success"
);
window
.
location
.
href
=
"{% url 'assets:cluster-list' %}"
;
};
var
fail
=
function
()
{
swal
(
"Failed"
,
"Delete"
+
"[ "
+
name
+
" ]"
+
"failed"
,
"error"
);
};
APIUpdateAttr
({
url
:
url
,
body
:
JSON
.
stringify
(
body
),
method
:
'DELETE'
,
success
:
success
,
error
:
fail
});
}
swal
({
title
:
'Are you sure delete ?'
,
text
:
" ["
+
name
+
"] "
,
type
:
"warning"
,
showCancelButton
:
true
,
cancelButtonText
:
'Cancel'
,
confirmButtonColor
:
"#DD6B55"
,
confirmButtonText
:
'Confirm'
,
closeOnConfirm
:
false
},
function
()
{
doDelete
()
});
}
jumpserver
.
assets_selected
=
{};
jumpserver
.
asset_groups_selected
=
{};
$
(
document
).
ready
(
function
()
{
$
(
document
).
ready
(
function
()
{
$
(
'.select2'
).
select2
();
$
(
'.select2'
).
select2
().
on
(
'select2:select'
,
function
(
evt
)
{
var
data
=
evt
.
params
.
data
;
jumpserver
.
cluster_selected
[
data
.
id
]
=
data
.
text
;
}).
on
(
'select2:unselect'
,
function
(
evt
)
{
var
data
=
evt
.
params
.
data
;
delete
jumpserver
.
cluster_selected
[
data
.
id
]
});
})
})
.
on
(
'click'
,
'.btn-delete-admin-user'
,
function
()
{
.
on
(
'click'
,
'.btn-delete-admin-user'
,
function
()
{
var
$this
=
$
(
this
);
var
$this
=
$
(
this
);
...
@@ -238,5 +209,15 @@ $(document).ready(function () {
...
@@ -238,5 +209,15 @@ $(document).ready(function () {
var
redirect_url
=
"{% url 'assets:admin-user-list' %}"
;
var
redirect_url
=
"{% url 'assets:admin-user-list' %}"
;
objectDelete
(
$this
,
name
,
the_url
,
redirect_url
);
objectDelete
(
$this
,
name
,
the_url
,
redirect_url
);
})
})
.
on
(
'click'
,
'#btn-add-cluster'
,
function
()
{
if
(
Object
.
keys
(
jumpserver
.
cluster_selected
).
length
===
0
)
{
return
false
;
}
var
clusters
=
[];
$
.
map
(
jumpserver
.
cluster_selected
,
function
(
value
,
index
)
{
clusters
.
push
(
index
);
});
bindToCluster
(
clusters
)
})
</script>
</script>
{% endblock %}
{% endblock %}
apps/assets/templates/assets/asset_detail.html
View file @
b4e1ac19
...
@@ -247,7 +247,6 @@
...
@@ -247,7 +247,6 @@
{% block custom_foot_js %}
{% block custom_foot_js %}
<script>
<script>
jumpserver
.
groups_selected
=
{};
jumpserver
.
groups_selected
=
{};
jumpserver
.
system_user_selected
=
{};
function
updateAssetGroups
(
groups
)
{
function
updateAssetGroups
(
groups
)
{
var
the_url
=
"{% url 'api-assets:asset-update-group' pk=asset.id %}"
;
var
the_url
=
"{% url 'api-assets:asset-update-group' pk=asset.id %}"
;
var
body
=
{
var
body
=
{
...
...
apps/assets/templates/assets/asset_group_detail.html
View file @
b4e1ac19
...
@@ -94,39 +94,34 @@
...
@@ -94,39 +94,34 @@
{% block custom_foot_js %}
{% block custom_foot_js %}
<script>
<script>
jumpserver
.
assets_selected
=
{};
jumpserver
.
assets_selected
=
{};
function
updateGroup
Assets
(
assets
)
{
function
add
Assets
(
assets
)
{
var
the_url
=
"{}"
;
var
the_url
=
"{
% url 'api-assets:group-add-assets' pk=asset_group.id %
}"
;
var
body
=
{
var
body
=
{
assets
:
Object
.
assign
([],
assets
)
assets
:
assets
};
};
var
$data_table
=
$
(
"#asset_list_table"
).
DataTable
();
var
$data_table
=
$
(
"#asset_list_table"
).
DataTable
();
var
success
=
function
(
data
)
{
var
success
=
function
(
data
)
{
$
(
'.select2-selection__rendered'
).
empty
();
$
(
'.select2-selection__rendered'
).
empty
();
$
.
map
(
jumpserver
.
assets_selected
,
function
(
asset_ip
,
index
)
{
$data_table
.
ajax
.
reload
();
$
(
'#opt_'
+
index
).
remove
();
jumpserver
.
groups_selected
=
{};
$data_table
.
ajax
.
reload
();
});
jumpserver
.
groups_selected
=
{};
};
};
console
.
log
(
body
);
APIUpdateAttr
({
//APIUpdateAttr({
url
:
the_url
,
// url: the_url,
body
:
JSON
.
stringify
(
body
),
// body: JSON.stringify(body),
method
:
'PUT'
,
// method: 'PUT',
success
:
success
// success: success
});
//});
}
}
function
leaveGroup
(
obj
,
name
,
url
,
data
)
{
function
leaveGroup
(
obj
,
name
,
url
,
data
)
{
function
doDelete
()
{
var
body
=
data
;
var
body
=
data
;
var
success
=
function
()
{
var
success
=
function
()
{
swal
(
'Deleted!'
,
"[ "
+
name
+
"]"
+
" has been deleted "
,
"success"
);
$
(
obj
).
parent
().
parent
().
remove
();
$
(
obj
).
parent
().
parent
().
remove
();
};
};
var
fail
=
function
()
{
var
fail
=
function
()
{
swal
(
"Failed"
,
"Delete"
+
"[ "
+
name
+
" ]"
+
"failed"
,
"error"
);
console
.
log
(
"Remove failed"
)
};
};
APIUpdateAttr
({
APIUpdateAttr
({
url
:
url
,
url
:
url
,
...
@@ -135,19 +130,6 @@ function leaveGroup(obj, name, url, data) {
...
@@ -135,19 +130,6 @@ function leaveGroup(obj, name, url, data) {
success
:
success
,
success
:
success
,
error
:
fail
error
:
fail
});
});
}
swal
({
title
:
'Are you sure delete ?'
,
text
:
" ["
+
name
+
"] "
,
type
:
"warning"
,
showCancelButton
:
true
,
cancelButtonText
:
'Cancel'
,
confirmButtonColor
:
"#DD6B55"
,
confirmButtonText
:
'Confirm'
,
closeOnConfirm
:
false
},
function
()
{
doDelete
()
});
}
}
Array
.
prototype
.
remove
=
function
(
val
)
{
Array
.
prototype
.
remove
=
function
(
val
)
{
...
@@ -188,13 +170,13 @@ function initTable() {
...
@@ -188,13 +170,13 @@ function initTable() {
}},
}},
{
targets
:
5
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
{
targets
:
5
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
update_btn
=
'<a href="{% url "assets:asset-update" pk=DEFAULT_PK %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'
.
replace
(
'{{ DEFAULT_PK }}'
,
rowData
.
id
);
var
update_btn
=
'<a href="{% url "assets:asset-update" pk=DEFAULT_PK %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'
.
replace
(
'{{ DEFAULT_PK }}'
,
rowData
.
id
);
var
del_btn
=
'<a class="btn btn-xs btn-danger m-l-xs btn
_asset_delete
" data-aid="{{ DEFAULT_PK }}">{% trans "Remove" %}</a>'
.
replace
(
'{{ DEFAULT_PK }}'
,
rowData
.
id
);
var
del_btn
=
'<a class="btn btn-xs btn-danger m-l-xs btn
-leave-group
" data-aid="{{ DEFAULT_PK }}">{% trans "Remove" %}</a>'
.
replace
(
'{{ DEFAULT_PK }}'
,
rowData
.
id
);
$
(
td
).
html
(
update_btn
+
del_btn
)
$
(
td
).
html
(
update_btn
+
del_btn
)
}}
}}
],
],
ajax_url
:
'{% url "api-assets:asset-list" %}?asset_group_id={{ asset_group.id }}'
,
ajax_url
:
'{% url "api-assets:asset-list" %}?asset_group_id={{ asset_group.id }}'
,
columns
:
[{
data
:
"hostname"
},
{
data
:
"ip"
},
{
data
:
"port"
},
columns
:
[{
data
:
"hostname"
},
{
data
:
"ip"
},
{
data
:
"port"
},
{
data
:
"
type"
},
{
data
:
"is_a
ctive"
},
{
data
:
"id"
}],
{
data
:
"
get_type_display"
},
{
data
:
"is_conne
ctive"
},
{
data
:
"id"
}],
op_html
:
$
(
'#actions'
).
html
()
op_html
:
$
(
'#actions'
).
html
()
};
};
jumpserver
.
initDataTable
(
options
);
jumpserver
.
initDataTable
(
options
);
...
@@ -208,7 +190,6 @@ $(document).ready(function () {
...
@@ -208,7 +190,6 @@ $(document).ready(function () {
.
on
(
'select2:select'
,
function
(
evt
)
{
.
on
(
'select2:select'
,
function
(
evt
)
{
var
data
=
evt
.
params
.
data
;
var
data
=
evt
.
params
.
data
;
jumpserver
.
assets_selected
[
data
.
id
]
=
data
.
text
;
jumpserver
.
assets_selected
[
data
.
id
]
=
data
.
text
;
console
.
log
(
jumpserver
.
assets_selected
)
})
})
.
on
(
'select2:unselect'
,
function
(
evt
)
{
.
on
(
'select2:unselect'
,
function
(
evt
)
{
var
data
=
evt
.
params
.
data
;
var
data
=
evt
.
params
.
data
;
...
@@ -223,22 +204,26 @@ $(document).ready(function () {
...
@@ -223,22 +204,26 @@ $(document).ready(function () {
if
(
Object
.
keys
(
jumpserver
.
assets_selected
).
length
===
0
)
{
if
(
Object
.
keys
(
jumpserver
.
assets_selected
).
length
===
0
)
{
return
false
;
return
false
;
}
}
var
assets_id
=
[];
$
.
map
(
jumpserver
.
assets_selected
,
function
(
value
,
index
)
{
assets_id
.
push
(
index
);
});
updateGroupAssets
(
jumpserver
.
assets_selected
);
addAssets
(
assets_id
);
})
})
.
on
(
'click'
,
'.btn-leave-group'
,
function
()
{
.
on
(
'click'
,
'.btn-leave-group'
,
function
()
{
var
$this
=
$
(
this
);
var
$this
=
$
(
this
);
var
the_url
=
"{% url 'api-assets:
asset-groups-update
' pk=asset_group.id %}"
;
var
the_url
=
"{% url 'api-assets:
group-update-assets
' pk=asset_group.id %}"
;
var
name
=
$
(
this
).
closest
(
"tr"
).
find
(
":nth-child(1) > a"
).
html
();
var
name
=
$
(
this
).
closest
(
"tr"
).
find
(
":nth-child(1) > a"
).
html
();
var
assets
=
[];
var
assets
=
[];
$
(
'#asset_list_table > tbody > tr'
).
map
(
function
()
{
$
(
'#asset_list_table > tbody > tr'
).
map
(
function
()
{
assets
.
push
(
parseInt
(
$
(
this
).
closest
(
"tr"
).
find
(
":nth-child(1) > a"
).
attr
(
"data-aid"
)
))
assets
.
push
(
$
(
this
).
closest
(
"tr"
).
find
(
":nth-child(1) > a"
).
attr
(
"data-aid"
))
});
});
var
delete_asset_id
=
$
(
this
).
data
(
'aid'
);
var
delete_asset_id
=
$
(
this
).
data
(
'aid'
);
assets
.
remove
(
delete_asset_id
);
assets
.
remove
(
delete_asset_id
);
console
.
log
(
assets
);
var
data
=
{
"assets"
:
assets
};
var
data
=
{
"assets"
:
assets
};
leaveGroup
(
$this
,
name
,
the_url
,
data
);
leaveGroup
(
$this
,
name
,
the_url
,
data
);
})
})
...
...
apps/assets/templates/assets/asset_group_list.html
View file @
b4e1ac19
...
@@ -21,19 +21,6 @@
...
@@ -21,19 +21,6 @@
<tbody>
<tbody>
</tbody>
</tbody>
</table>
</table>
<div
id=
"actions"
class=
"hide"
>
<div
class=
"input-group"
>
<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>
</select>
<div
class=
"input-group-btn pull-left"
style=
"padding-left: 5px;"
>
<button
id=
'btn_bulk_update'
style=
"height: 32px;"
class=
"btn btn-sm btn-primary"
>
{% trans 'Submit' %}
</button>
</div>
</div>
</div>
{% include 'assets/_asset_group_bulk_update_modal.html' %}
{% include 'assets/_asset_group_bulk_update_modal.html' %}
{% endblock %}
{% endblock %}
{% block content_bottom_left %}{% endblock %}
{% block content_bottom_left %}{% endblock %}
...
...
apps/assets/templates/assets/cluster_assets.html
View file @
b4e1ac19
This diff is collapsed.
Click to expand it.
apps/assets/templates/assets/cluster_list.html
View file @
b4e1ac19
...
@@ -27,18 +27,6 @@
...
@@ -27,18 +27,6 @@
<tbody>
<tbody>
</tbody>
</tbody>
</table>
</table>
<div
id=
"actions"
class=
"hide"
>
<div
class=
"input-group"
>
<select
class=
"form-control m-b"
style=
"width: auto"
id=
"slct_bulk_update"
>
<option
value=
"delete"
>
{% trans 'Delete selected' %}
</option>
</select>
<div
class=
"input-group-btn pull-left"
style=
"padding-left: 5px;"
>
<button
id=
'btn_bulk_update'
style=
"height: 32px;"
class=
"btn btn-sm btn-primary"
>
{% trans 'Submit' %}
</button>
</div>
</div>
</div>
{% endblock %}
{% endblock %}
{% block content_bottom_left %}{% endblock %}
{% block content_bottom_left %}{% endblock %}
{% block custom_foot_js %}
{% block custom_foot_js %}
...
...
apps/assets/urls/api_urls.py
View file @
b4e1ac19
...
@@ -19,37 +19,22 @@ urlpatterns = [
...
@@ -19,37 +19,22 @@ urlpatterns = [
name
=
'system-user-auth-info'
),
name
=
'system-user-auth-info'
),
url
(
r'^v1/assets/(?P<pk>[0-9a-zA-Z\-]{36})/groups/$'
,
url
(
r'^v1/assets/(?P<pk>[0-9a-zA-Z\-]{36})/groups/$'
,
api
.
AssetUpdateGroupApi
.
as_view
(),
name
=
'asset-update-group'
),
api
.
AssetUpdateGroupApi
.
as_view
(),
name
=
'asset-update-group'
),
url
(
r'^v1/assets/(?P<pk>[0-9a-zA-Z\-]{36})/refresh/$'
,
url
(
r'^v1/assets/(?P<pk>[0-9a-zA-Z\-]{36})/refresh/$'
,
api
.
AssetRefreshHardwareView
.
as_view
(),
name
=
'asset-refresh'
),
api
.
AssetRefreshHardwareView
.
as_view
(),
name
=
'asset-refresh'
),
url
(
r'^v1/assets/(?P<pk>[0-9a-zA-Z\-]{36})/admin-user-test/$'
,
url
(
r'^v1/assets/(?P<pk>[0-9a-zA-Z\-]{36})/admin-user-test/$'
,
api
.
AssetAdminUserTestView
.
as_view
(),
name
=
'asset-admin-user-test'
),
api
.
AssetAdminUserTestView
.
as_view
(),
name
=
'asset-admin-user-test'
),
url
(
r'^v1/assets/(?P<pk>[0-9a-zA-Z\-]{36})/system-users/$'
,
api
.
SystemUserUpdateApi
.
as_view
(),
name
=
'asset-update-system-users'
),
url
(
r'^v1/groups/(?P<pk>[0-9a-zA-Z\-]{36})/push-system-user/$'
,
api
.
AssetGroupPushSystemUserView
.
as_view
(),
name
=
'asset-group-push-system-user'
),
# update the system users, which add and delete the asset to the system user
url
(
r'^v1/system-user/(?P<pk>[0-9a-zA-Z\-]{36})/assets/$'
,
api
.
SystemUserUpdateAssetsApi
.
as_view
(),
name
=
'systemuser-update-assets'
),
url
(
r'^v1/system-user/(?P<pk>[0-9a-zA-Z\-]{36})/groups/$'
,
api
.
SystemUserUpdateAssetGroupApi
.
as_view
(),
name
=
'systemuser-update-assetgroups'
),
# update the asset group, which add or delete the asset to the group
# update the asset group, which add or delete the asset to the group
url
(
r'^v1/groups/(?P<pk>[0-9a-zA-Z\-]{36})/assets/$'
,
url
(
r'^v1/groups/(?P<pk>[0-9a-zA-Z\-]{36})/assets/$'
,
api
.
AssetGroupUpdateApi
.
as_view
(),
name
=
'asset-groups-update'
),
api
.
GroupUpdateAssetsApi
.
as_view
(),
name
=
'group-update-assets'
),
url
(
r'^v1/groups/(?P<pk>[0-9a-zA-Z\-]{36})/assets/add/$'
,
# update the asset group, and add or delete the system_user to the group
api
.
GroupAddAssetsApi
.
as_view
(),
name
=
'group-add-assets'
),
url
(
r'^v1/groups/(?P<pk>[0-9a-zA-Z\-]{36})/system-users/$'
,
api
.
AssetGroupUpdateSystemUserApi
.
as_view
(),
name
=
'asset-groups-update-systemusers'
),
# update the Cluster, and add or delete the assets to the Cluster
# update the Cluster, and add or delete the assets to the Cluster
url
(
r'^v1/cluster/(?P<pk>[0-9a-zA-Z\-]{36})/assets/$'
,
url
(
r'^v1/cluster/(?P<pk>[0-9a-zA-Z\-]{36})/assets/$'
,
api
.
ClusterUpdateAssetsApi
.
as_view
(),
name
=
'cluster-update-assets'
),
api
.
ClusterUpdateAssetsApi
.
as_view
(),
name
=
'cluster-update-assets'
),
url
(
r'^v1/cluster/(?P<pk>[0-9a-zA-Z\-]{36})/assets/$'
,
api
.
ClusterAddAssetsApi
.
as_view
(),
name
=
'cluster-add-assets'
),
url
(
r'^v1/admin-user/(?P<pk>[0-9a-zA-Z\-]{36})/clusters/$'
,
api
.
AdminUserAddClustersApi
.
as_view
(),
name
=
'admin-user-add-clusters'
),
]
]
urlpatterns
+=
router
.
urls
urlpatterns
+=
router
.
urls
...
...
apps/assets/views/asset.py
View file @
b4e1ac19
...
@@ -24,7 +24,7 @@ from django.shortcuts import redirect
...
@@ -24,7 +24,7 @@ from django.shortcuts import redirect
from
common.mixins
import
JSONResponseMixin
from
common.mixins
import
JSONResponseMixin
from
common.utils
import
get_object_or_none
,
get_logger
from
common.utils
import
get_object_or_none
,
get_logger
,
is_uuid
from
..
import
forms
from
..
import
forms
from
..models
import
Asset
,
AssetGroup
,
AdminUser
,
Cluster
,
SystemUser
from
..models
import
Asset
,
AssetGroup
,
AdminUser
,
Cluster
,
SystemUser
from
..hands
import
AdminUserRequiredMixin
from
..hands
import
AdminUserRequiredMixin
...
@@ -112,16 +112,18 @@ class AssetBulkUpdateView(AdminUserRequiredMixin, ListView):
...
@@ -112,16 +112,18 @@ class AssetBulkUpdateView(AdminUserRequiredMixin, ListView):
form_class
=
forms
.
AssetBulkUpdateForm
form_class
=
forms
.
AssetBulkUpdateForm
template_name
=
'assets/asset_bulk_update.html'
template_name
=
'assets/asset_bulk_update.html'
success_url
=
reverse_lazy
(
'assets:asset-list'
)
success_url
=
reverse_lazy
(
'assets:asset-list'
)
id_list
=
None
form
=
None
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
assets_id
=
self
.
request
.
GET
.
get
(
'assets_id'
,
''
)
assets_id
=
self
.
request
.
GET
.
get
(
'assets_id'
,
''
)
self
.
assets_id_list
=
[
int
(
i
)
for
i
in
assets_id
.
split
(
','
)
if
i
.
isdigit
(
)]
self
.
id_list
=
[
i
for
i
in
assets_id
.
split
(
','
)]
if
kwargs
.
get
(
'form'
):
if
kwargs
.
get
(
'form'
):
self
.
form
=
kwargs
[
'form'
]
self
.
form
=
kwargs
[
'form'
]
elif
assets_id
:
elif
assets_id
:
self
.
form
=
self
.
form_class
(
self
.
form
=
self
.
form_class
(
initial
=
{
'assets'
:
self
.
assets_
id_list
}
initial
=
{
'assets'
:
self
.
id_list
}
)
)
else
:
else
:
self
.
form
=
self
.
form_class
()
self
.
form
=
self
.
form_class
()
...
@@ -136,13 +138,11 @@ class AssetBulkUpdateView(AdminUserRequiredMixin, ListView):
...
@@ -136,13 +138,11 @@ class AssetBulkUpdateView(AdminUserRequiredMixin, ListView):
return
self
.
get
(
request
,
form
=
form
,
*
args
,
**
kwargs
)
return
self
.
get
(
request
,
form
=
form
,
*
args
,
**
kwargs
)
def
get_context_data
(
self
,
**
kwargs
):
def
get_context_data
(
self
,
**
kwargs
):
# assets_list = Asset.objects.filter(id__in=self.assets_id_list)
context
=
{
context
=
{
'app'
:
'Assets'
,
'app'
:
'Assets'
,
'action'
:
'Bulk update asset'
,
'action'
:
'Bulk update asset'
,
'form'
:
self
.
form
,
'form'
:
self
.
form
,
'assets_selected'
:
self
.
assets_id_list
,
'assets_selected'
:
self
.
id_list
,
'assets'
:
Asset
.
objects
.
all
(),
}
}
kwargs
.
update
(
context
)
kwargs
.
update
(
context
)
return
super
()
.
get_context_data
(
**
kwargs
)
return
super
()
.
get_context_data
(
**
kwargs
)
...
@@ -270,13 +270,6 @@ class BulkImportAssetView(AdminUserRequiredMixin, JSONResponseMixin, FormView):
...
@@ -270,13 +270,6 @@ class BulkImportAssetView(AdminUserRequiredMixin, JSONResponseMixin, FormView):
asset_dict
=
dict
(
zip
(
attr
,
row
))
asset_dict
=
dict
(
zip
(
attr
,
row
))
id_
=
asset_dict
.
pop
(
'id'
,
0
)
id_
=
asset_dict
.
pop
(
'id'
,
0
)
try
:
id_
=
int
(
id_
)
except
ValueError
:
id_
=
0
asset
=
get_object_or_none
(
Asset
,
id
=
id_
)
for
k
,
v
in
asset_dict
.
items
():
for
k
,
v
in
asset_dict
.
items
():
if
k
==
'cluster'
:
if
k
==
'cluster'
:
v
=
get_object_or_none
(
Cluster
,
name
=
v
)
v
=
get_object_or_none
(
Cluster
,
name
=
v
)
...
@@ -296,6 +289,7 @@ class BulkImportAssetView(AdminUserRequiredMixin, JSONResponseMixin, FormView):
...
@@ -296,6 +289,7 @@ class BulkImportAssetView(AdminUserRequiredMixin, JSONResponseMixin, FormView):
continue
continue
asset_dict
[
k
]
=
v
asset_dict
[
k
]
=
v
asset
=
get_object_or_none
(
Asset
,
id
=
id_
)
if
is_uuid
(
id_
)
else
None
if
not
asset
:
if
not
asset
:
try
:
try
:
groups
=
asset_dict
.
pop
(
'groups'
)
groups
=
asset_dict
.
pop
(
'groups'
)
...
...
apps/common/utils.py
View file @
b4e1ac19
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
#
#
import
re
from
collections
import
OrderedDict
from
collections
import
OrderedDict
from
six
import
string_types
from
six
import
string_types
import
base64
import
base64
...
@@ -29,6 +29,7 @@ from django.utils import timezone
...
@@ -29,6 +29,7 @@ from django.utils import timezone
from
.compat
import
to_bytes
,
to_string
from
.compat
import
to_bytes
,
to_string
SECRET_KEY
=
settings
.
SECRET_KEY
SECRET_KEY
=
settings
.
SECRET_KEY
UUID_PATTERN
=
re
.
compile
(
r'[0-9a-zA-Z\-]{36}'
)
def
reverse
(
view_name
,
urlconf
=
None
,
args
=
None
,
kwargs
=
None
,
def
reverse
(
view_name
,
urlconf
=
None
,
args
=
None
,
kwargs
=
None
,
...
@@ -382,4 +383,11 @@ def get_short_uuid_str():
...
@@ -382,4 +383,11 @@ def get_short_uuid_str():
return
str
(
uuid
.
uuid4
())
.
split
(
'-'
)[
-
1
]
return
str
(
uuid
.
uuid4
())
.
split
(
'-'
)[
-
1
]
def
is_uuid
(
s
):
if
UUID_PATTERN
.
match
(
s
):
return
True
else
:
return
False
signer
=
Signer
()
signer
=
Signer
()
apps/locale/zh/LC_MESSAGES/django.mo
View file @
b4e1ac19
No preview for this file type
apps/locale/zh/LC_MESSAGES/django.po
View file @
b4e1ac19
...
@@ -209,7 +209,7 @@ msgstr "资产组"
...
@@ -209,7 +209,7 @@ msgstr "资产组"
#: assets/models/asset.py:51 assets/models/user.py:198
#: assets/models/asset.py:51 assets/models/user.py:198
#: assets/templates/assets/asset_detail.html:85 templates/_nav.html:24
#: assets/templates/assets/asset_detail.html:85 templates/_nav.html:24
msgid "Cluster"
msgid "Cluster"
msgstr "
机房
"
msgstr "
集群
"
#: assets/models/asset.py:52 assets/templates/assets/asset_detail.html:129
#: assets/models/asset.py:52 assets/templates/assets/asset_detail.html:129
msgid "Is active"
msgid "Is active"
...
...
apps/ops/utils.py
View file @
b4e1ac19
...
@@ -11,14 +11,6 @@ from .ansible.exceptions import AnsibleError
...
@@ -11,14 +11,6 @@ from .ansible.exceptions import AnsibleError
from
.models
import
AdHocRunHistory
,
Task
,
AdHoc
from
.models
import
AdHocRunHistory
,
Task
,
AdHoc
logger
=
get_logger
(
__file__
)
logger
=
get_logger
(
__file__
)
UUID_PATTERN
=
re
.
compile
(
r'[0-9a-zA-Z\-]{36}'
)
def
is_uuid
(
s
):
if
UUID_PATTERN
.
match
(
s
):
return
True
else
:
return
False
def
record_adhoc
(
func
):
def
record_adhoc
(
func
):
...
@@ -112,47 +104,6 @@ def run_adhoc(hostname_list, pattern, tasks, name=None,
...
@@ -112,47 +104,6 @@ def run_adhoc(hostname_list, pattern, tasks, name=None,
return
runner
.
run
(
tasks
,
pattern
,
play_name
=
name
)
return
runner
.
run
(
tasks
,
pattern
,
play_name
=
name
)
# def create_and_run_adhoc(hostname_list, pattern, tasks, name=None,
# run_as_admin=False, run_as=None, become_info=None):
# if name is None:
# name = "Adhoc-task-{}-{}".format(
# get_short_uuid_str(),
# timezone.now().strftime("%Y-%m-%d %H:%M:%S"),
# )
# task = Task(name=name)
# task.save()
# adhoc = AdHoc(
# task=task, pattern=pattern, name=name,
# run_as_admin=run_as_admin, run_as=run_as
# )
# adhoc.hosts = hostname_list
# adhoc.tasks = tasks
# adhoc.become = become_info
# adhoc.save()
# def get_task_by_name(name):
# task = get_object_or_none(Task, name=name)
# return task
# def create_task(name, created_by=""):
# return Task.objects.create(name=name, created_by=created_by)
#
#
# def create_adhoc(task, hosts, tasks, pattern='all', options=None,
# run_as_admin=False, run_as="",
# become_info=None, created_by=""):
# adhoc = AdHoc(task=task, pattern=pattern, run_as_admin=run_as_admin,
# run_as=run_as, created_by=created_by)
# adhoc.hosts = hosts
# adhoc.tasks = tasks
# adhoc.options = options
# adhoc.become = become_info
# adhoc.save()
# return adhoc
def
create_or_update_task
(
def
create_or_update_task
(
task_name
,
hosts
,
tasks
,
pattern
=
'all'
,
options
=
None
,
task_name
,
hosts
,
tasks
,
pattern
=
'all'
,
options
=
None
,
run_as_admin
=
False
,
run_as
=
""
,
become_info
=
None
,
run_as_admin
=
False
,
run_as
=
""
,
become_info
=
None
,
...
...
apps/users/templates/users/user_group_detail.html
View file @
b4e1ac19
...
@@ -181,10 +181,9 @@ $(document).ready(function () {
...
@@ -181,10 +181,9 @@ $(document).ready(function () {
return
$
(
this
).
data
(
'uid'
);
return
$
(
this
).
data
(
'uid'
);
}).
get
();
}).
get
();
$
.
map
(
jumpserver
.
users_selected
,
function
(
value
,
index
)
{
$
.
map
(
jumpserver
.
users_selected
,
function
(
value
,
index
)
{
users
.
push
(
parseInt
(
index
)
);
users
.
push
(
index
);
$
(
'#opt_'
+
index
).
remove
();
$
(
'#opt_'
+
index
).
remove
();
});
});
console
.
log
(
users
);
updateGroupMember
(
users
)
updateGroupMember
(
users
)
}).
on
(
'click'
,
'.btn-delete-user-group'
,
function
()
{
}).
on
(
'click'
,
'.btn-delete-user-group'
,
function
()
{
var
$this
=
$
(
this
);
var
$this
=
$
(
this
);
...
...
apps/users/views/user.py
View file @
b4e1ac19
...
@@ -19,7 +19,6 @@ from django.utils import timezone
...
@@ -19,7 +19,6 @@ from django.utils import timezone
from
django.utils.translation
import
ugettext
as
_
from
django.utils.translation
import
ugettext
as
_
from
django.utils.decorators
import
method_decorator
from
django.utils.decorators
import
method_decorator
from
django.views
import
View
from
django.views
import
View
from
django.views.generic
import
ListView
from
django.views.generic.base
import
TemplateView
from
django.views.generic.base
import
TemplateView
from
django.views.generic.edit
import
(
from
django.views.generic.edit
import
(
CreateView
,
UpdateView
,
FormMixin
,
FormView
CreateView
,
UpdateView
,
FormMixin
,
FormView
...
@@ -33,7 +32,7 @@ from ..models import User, UserGroup
...
@@ -33,7 +32,7 @@ from ..models import User, UserGroup
from
..utils
import
AdminUserRequiredMixin
from
..utils
import
AdminUserRequiredMixin
from
..signals
import
on_user_created
from
..signals
import
on_user_created
from
common.mixins
import
JSONResponseMixin
from
common.mixins
import
JSONResponseMixin
from
common.utils
import
get_logger
,
get_object_or_none
from
common.utils
import
get_logger
,
get_object_or_none
,
is_uuid
__all__
=
[
__all__
=
[
'UserListView'
,
'UserCreateView'
,
'UserDetailView'
,
'UserListView'
,
'UserCreateView'
,
'UserDetailView'
,
...
@@ -92,16 +91,6 @@ class UserUpdateView(AdminUserRequiredMixin, UpdateView):
...
@@ -92,16 +91,6 @@ class UserUpdateView(AdminUserRequiredMixin, UpdateView):
context_object_name
=
'user_object'
context_object_name
=
'user_object'
success_url
=
reverse_lazy
(
'users:user-list'
)
success_url
=
reverse_lazy
(
'users:user-list'
)
# def form_valid(self, form):
# username = self.object.username
# user = form.save(commit=False)
# user.username = username
# user.save()
# password = self.request.POST.get('password', '')
# if password:
# user.set_password(password)
# return super().form_valid(form)
def
get_context_data
(
self
,
**
kwargs
):
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
_
(
'Users'
),
'action'
:
_
(
'Update user'
)}
context
=
{
'app'
:
_
(
'Users'
),
'action'
:
_
(
'Update user'
)}
kwargs
.
update
(
context
)
kwargs
.
update
(
context
)
...
@@ -146,7 +135,6 @@ class UserBulkUpdateView(AdminUserRequiredMixin, TemplateView):
...
@@ -146,7 +135,6 @@ class UserBulkUpdateView(AdminUserRequiredMixin, TemplateView):
'action'
:
'Bulk update asset'
,
'action'
:
'Bulk update asset'
,
'form'
:
self
.
form
,
'form'
:
self
.
form
,
'users_selected'
:
self
.
id_list
,
'users_selected'
:
self
.
id_list
,
'users'
:
User
.
objects
.
all
(),
}
}
kwargs
.
update
(
context
)
kwargs
.
update
(
context
)
return
super
()
.
get_context_data
(
**
kwargs
)
return
super
()
.
get_context_data
(
**
kwargs
)
...
@@ -255,9 +243,7 @@ class UserBulkImportView(AdminUserRequiredMixin, JSONResponseMixin, FormView):
...
@@ -255,9 +243,7 @@ class UserBulkImportView(AdminUserRequiredMixin, JSONResponseMixin, FormView):
if
set
(
row
)
==
{
''
}:
if
set
(
row
)
==
{
''
}:
continue
continue
user_dict
=
dict
(
zip
(
attr
,
row
))
user_dict
=
dict
(
zip
(
attr
,
row
))
print
(
user_dict
)
id_
=
user_dict
.
pop
(
'id'
)
id_
=
user_dict
.
pop
(
'id'
,
0
)
user
=
get_object_or_none
(
User
,
id
=
id_
)
for
k
,
v
in
user_dict
.
items
():
for
k
,
v
in
user_dict
.
items
():
if
k
in
[
'is_active'
]:
if
k
in
[
'is_active'
]:
if
v
.
lower
()
==
'false'
:
if
v
.
lower
()
==
'false'
:
...
@@ -271,6 +257,7 @@ class UserBulkImportView(AdminUserRequiredMixin, JSONResponseMixin, FormView):
...
@@ -271,6 +257,7 @@ class UserBulkImportView(AdminUserRequiredMixin, JSONResponseMixin, FormView):
continue
continue
user_dict
[
k
]
=
v
user_dict
[
k
]
=
v
user
=
get_object_or_none
(
User
,
id
=
id_
)
if
is_uuid
(
id_
)
else
None
if
not
user
:
if
not
user
:
try
:
try
:
groups
=
user_dict
.
pop
(
'groups'
)
groups
=
user_dict
.
pop
(
'groups'
)
...
...
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