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
b0eace6a
Commit
b0eace6a
authored
Dec 19, 2017
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Bugfix] 基本完成assets模块
parent
b4e1ac19
Show whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
438 additions
and
598 deletions
+438
-598
api.py
apps/assets/api.py
+68
-20
forms.py
apps/assets/forms.py
+18
-20
asset.py
apps/assets/models/asset.py
+19
-6
user.py
apps/assets/models/user.py
+17
-1
serializers.py
apps/assets/serializers.py
+16
-22
tasks.py
apps/assets/tasks.py
+7
-14
admin_user_assets.html
apps/assets/templates/assets/admin_user_assets.html
+16
-97
admin_user_detail.html
apps/assets/templates/assets/admin_user_detail.html
+3
-21
asset_detail.html
apps/assets/templates/assets/asset_detail.html
+23
-11
cluster_assets.html
apps/assets/templates/assets/cluster_assets.html
+22
-1
cluster_detail.html
apps/assets/templates/assets/cluster_detail.html
+42
-34
system_user_asset.html
apps/assets/templates/assets/system_user_asset.html
+23
-177
system_user_auth.html
apps/assets/templates/assets/system_user_auth.html
+0
-73
system_user_detail.html
apps/assets/templates/assets/system_user_detail.html
+86
-34
system_user_list.html
apps/assets/templates/assets/system_user_list.html
+38
-16
system_user_update.html
apps/assets/templates/assets/system_user_update.html
+9
-0
api_urls.py
apps/assets/urls/api_urls.py
+9
-5
views_urls.py
apps/assets/urls/views_urls.py
+0
-1
admin_user.py
apps/assets/views/admin_user.py
+2
-2
cluster.py
apps/assets/views/cluster.py
+16
-6
system_user.py
apps/assets/views/system_user.py
+0
-33
user_detail.html
apps/users/templates/users/user_detail.html
+4
-4
No files found.
apps/assets/api.py
View file @
b0eace6a
...
...
@@ -18,14 +18,16 @@ from rest_framework.response import Response
from
rest_framework_bulk
import
BulkModelViewSet
from
rest_framework_bulk
import
ListBulkCreateUpdateDestroyAPIView
from
django.shortcuts
import
get_object_or_404
from
django.db.models
import
Q
from
common.mixins
import
IDInFilterMixin
from
common.utils
import
get_object_or_none
from
.hands
import
IsSuperUser
,
IsValidUser
,
IsSuperUserOrAppUser
,
\
get_user_granted_assets
,
push_users
get_user_granted_assets
from
.models
import
AssetGroup
,
Asset
,
Cluster
,
SystemUser
,
AdminUser
from
.
import
serializers
from
.tasks
import
update_assets_hardware_info
,
test_admin_user_connectability_manual
from
.tasks
import
update_assets_hardware_info
,
test_admin_user_connectability
,
\
test_admin_user_connectability_manual
,
push_system_user_to_cluster_assets
,
\
test_system_user_connectability
class
AssetViewSet
(
IDInFilterMixin
,
BulkModelViewSet
):
...
...
@@ -51,8 +53,9 @@ class AssetViewSet(IDInFilterMixin, BulkModelViewSet):
queryset
=
queryset
.
filter
(
groups__id
=
asset_group_id
)
if
admin_user_id
:
admin_user
=
get_object_or_404
(
AdminUser
,
id
=
admin_user_id
)
assets_direct
=
[
asset
.
id
for
asset
in
admin_user
.
asset_set
.
all
()]
clusters
=
[
cluster
.
id
for
cluster
in
admin_user
.
cluster_set
.
all
()]
queryset
=
queryset
.
filter
(
cluster__id__in
=
clusters
)
queryset
=
queryset
.
filter
(
Q
(
cluster__id__in
=
clusters
)
|
Q
(
id__in
=
assets_direct
)
)
return
queryset
...
...
@@ -65,15 +68,6 @@ class AssetGroupViewSet(IDInFilterMixin, BulkModelViewSet):
permission_classes
=
(
IsSuperUser
,)
class
AssetUpdateGroupApi
(
generics
.
RetrieveUpdateAPIView
):
"""
Asset update it's group api
"""
queryset
=
Asset
.
objects
.
all
()
serializer_class
=
serializers
.
AssetUpdateGroupSerializer
permission_classes
=
(
IsSuperUser
,)
class
GroupUpdateAssetsApi
(
generics
.
RetrieveUpdateAPIView
):
"""
Asset group, update it's asset member
...
...
@@ -117,6 +111,18 @@ class ClusterViewSet(IDInFilterMixin, BulkModelViewSet):
permission_classes
=
(
IsSuperUser
,)
# TOdo
class
ClusterTestAssetsAliveApi
(
generics
.
RetrieveAPIView
):
"""
Test cluster asset can connect using admin user or not
"""
queryset
=
Cluster
.
objects
.
all
()
permission_classes
=
(
IsSuperUser
,)
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
cluster
=
self
.
get_object
()
class
ClusterAddAssetsApi
(
generics
.
UpdateAPIView
):
queryset
=
Cluster
.
objects
.
all
()
serializer_class
=
serializers
.
ClusterUpdateAssetsSerializer
...
...
@@ -162,7 +168,7 @@ class AdminUserAddClustersApi(generics.UpdateAPIView):
return
Response
({
'error'
:
serializer
.
errors
},
status
=
400
)
class
SystemUserViewSet
(
IDInFilterMixin
,
BulkModelViewSet
):
class
SystemUserViewSet
(
BulkModelViewSet
):
"""
System user api set, for add,delete,update,list,retrieve resource
"""
...
...
@@ -170,6 +176,10 @@ class SystemUserViewSet(IDInFilterMixin, BulkModelViewSet):
serializer_class
=
serializers
.
SystemUserSerializer
permission_classes
=
(
IsSuperUserOrAppUser
,)
def
update
(
self
,
request
,
*
args
,
**
kwargs
):
print
(
request
.
data
)
return
super
()
.
update
(
request
,
*
args
,
**
kwargs
)
class
AssetListUpdateApi
(
IDInFilterMixin
,
ListBulkCreateUpdateDestroyAPIView
):
"""
...
...
@@ -199,7 +209,7 @@ class SystemUserAuthInfoApi(generics.RetrieveAPIView):
return
Response
(
data
)
class
AssetRefreshHardware
View
(
generics
.
RetrieveAPIView
):
class
AssetRefreshHardware
Api
(
generics
.
RetrieveAPIView
):
"""
Refresh asset hardware info
"""
...
...
@@ -217,7 +227,7 @@ class AssetRefreshHardwareView(generics.RetrieveAPIView):
return
Response
({
"msg"
:
"ok"
})
class
AssetAdminUserTest
View
(
AssetRefreshHardware
View
):
class
AssetAdminUserTest
Api
(
generics
.
RetrieveAPI
View
):
"""
Test asset admin user connectivity
"""
...
...
@@ -227,9 +237,47 @@ class AssetAdminUserTestView(AssetRefreshHardwareView):
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
asset_id
=
kwargs
.
get
(
'pk'
)
asset
=
get_object_or_404
(
Asset
,
pk
=
asset_id
)
result
=
test_admin_user_connectability_manual
(
asset
)
if
result
:
return
Response
(
'1'
)
ok
,
msg
=
test_admin_user_connectability_manual
(
asset
)
if
ok
:
return
Response
(
{
"msg"
:
"pong"
}
)
else
:
return
Response
(
'0'
,
status
=
502
)
return
Response
({
"error"
:
msg
},
status
=
502
)
class
AdminUserTestConnectiveApi
(
generics
.
RetrieveAPIView
):
"""
Test asset admin user connectivity
"""
queryset
=
AdminUser
.
objects
.
all
()
permission_classes
=
(
IsSuperUser
,)
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
admin_user
=
self
.
get_object
()
test_admin_user_connectability
.
delay
(
admin_user
,
force
=
True
)
return
Response
({
"msg"
:
"Task created"
})
class
SystemUserPushApi
(
generics
.
RetrieveAPIView
):
"""
Push system user to cluster assets api
"""
queryset
=
SystemUser
.
objects
.
all
()
permission_classes
=
(
IsSuperUser
,)
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
system_user
=
self
.
get_object
()
push_system_user_to_cluster_assets
.
delay
(
system_user
,
force
=
True
)
return
Response
({
"msg"
:
"Task created"
})
class
SystemUserTestConnectiveApi
(
generics
.
RetrieveAPIView
):
"""
Push system user to cluster assets api
"""
queryset
=
SystemUser
.
objects
.
all
()
permission_classes
=
(
IsSuperUser
,)
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
system_user
=
self
.
get_object
()
test_system_user_connectability
.
delay
(
system_user
,
force
=
True
)
return
Response
({
"msg"
:
"Task created"
})
apps/assets/forms.py
View file @
b0eace6a
...
...
@@ -273,26 +273,24 @@ class SystemUserForm(forms.ModelForm):
}
class
SystemUserUpdateForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
SystemUser
fields
=
[
'name'
,
'username'
,
'protocol'
,
'priority'
,
'sudo'
,
'comment'
,
'shell'
,
'cluster'
]
widgets
=
{
'name'
:
forms
.
TextInput
(
attrs
=
{
'placeholder'
:
_
(
'Name'
)}),
'username'
:
forms
.
TextInput
(
attrs
=
{
'placeholder'
:
_
(
'Username'
)}),
'cluster'
:
forms
.
SelectMultiple
(
attrs
=
{
'class'
:
'select2'
,
'data-placeholder'
:
_
(
' Select clusters'
)}),
}
help_texts
=
{
'name'
:
'* required'
,
'username'
:
'* required'
,
'cluster'
:
'If auto push checked, then push system user to that cluster assets'
,
'priority'
:
'High level will be using login asset as default, if user was granted more than 2 system user'
,
}
class
SystemUserUpdateForm
(
SystemUserForm
):
def
save
(
self
,
commit
=
True
):
# Because we define custom field, so we need rewrite :method: `save`
password
=
self
.
cleaned_data
.
get
(
'password'
,
None
)
private_key_file
=
self
.
cleaned_data
.
get
(
'private_key_file'
)
system_user
=
super
(
forms
.
ModelForm
,
self
)
.
save
()
if
private_key_file
:
print
(
private_key_file
)
private_key
=
private_key_file
.
read
()
.
strip
()
.
decode
(
'utf-8'
)
public_key
=
ssh_pubkey_gen
(
private_key
=
private_key
)
else
:
private_key
=
public_key
=
None
system_user
.
set_auth
(
password
=
password
,
private_key
=
private_key
,
public_key
=
public_key
)
return
system_user
def
clean_password
(
self
):
return
self
.
cleaned_data
[
'password'
]
class
SystemUserAuthForm
(
forms
.
Form
):
...
...
apps/assets/models/asset.py
View file @
b0eace6a
...
...
@@ -116,6 +116,23 @@ class Asset(models.Model):
else
:
return
False
@property
def
admin_user_avail
(
self
):
if
self
.
admin_user
:
admin_user
=
self
.
admin_user
elif
self
.
cluster
and
self
.
cluster
.
admin_user
:
admin_user
=
self
.
cluster
.
admin_user
else
:
return
None
return
admin_user
@property
def
is_has_private_admin_user
(
self
):
if
self
.
admin_user
:
return
True
else
:
return
False
def
to_json
(
self
):
return
{
'id'
:
self
.
id
,
...
...
@@ -133,12 +150,8 @@ class Asset(models.Model):
Todo: May be move to ops implements it
"""
data
=
self
.
to_json
()
admin_user
=
None
if
self
.
admin_user
:
admin_user
=
self
.
admin_user
elif
self
.
cluster
and
self
.
cluster
.
admin_user
:
admin_user
=
self
.
cluster
.
admin_user
if
admin_user
:
if
self
.
admin_user_avail
:
admin_user
=
self
.
admin_user_avail
data
.
update
({
'username'
:
admin_user
.
username
,
'password'
:
admin_user
.
password
,
...
...
apps/assets/models/user.py
View file @
b0eace6a
...
...
@@ -8,12 +8,14 @@ import uuid
from
hashlib
import
md5
import
sshpubkeys
from
django.core.cache
import
cache
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.conf
import
settings
from
common.utils
import
signer
,
ssh_key_string_to_obj
,
ssh_key_gen
from
.utils
import
private_key_validator
from
..const
import
SYSTEM_USER_CONN_CACHE_KEY
__all__
=
[
'AdminUser'
,
'SystemUser'
,]
...
...
@@ -103,6 +105,7 @@ class AssetUser(models.Model):
update_fields
.
append
(
'_public_key'
)
if
update_fields
:
print
(
update_fields
)
self
.
save
(
update_fields
=
update_fields
)
def
auto_gen_auth
(
self
):
...
...
@@ -195,7 +198,7 @@ class SystemUser(AssetUser):
(
'P'
,
'Password'
),
(
'K'
,
'Public key'
),
)
cluster
=
models
.
ManyToManyField
(
'assets.Cluster'
,
verbose_name
=
_
(
"Cluster"
))
cluster
=
models
.
ManyToManyField
(
'assets.Cluster'
,
null
=
True
,
blank
=
True
,
verbose_name
=
_
(
"Cluster"
))
priority
=
models
.
IntegerField
(
default
=
10
,
verbose_name
=
_
(
"Priority"
))
# Todo: If user granted more priority user, default will be login as the hign
protocol
=
models
.
CharField
(
max_length
=
16
,
choices
=
PROTOCOL_CHOICES
,
default
=
'ssh'
,
verbose_name
=
_
(
'Protocol'
))
auto_push
=
models
.
BooleanField
(
default
=
True
,
verbose_name
=
_
(
'Auto push'
))
...
...
@@ -224,6 +227,19 @@ class SystemUser(AssetUser):
'auto_push'
:
self
.
auto_push
,
}
@property
def
assets_connective
(
self
):
_result
=
cache
.
get
(
SYSTEM_USER_CONN_CACHE_KEY
.
format
(
self
.
name
),
{})
return
_result
@property
def
unreachable_assets
(
self
):
return
list
(
self
.
assets_connective
.
get
(
'dark'
,
{})
.
keys
())
@property
def
reachable_assets
(
self
):
return
self
.
assets_connective
.
get
(
'contacted'
,
[])
class
Meta
:
ordering
=
[
'name'
]
...
...
apps/assets/serializers.py
View file @
b0eace6a
...
...
@@ -25,17 +25,6 @@ class AssetGroupSerializer(BulkSerializerMixin, serializers.ModelSerializer):
return
obj
.
assets
.
count
()
class
AssetUpdateGroupSerializer
(
serializers
.
ModelSerializer
):
"""
资产更新自己所在资产组的请求数据结构定义
"""
groups
=
serializers
.
PrimaryKeyRelatedField
(
many
=
True
,
queryset
=
AssetGroup
.
objects
.
all
())
class
Meta
:
model
=
Asset
fields
=
[
'id'
,
'groups'
]
class
AssetUpdateSystemUserSerializer
(
serializers
.
ModelSerializer
):
"""
资产更新其系统用户请求的数据结构定义
...
...
@@ -90,11 +79,7 @@ class AdminUserSerializer(serializers.ModelSerializer):
@staticmethod
def
get_assets_amount
(
obj
):
amount
=
0
clusters
=
obj
.
cluster_set
.
all
()
for
cluster
in
clusters
:
amount
+=
len
(
cluster
.
assets
.
all
())
return
amount
return
obj
.
assets_amount
class
SystemUserSerializer
(
serializers
.
ModelSerializer
):
...
...
@@ -102,6 +87,9 @@ class SystemUserSerializer(serializers.ModelSerializer):
系统用户
"""
unreachable_amount
=
serializers
.
SerializerMethodField
()
reachable_amount
=
serializers
.
SerializerMethodField
()
unreachable_assets
=
serializers
.
SerializerMethodField
()
reachable_assets
=
serializers
.
SerializerMethodField
()
assets_amount
=
serializers
.
SerializerMethodField
()
class
Meta
:
...
...
@@ -109,12 +97,18 @@ class SystemUserSerializer(serializers.ModelSerializer):
exclude
=
(
'_password'
,
'_private_key'
,
'_public_key'
)
@staticmethod
def
get_unreachable_amount
(
obj
):
data
=
cache
.
get
(
SYSTEM_USER_CONN_CACHE_KEY
.
format
(
obj
.
name
))
if
data
:
return
len
(
data
.
get
(
'dark'
))
else
:
return
"Unknown"
def
get_unreachable_assets
(
obj
):
return
obj
.
unreachable_assets
@staticmethod
def
get_reachable_assets
(
obj
):
return
obj
.
reachable_assets
def
get_unreachable_amount
(
self
,
obj
):
return
len
(
self
.
get_unreachable_assets
(
obj
))
def
get_reachable_amount
(
self
,
obj
):
return
len
(
self
.
get_reachable_assets
(
obj
))
@staticmethod
def
get_assets_amount
(
obj
):
...
...
apps/assets/tasks.py
View file @
b0eace6a
...
...
@@ -181,10 +181,10 @@ def test_admin_user_connectability_manual(asset, task_name=None):
if
result
.
results_summary
[
'dark'
]:
cache
.
set
(
const
.
ASSET_ADMIN_CONN_CACHE_KEY
.
format
(
asset
.
hostname
),
0
,
CACHE_MAX_TIME
)
return
False
return
False
,
result
.
results_summary
[
'dark'
]
else
:
cache
.
set
(
const
.
ASSET_ADMIN_CONN_CACHE_KEY
.
format
(
asset
.
hostname
),
1
,
CACHE_MAX_TIME
)
return
True
return
True
,
""
@shared_task
...
...
@@ -211,7 +211,8 @@ def test_system_user_connectability(system_user, force=False):
)
cache
.
set
(
lock_key
,
1
,
CACHE_MAX_TIME
)
result
=
task
.
run
()
cache_key
=
const
.
SYSTEM_USER_CONN_CACHE_KEY
cache_key
=
const
.
SYSTEM_USER_CONN_CACHE_KEY
.
format
(
system_user
.
name
)
print
(
"Set cache: {} {}"
.
format
(
cache_key
,
result
.
results_summary
))
cache
.
set
(
cache_key
,
result
.
results_summary
,
CACHE_MAX_TIME
)
return
result
.
results_summary
...
...
@@ -369,7 +370,7 @@ def update_asset_info_when_created(sender, instance=None, created=False, **kwarg
@receiver
(
post_save
,
sender
=
Asset
,
dispatch_uid
=
"my_unique_identifier"
)
def
update_asset_conn_info_
whe
n_created
(
sender
,
instance
=
None
,
created
=
False
,
**
kwargs
):
def
update_asset_conn_info_
o
n_created
(
sender
,
instance
=
None
,
created
=
False
,
**
kwargs
):
if
instance
and
created
:
task_name
=
'TEST-ASSET-CONN-WHEN-CREATED-{}'
.
format
(
instance
)
msg
=
"Receive asset {} create signal, test asset connectability"
.
format
(
...
...
@@ -380,7 +381,7 @@ def update_asset_conn_info_when_created(sender, instance=None, created=False, **
@receiver
(
post_save
,
sender
=
Asset
,
dispatch_uid
=
"my_unique_identifier"
)
def
push_system_user_
whe
n_created
(
sender
,
instance
=
None
,
created
=
False
,
**
kwargs
):
def
push_system_user_
o
n_created
(
sender
,
instance
=
None
,
created
=
False
,
**
kwargs
):
if
instance
and
created
:
task_name
=
'PUSH-SYSTEM-USER-WHEN-ASSET-CREATED-{}'
.
format
(
instance
)
system_users
=
instance
.
cluster
.
systemuser_set
.
all
()
...
...
@@ -392,15 +393,7 @@ def push_system_user_when_created(sender, instance=None, created=False, **kwargs
@receiver
(
post_save
,
sender
=
SystemUser
)
def
push_system_user_on_change
(
sender
,
instance
=
None
,
created
=
False
,
**
kwargs
):
if
instance
and
instance
.
auto_push
:
logger
.
debug
(
"System user `{}` auth changed, push it"
.
format
(
instance
.
name
))
task_name
=
"PUSH-SYSTEM-USER-ON-CREATED-{}"
.
format
(
instance
.
name
)
push_system_user_to_cluster_assets
.
delay
(
instance
,
task_name
)
@receiver
(
post_save
,
sender
=
SystemUser
)
def
push_system_user_on_change
(
sender
,
instance
=
None
,
update_fields
=
None
,
**
kwargs
):
def
push_system_user_on_auth_change
(
sender
,
instance
=
None
,
update_fields
=
None
,
**
kwargs
):
fields_check
=
{
'_password'
,
'_private_key'
,
'_public_key'
}
auth_changed
=
update_fields
&
fields_check
if
update_fields
else
None
if
instance
and
instance
.
auto_push
and
auth_changed
:
...
...
apps/assets/templates/assets/admin_user_assets.html
View file @
b0eace6a
...
...
@@ -60,7 +60,7 @@
<th>
{% trans 'IP' %}
</th>
<th>
{% trans 'Port' %}
</th>
<th>
{% trans 'Type' %}
</th>
<th>
{% trans '
Valid
' %}
</th>
<th>
{% trans '
Alive
' %}
</th>
</tr>
</thead>
<tbody>
...
...
@@ -78,10 +78,10 @@
<table
class=
"table"
>
<tbody>
<tr
class=
"no-borders-tr"
>
<td
width=
"50%"
>
{% trans '
Retest connectivity
' %}:
</td>
<td
width=
"50%"
>
{% trans '
Test connective
' %}:
</td>
<td>
<span
style=
"float: right"
>
<button
type=
"button"
class=
"btn btn-primary btn-xs
"
style=
"width: 54px"
>
{% trans 'Star
t' %}
</button>
<button
type=
"button"
class=
"btn btn-primary btn-xs
btn-test-connective"
style=
"width: 54px"
>
{% trans 'Tes
t' %}
</button>
</span>
</td>
</tr>
...
...
@@ -98,56 +98,6 @@
{% endblock %}
{% block custom_foot_js %}
<script>
Array
.
prototype
.
remove
=
function
(
val
)
{
var
index
=
this
.
indexOf
(
val
);
if
(
index
>
-
1
)
{
this
.
splice
(
index
,
1
);
}
};
Array
.
prototype
.
unique
=
function
(){
var
res
=
[];
var
json
=
{};
for
(
var
i
=
0
;
i
<
this
.
length
;
i
++
){
if
(
!
json
[
this
[
i
]]){
res
.
push
(
this
[
i
]);
json
[
this
[
i
]]
=
1
;
}
}
return
res
;
};
function
objectRemove
(
obj
,
name
,
url
,
data
)
{
function
doRemove
()
{
var
body
=
data
;
var
success
=
function
()
{
swal
(
'Remove!'
,
"[ "
+
name
+
"]"
+
" has been deleted "
,
"success"
);
$
(
obj
).
parent
().
parent
().
remove
();
};
var
fail
=
function
()
{
swal
(
"Failed"
,
"Remove"
+
"[ "
+
name
+
" ]"
+
"failed"
,
"error"
);
};
APIUpdateAttr
({
url
:
url
,
body
:
JSON
.
stringify
(
body
),
method
:
'PATCH'
,
success
:
success
,
error
:
fail
});
}
swal
({
title
:
'Are you sure remove ?'
,
text
:
" ["
+
name
+
"] "
,
type
:
"warning"
,
showCancelButton
:
true
,
cancelButtonText
:
'Cancel'
,
confirmButtonColor
:
"#DD6B55"
,
confirmButtonText
:
'Confirm'
,
closeOnConfirm
:
false
},
function
()
{
doRemove
()
});
}
jumpserver
.
assets_selected
=
{};
jumpserver
.
asset_groups_selected
=
{};
function
initTable
()
{
var
options
=
{
...
...
@@ -168,56 +118,13 @@ function initTable() {
}}],
ajax_url
:
'{% url "api-assets:asset-list" %}?admin_user_id={{ admin_user.id }}'
,
columns
:
[{
data
:
function
(){
return
""
}},
{
data
:
"hostname"
},
{
data
:
"ip"
},
{
data
:
"port"
},
{
data
:
"type"
},
{
data
:
"is_
a
ctive"
}],
{
data
:
"type"
},
{
data
:
"is_
conne
ctive"
}],
op_html
:
$
(
'#actions'
).
html
()
};
jumpserver
.
initDataTable
(
options
);
}
function
adminUserDelete
(
name
,
url
)
{
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
()
});
}
$
(
document
).
ready
(
function
()
{
$
(
'.select2'
).
select2
()
.
on
(
"select2:select"
,
function
(
evt
)
{
var
data
=
evt
.
params
.
data
;
jumpserver
.
assets_selected
[
data
.
id
]
=
data
.
text
;
jumpserver
.
asset_groups_selected
[
data
.
id
]
=
data
.
text
;
})
.
on
(
'select2:unselect'
,
function
(
evt
)
{
var
data
=
evt
.
params
.
data
;
delete
jumpserver
.
assets_selected
[
data
.
id
];
delete
jumpserver
.
asset_groups_selected
[
data
.
id
]
});
initTable
();
})
.
on
(
'click'
,
'.btn-delete-admin-user'
,
function
()
{
...
...
@@ -228,5 +135,17 @@ $(document).ready(function () {
var
redirect_url
=
"{% url 'assets:admin-user-list' %}"
;
objectDelete
(
$this
,
name
,
the_url
,
redirect_url
);
})
.
on
(
'click'
,
'.btn-test-connective'
,
function
()
{
var
the_url
=
"{% url 'api-assets:admin-user-connective' pk=admin_user.id %}"
;
var
error
=
function
(
data
)
{
alert
(
data
)
};
APIUpdateAttr
({
url
:
the_url
,
error
:
error
,
method
:
'GET'
,
success_message
:
"{% trans "
Task
has
been
send
,
seen
left
asset
status
" %}"
});
})
</script>
{% endblock %}
apps/assets/templates/assets/admin_user_detail.html
View file @
b0eace6a
...
...
@@ -31,7 +31,7 @@
</ul>
</div>
<div
class=
"tab-content"
>
<div
class=
"col-sm-
8
"
style=
"padding-left: 0;"
>
<div
class=
"col-sm-
7
"
style=
"padding-left: 0;"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<span
class=
"label"
><b>
{{ admin_user.name }}
</b></span>
...
...
@@ -77,26 +77,8 @@
</div>
</div>
</div>
<div
class=
"col-sm-4"
style=
"padding-left: 0;padding-right: 0"
>
<div
class=
"panel panel-primary"
>
<div
class=
"panel-heading"
>
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Quick update' %}
</div>
<div
class=
"panel-body"
>
<table
class=
"table"
>
<tbody>
<tr
class=
"no-borders-tr"
>
<td
width=
"50%"
>
{% trans 'Test auth all assets manual' %}:
</td>
<td>
<span
style=
"float: right"
>
<button
type=
"button"
class=
"btn btn-primary btn-xs"
style=
"width: 54px"
>
{% trans 'Run' %}
</button>
</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div
class=
"col-sm-5"
style=
"padding-left: 0;padding-right: 0"
>
<div
class=
"panel panel-info"
>
<div
class=
"panel-heading"
>
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Using this as cluster admin user' %}
...
...
apps/assets/templates/assets/asset_detail.html
View file @
b0eace6a
...
...
@@ -71,8 +71,8 @@
</tr>
<tr>
<td>
{% trans 'Admin user' %}:
</td>
{% if asset.admin_user %}
<td><b>
{{ asset.admin_user.name }}
</b></td>
{% if asset.admin_user
_avail
%}
<td><b>
{{ asset.admin_user
_avail
.name }}
</b></td>
{% else %}
<td><b>
None
</b></td>
{% endif %}
...
...
@@ -195,6 +195,14 @@
</span>
</td>
</tr>
<tr>
<td>
{% trans 'Test is alive' %}:
</td>
<td>
<span
class=
"pull-right"
>
<button
type=
"button"
class=
"btn btn-primary btn-xs"
id=
"btn-test-is-alive"
style=
"width: 54px"
>
{% trans 'Test' %}
</button>
</span>
</td>
</tr>
</tbody>
</table>
</div>
...
...
@@ -248,7 +256,7 @@
<script>
jumpserver
.
groups_selected
=
{};
function
updateAssetGroups
(
groups
)
{
var
the_url
=
"{% url 'api-assets:asset-
update-group
' pk=asset.id %}"
;
var
the_url
=
"{% url 'api-assets:asset-
detail
' pk=asset.id %}"
;
var
body
=
{
groups
:
Object
.
assign
([],
groups
)
};
...
...
@@ -355,14 +363,18 @@ $(document).ready(function () {
}).
on
(
'click'
,
'#btn_refresh_asset'
,
function
()
{
alert
(
'关闭alert, 等待完成, 自动刷新页面'
);
refreshAssetHardware
()
}).
on
(
'click'
,
'#btn_test_admin_user'
,
function
()
{
$
.
ajax
({
url
:
'{% url "api-assets:asset-admin-user-test" pk=asset.id %}'
}).
done
(
function
(
data
,
textStatue
,
jqXHR
)
{
toastr
.
success
(
'Success'
)
}).
fail
(
function
(
data
,
textStaue
,
errorThrown
)
{
toastr
.
error
(
'Error'
)
})
}).
on
(
'click'
,
'#btn-test-is-alive'
,
function
()
{
var
the_url
=
"{% url 'api-assets:asset-alive-test' pk=asset.id %}"
;
var
error
=
function
(
data
)
{
alert
(
data
)
};
alert
(
'关闭alert, 等待完成'
);
APIUpdateAttr
({
url
:
the_url
,
error
:
error
,
method
:
'GET'
,
success_message
:
"{% trans "
Pong
" %}"
});
})
</script>
...
...
apps/assets/templates/assets/cluster_assets.html
View file @
b0eace6a
...
...
@@ -64,6 +64,25 @@
</div>
<div
class=
"col-sm-4"
style=
"padding-left: 0;padding-right: 0"
>
<div
class=
"panel panel-primary"
>
<div
class=
"panel-heading"
>
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Quick update' %}
</div>
<div
class=
"panel-body"
>
<table
class=
"table"
>
<tbody>
<tr
class=
"no-borders-tr"
>
<td
width=
"50%"
>
{% trans 'Test assets alive' %}:
</td>
<td>
<span
style=
"float: right"
>
<button
type=
"button"
class=
"btn btn-primary btn-xs"
id=
"btn-test-assets"
style=
"width: 54px"
>
{% trans 'Run' %}
</button>
</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div
class=
"panel panel-info"
>
<div
class=
"panel-heading"
>
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Add assets to' %} {{ cluster.name }}
</div>
...
...
@@ -173,7 +192,6 @@ $(document).ready(function () {
});
initTable
();
})
.
on
(
'click'
,
'.btn-add-assets'
,
function
()
{
if
(
Object
.
keys
(
jumpserver
.
assets_selected
).
length
===
0
)
{
return
false
;
...
...
@@ -185,5 +203,8 @@ $(document).ready(function () {
addAssets
(
assets_id
);
})
.
on
(
'click'
,
'#btn-test-assets'
,
function
()
{
console
.
log
(
'ok'
);
})
</script>
{% endblock %}
apps/assets/templates/assets/cluster_detail.html
View file @
b0eace6a
...
...
@@ -102,6 +102,44 @@
</div>
</div>
</div>
{#
<div
class=
"col-sm-4"
style=
"padding-left: 0;padding-right: 0"
>
#}
{#
<div
class=
"panel panel-primary"
>
#}
{#
<div
class=
"panel-heading"
>
#}
{#
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Update admin user' %}#}
{#
</div>
#}
{#
<div
class=
"panel-body"
>
#}
{#
<table
class=
"table cluster_edit"
id=
"add-asset2group"
>
#}
{#
<tbody>
#}
{#
<form>
#}
{#
<tr>
#}
{#
<td
colspan=
"2"
class=
"no-borders"
>
#}
{#
<select
data-placeholder=
"{% trans 'Select admin user' %}"
id=
"cluster_selected"
class=
"select2"
style=
"width: 100%"
tabindex=
"4"
>
#}
{# {% for admin_user in admin_user_list %}#}
{#
<option
value=
"{{ admin_user.id }}"
id=
"opt_{{ admin_user.id }}"
{%
if
admin_user
.
id =
=
cluster
.
admin_user
.
id
%}
selected
{%
endif
%}
>
{{ admin_user.name }}
</option>
#}
{# {% endfor %}#}
{#
</select>
#}
{#
</td>
#}
{#
</tr>
#}
{#
<tr>
#}
{#
<td
colspan=
"2"
class=
"no-borders"
>
#}
{#
<button
type=
"button"
class=
"btn btn-primary btn-sm"
id=
"btn-add-to-cluster"
>
{% trans 'Confirm' %}
</button>
#}
{#
</td>
#}
{#
</tr>
#}
{#
</form>
#}
{##}
{# {% for cluster in system_user.cluster.all %}#}
{#
<tr>
#}
{#
<td
><b
class=
"bdg_cluster"
data-gid=
{{
cluster
.
id
}}
>
{{ cluster.name }}
</b></td>
#}
{#
<td>
#}
{#
<button
class=
"btn btn-danger pull-right btn-xs btn-remove-from-cluster"
type=
"button"
><i
class=
"fa fa-minus"
></i></button>
#}
{#
</td>
#}
{#
</tr>
#}
{# {% endfor %}#}
{#
</tbody>
#}
{#
</table>
#}
{#
</div>
#}
{#
</div>
#}
{#
</div>
#}
</div>
</div>
</div>
...
...
@@ -111,46 +149,16 @@
{% endblock %}
{% block custom_foot_js %}
<script>
function
clusterDelete
(
name
,
url
)
{
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
()
});
}
$
(
document
).
ready
(
function
()
{
$
(
'.select2'
).
select2
();
})
.
on
(
'click'
,
'.btn-delete-cluster'
,
function
()
{
var
name
=
$
(
'.cluster-details > tbody > tr'
).
attr
(
"data-name"
)
;
var
id
=
{{
cluster
.
id
}}
;
var
name
=
"{{ cluster.name }}"
;
var
id
=
"{{ cluster.id }}"
;
var
the_url
=
'{% url "api-assets:cluster-detail" pk=DEFAULT_PK %}'
.
replace
(
"{{ DEFAULT_PK }}"
,
id
);
clusterDelete
(
name
,
the_url
);
var
redirect_url
=
"{% url 'assets:cluster-list' %}"
;
objectDelete
(
this
,
name
,
the_url
,
redirect_url
);
});
</script>
{% endblock %}
apps/assets/templates/assets/system_user_asset.html
View file @
b0eace6a
...
...
@@ -16,11 +16,6 @@
<li>
<a
href=
"{% url 'assets:system-user-detail' pk=system_user.id %}"
class=
"text-center"
><i
class=
"fa fa-laptop"
></i>
{% trans 'Detail' %}
</a>
</li>
<li>
<a
href=
"{% url 'assets:system-user-auth' pk=system_user.id %}"
class=
"text-center"
>
<i
class=
"fa fa-bar-chart-o"
></i>
{% trans 'Auth' %}
</a>
</li>
<li
class=
"active"
>
<a
href=
"{% url 'assets:system-user-asset' pk=system_user.id %}"
class=
"text-center"
>
<i
class=
"fa fa-bar-chart-o"
></i>
{% trans 'Assets' %}
...
...
@@ -78,15 +73,15 @@
<td
width=
"50%"
>
{% trans 'Push system user manually' %}:
</td>
<td>
<span
style=
"float: right"
>
<button
type=
"button"
class=
"btn btn-primary btn-xs"
style=
"width: 54px"
>
{% trans 'Push' %}
</button>
<button
type=
"button"
class=
"btn btn-primary btn-xs
btn-push
"
style=
"width: 54px"
>
{% trans 'Push' %}
</button>
</span>
</td>
</tr>
<tr>
<td
width=
"50%"
>
{% trans '
Refresh assets connectivity
' %}:
</td>
<td
width=
"50%"
>
{% trans '
Test assets connective
' %}:
</td>
<td>
<span
style=
"float: right"
>
<button
type=
"button"
class=
"btn btn-primary btn-xs
"
style=
"width: 54px"
>
{% trans 'Refresh
' %}
</button>
<button
type=
"button"
class=
"btn btn-primary btn-xs
btn-test-connective"
style=
"width: 54px"
>
{% trans 'Test
' %}
</button>
</span>
</td>
</tr>
...
...
@@ -103,26 +98,8 @@
{% endblock %}
{% block custom_foot_js %}
<script>
jumpserver
.
assets_selected
=
{};
jumpserver
.
asset_groups_selected
=
{};
Array
.
prototype
.
remove
=
function
(
val
)
{
var
index
=
this
.
indexOf
(
val
);
if
(
index
>
-
1
)
{
this
.
splice
(
index
,
1
);
}
};
Array
.
prototype
.
unique
=
function
(){
var
res
=
[];
var
json
=
{};
for
(
var
i
=
0
;
i
<
this
.
length
;
i
++
){
if
(
!
json
[
this
[
i
]]){
res
.
push
(
this
[
i
]);
json
[
this
[
i
]]
=
1
;
}
}
return
res
;
};
function
initAssetsTable
()
{
var
unreachable
=
{{
system_user
.
unreachable_assets
|
safe
}};
var
options
=
{
ele
:
$
(
'#system_user_list'
),
buttons
:
[],
...
...
@@ -133,7 +110,7 @@ function initAssetsTable() {
$
(
td
).
html
(
detail_btn
.
replace
(
'{{ DEFAULT_PK }}'
,
rowData
.
id
));
}},
{
targets
:
3
,
createdCell
:
function
(
td
,
cellData
)
{
if
(
!
cellData
)
{
if
(
unreachable
.
indexOf
(
cellData
)
>=
0
)
{
$
(
td
).
html
(
'<i class="fa fa-times text-danger"></i>'
)
}
else
{
$
(
td
).
html
(
'<i class="fa fa-check text-navy"></i>'
)
...
...
@@ -141,67 +118,12 @@ function initAssetsTable() {
}}
],
ajax_url
:
'{% url "api-assets:asset-list" %}?system_user_id={{ system_user.id }}'
,
columns
:
[{
data
:
"hostname"
},
{
data
:
"ip"
},
{
data
:
"port"
},
{
data
:
"
is_connectiv
e"
}],
columns
:
[{
data
:
"hostname"
},
{
data
:
"ip"
},
{
data
:
"port"
},
{
data
:
"
hostnam
e"
}],
op_html
:
$
(
'#actions'
).
html
()
};
jumpserver
.
initDataTable
(
options
);
}
function
objectDelete
(
obj
,
name
,
url
,
data
)
{
function
doDelete
()
{
var
body
=
data
;
var
success
=
function
()
{
swal
(
'Deleted!'
,
"[ "
+
name
+
"]"
+
" has been deleted "
,
"success"
);
$
(
obj
).
parent
().
parent
().
remove
();
};
var
fail
=
function
()
{
swal
(
"Failed"
,
"Delete"
+
"[ "
+
name
+
" ]"
+
"failed"
,
"error"
);
};
APIUpdateAttr
({
url
:
url
,
body
:
JSON
.
stringify
(
body
),
method
:
'PATCH'
,
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
()
});
}
function
updateSystemUserAssetGroup
(
asset_groups
)
{
var
the_url
=
"{% url 'api-assets:systemuser-update-assetgroups' pk=system_user.id %}"
;
var
body
=
{
asset_groups
:
Object
.
assign
([],
asset_groups
)
};
var
success
=
function
(
data
)
{
$
(
'.select2-selection__rendered'
).
empty
();
$
(
'#groups_selected'
).
val
(
''
);
$
.
map
(
jumpserver
.
asset_groups_selected
,
function
(
asset_groups
,
index
)
{
$
(
'#opt_'
+
index
).
remove
();
$
(
'.system-user-table tbody'
).
append
(
'<tr>'
+
'<td><b class="bdg_asset_groups" data-sid="'
+
index
+
'">'
+
asset_groups
+
'</b></td>'
+
'<td><button class="btn btn-danger btn-xs pull-right btn-leave-system_user" type="button"><i class="fa fa-minus"></i></button></td>'
+
'</tr>'
)
});
jumpserver
.
assets_selected
=
{};
};
APIUpdateAttr
({
url
:
the_url
,
body
:
JSON
.
stringify
(
body
),
success
:
success
});
}
$
(
document
).
ready
(
function
()
{
$
(
'.select2'
).
select2
()
.
on
(
"select2:select"
,
function
(
evt
)
{
...
...
@@ -216,107 +138,31 @@ $(document).ready(function () {
});
initAssetsTable
();
})
.
on
(
'click'
,
'.btn-add-asset2system-user'
,
function
()
{
if
(
Object
.
keys
(
jumpserver
.
assets_selected
).
length
===
0
)
{
return
false
;
}
var
$data_table
=
$
(
"#system_user_list"
).
DataTable
();
var
assets
=
[];
$
.
ajax
({
url
:
'{% url "api-assets:asset-list" %}?system_user_id={{ system_user.id }}'
,
method
:
'GET'
,
dataType
:
'json'
,
success
:
function
(
result
)
{
for
(
var
i
in
result
){
if
(
!
isNaN
(
parseInt
(
result
[
i
][
'id'
])))
{
assets
.
push
(
parseInt
(
result
[
i
][
'id'
]))
}
}
$
.
map
(
jumpserver
.
assets_selected
,
function
(
value
,
index
)
{
assets
.
push
(
parseInt
(
index
));
});
assets
.
unique
();
var
the_url
=
"{% url 'api-assets:systemuser-update-assets' pk=system_user.id %}"
;
var
body
=
{
"assets"
:
assets
};
.
on
(
'click'
,
'.btn-push'
,
function
()
{
var
the_url
=
"{% url 'api-assets:system-user-push' pk=system_user.id %}"
;
var
error
=
function
(
data
)
{
alert
(
data
)
};
APIUpdateAttr
({
url
:
the_url
,
body
:
JSON
.
stringify
(
body
),
method
:
'PATCH'
});
$data_table
.
ajax
.
reload
();
}
});
})
.
on
(
'click'
,
'.btn_asset_delete'
,
function
()
{
var
$this
=
$
(
this
);
var
the_url
=
"{% url 'api-assets:systemuser-update-assets' pk=system_user.id %}"
;
var
name
=
$
(
this
).
closest
(
"tr"
).
find
(
":nth-child(1) > a"
).
html
();
var
$data_table
=
$
(
"#system_user_list"
).
DataTable
();
var
assets
=
[];
$
(
'#system_user_list > tbody > tr'
).
map
(
function
()
{
assets
.
push
(
parseInt
(
$
(
this
).
closest
(
"tr"
).
find
(
":nth-child(1) > a"
).
attr
(
"data-aid"
)))
});
var
delete_asset_id
=
$
(
this
).
data
(
'aid'
);
assets
.
remove
(
delete_asset_id
);
assets
.
unique
();
var
data
=
{
"assets"
:
assets
};
objectDelete
(
$this
,
name
,
the_url
,
data
);
$data_table
.
ajax
.
reload
();
})
.
on
(
'click'
,
'#btn_add_user_group'
,
function
()
{
jumpserver
.
assets_selected
=
{};
if
(
Object
.
keys
(
jumpserver
.
asset_groups_selected
).
length
===
0
)
{
return
false
;
}
asset_groups
=
[];
$
.
ajax
({
url
:
'{% url "api-assets:systemuser-update-assetgroups" pk=system_user.id %}'
,
error
:
error
,
method
:
'GET'
,
dataType
:
'json'
,
success
:
function
(
result
)
{
for
(
var
i
in
result
[
'asset_groups'
])
{
if
(
!
isNaN
(
result
[
'asset_groups'
][
i
]))
{
asset_groups
.
push
(
parseInt
(
result
[
'asset_groups'
][
i
]));
}
}
$
.
map
(
jumpserver
.
asset_groups_selected
,
function
(
value
,
index
)
{
asset_groups
.
push
(
parseInt
(
index
));
success_message
:
"{% trans "
Task
has
been
send
,
Go
to
ops
task
list
seen
result
" %}"
});
asset_groups
.
unique
();
console
.
log
(
asset_groups
);
var
the_url
=
'{% url "api-assets:systemuser-update-assetgroups" pk=system_user.id %}'
;
var
body
=
{
"asset_groups"
:
asset_groups
};
})
.
on
(
'click'
,
'.btn-test-connective'
,
function
()
{
var
the_url
=
"{% url 'api-assets:system-user-connective' pk=system_user.id %}"
;
var
error
=
function
(
data
)
{
alert
(
data
)
};
APIUpdateAttr
({
url
:
the_url
,
body
:
JSON
.
stringify
(
body
),
method
:
'PATCH'
});
{
#
TODO
:
reload
the
table
#
}
{
#
window
.
location
.
href
=
"{% url 'assets:system-user-asset' pk=system_user.id %}"
#
}
}
error
:
error
,
method
:
'GET'
,
success_message
:
"{% trans "
Task
has
been
send
,
seen
left
assets
status
" %}"
});
})
.
on
(
'click'
,
'.btn-leave-system_user'
,
function
()
{
var
$this
=
$
(
this
);
var
$tr
=
$this
.
closest
(
'tr'
);
var
$badge
=
$tr
.
find
(
'.bdg_asset_groups'
);
var
sid
=
$badge
.
data
(
'gid'
);
var
name
=
$badge
.
html
()
||
$badge
.
text
();
$
(
'system-user-table'
).
append
(
'<option value="'
+
sid
+
'" id="opt_'
+
sid
+
'">'
+
name
+
'</option>'
);
$tr
.
remove
();
var
asset_groups
=
$
(
'.bdg_asset_groups'
).
map
(
function
()
{
return
$
(
this
).
data
(
'gid'
);
}).
get
();
updateSystemUserAssetGroup
(
asset_groups
);
});
</script>
...
...
apps/assets/templates/assets/system_user_auth.html
deleted
100644 → 0
View file @
b4e1ac19
{% extends 'base.html' %}
{% load static %}
{% load i18n %}
{% load bootstrap3 %}
{% block content %}
<div
class=
"wrapper wrapper-content animated fadeInRight"
>
<div
class=
"row"
>
<div
class=
"col-sm-12"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"panel-options"
>
<ul
class=
"nav nav-tabs"
>
<li>
<a
href=
"{% url 'assets:system-user-detail' pk=system_user.id %}"
class=
"text-center"
><i
class=
"fa fa-laptop"
></i>
{% trans 'Detail' %}
</a>
</li>
<li
class=
"active"
>
<a
href=
"{% url 'assets:system-user-auth' pk=system_user.id %}"
class=
"text-center"
>
<i
class=
"fa fa-bar-chart-o"
></i>
{% trans 'Auth' %}
</a>
</li>
<li>
<a
href=
"{% url 'assets:system-user-asset' pk=system_user.id %}"
class=
"text-center"
>
<i
class=
"fa fa-bar-chart-o"
></i>
{% trans 'Attached assets' %}
</a>
</li>
<li
class=
"pull-right"
>
<a
class=
"btn btn-outline btn-default"
href=
"{% url 'assets:system-user-update' pk=system_user.id %}"
><i
class=
"fa fa-edit"
></i>
Update
</a>
</li>
</ul>
</div>
<div
class=
"tab-content"
>
<div
class=
"col-sm-12"
style=
"padding-left: 0;"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<span
class=
"label"
><b>
{{ system_user.name }}
</b></span>
<div
class=
"ibox-tools"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
</a>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
>
<i
class=
"fa fa-wrench"
></i>
</a>
<ul
class=
"dropdown-menu dropdown-user"
>
</ul>
<a
class=
"close-link"
>
<i
class=
"fa fa-times"
></i>
</a>
</div>
</div>
<div
class=
"ibox-content"
>
<form
enctype=
"multipart/form-data"
method=
"post"
class=
"form-horizontal"
action=
""
>
{% csrf_token %}
{% bootstrap_field form.password layout="horizontal" %}
<div
class=
"hr-line-dashed"
></div>
{% bootstrap_field form.private_key_file layout="horizontal" %}
<div
class=
"hr-line-dashed"
></div>
<div
class=
"form-group"
>
<div
class=
"col-sm-4 col-sm-offset-2"
>
<button
class=
"btn btn-white"
type=
"reset"
>
{% trans 'Reset' %}
</button>
<button
id=
"submit_button"
class=
"btn btn-primary"
type=
"submit"
>
{% trans 'Submit' %}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
apps/assets/templates/assets/system_user_detail.html
View file @
b0eace6a
...
...
@@ -17,11 +17,6 @@
<li
class=
"active"
>
<a
href=
"{% url 'assets:system-user-detail' pk=system_user.id %}"
class=
"text-center"
><i
class=
"fa fa-laptop"
></i>
{% trans 'Detail' %}
</a>
</li>
<li>
<a
href=
"{% url 'assets:system-user-auth' pk=system_user.id %}"
class=
"text-center"
>
<i
class=
"fa fa-bar-chart-o"
></i>
{% trans 'Auth' %}
</a>
</li>
<li>
<a
href=
"{% url 'assets:system-user-asset' pk=system_user.id %}"
class=
"text-center"
>
<i
class=
"fa fa-bar-chart-o"
></i>
{% trans 'Attached assets' %}
...
...
@@ -120,8 +115,8 @@
<span
class=
"pull-right"
>
<div
class=
"switch"
>
<div
class=
"onoffswitch"
>
<input
type=
"checkbox"
{%
if
system_user
.
auto_push
%}
checked
{%
endif
%}
class=
"onoffswitch-checkbox"
id=
"
is_active
"
>
<label
class=
"onoffswitch-label"
for=
"
is_active
"
>
<input
type=
"checkbox"
{%
if
system_user
.
auto_push
%}
checked
{%
endif
%}
class=
"onoffswitch-checkbox"
id=
"
btn-auto-push
"
>
<label
class=
"onoffswitch-label"
for=
"
btn-auto-push
"
>
<span
class=
"onoffswitch-inner"
></span>
<span
class=
"onoffswitch-switch"
></span>
</label>
...
...
@@ -147,12 +142,12 @@
<i
class=
"fa fa-info-circle"
></i>
{% trans 'Clusters' %}
</div>
<div
class=
"panel-body"
>
<table
class=
"table
group
_edit"
id=
"add-asset2group"
>
<table
class=
"table
cluster
_edit"
id=
"add-asset2group"
>
<tbody>
<form>
<tr>
<td
colspan=
"2"
class=
"no-borders"
>
<select
data-placeholder=
"{% trans 'Add to cluster' %}"
id=
""
class=
"select2"
style=
"width: 100%"
multiple=
""
tabindex=
"4"
>
<select
data-placeholder=
"{% trans 'Add to cluster' %}"
id=
"
cluster_selected
"
class=
"select2"
style=
"width: 100%"
multiple=
""
tabindex=
"4"
>
{% for cluster in cluster_remain %}
<option
value=
"{{ cluster.id }}"
id=
"opt_{{ cluster.id }}"
>
{{ cluster.name }}
</option>
{% endfor %}
...
...
@@ -161,16 +156,16 @@
</tr>
<tr>
<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-to-cluster
"
>
{% trans 'Confirm' %}
</button>
</td>
</tr>
</form>
{% for cluster in system_user.cluster.all %}
<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>
<button
class=
"btn btn-danger pull-right btn-xs btn-
remove-from-cluster
"
type=
"button"
><i
class=
"fa fa-minus"
></i></button>
</td>
</tr>
{% endfor %}
...
...
@@ -186,27 +181,84 @@
</div>
{% endblock %}
{% block custom_foot_js %}
<script>
// Todo: 添加自动推送的js
{
#
function
switch_user_status
(
obj
)
{
#
}
{
#
var
status
=
$
(
obj
).
prop
(
'checked'
);
#
}
{
##
}
{
#
$
.
ajax
({
#
}
{
#
url
:
"{% url 'users:user-active-api' pk=user.id %}"
,
#
}
{
#
type
:
"PUT"
,
#
}
{
#
data
:
{
#
}
{
#
'is_active'
:
status
#
}
{
#
},
#
}
{
#
success
:
function
(
data
,
status
)
{
#
}
{
#
console
.
log
(
data
)
#
}
{
#
},
#
}
{
#
error
:
function
()
{
#
}
{
#
console
.
log
(
'error'
)
#
}
{
#
}
#
}
{
#
})
#
}
{
#
}
#
}
$
(
document
).
ready
(
function
()
{
$
(
'.select2'
).
select2
();
<script>
function
updateSystemUserCluster
(
clusters
)
{
var
the_url
=
"{% url 'api-assets:system-user-detail' pk=system_user.id %}"
;
var
body
=
{
cluster
:
Object
.
assign
([],
clusters
)
};
var
success
=
function
(
data
)
{
// remove all the selected groups from select > option and rendered ul element;
$
(
'.select2-selection__rendered'
).
empty
();
$
(
'#cluster_selected'
).
val
(
''
);
$
.
map
(
jumpserver
.
cluster_selected
,
function
(
cluster_name
,
index
)
{
$
(
'#opt_'
+
index
).
remove
();
// change tr html of user groups.
$
(
'.cluster_edit tbody'
).
append
(
'<tr>'
+
'<td><b class="bdg_cluster" data-gid="'
+
index
+
'">'
+
cluster_name
+
'</b></td>'
+
'<td><button class="btn btn-danger btn-xs pull-right btn-remove-from-cluster" type="button"><i class="fa fa-minus"></i></button></td>'
+
'</tr>'
)
});
// clear jumpserver.groups_selected
jumpserver
.
cluster_selected
=
{};
};
APIUpdateAttr
({
url
:
the_url
,
body
:
JSON
.
stringify
(
body
),
success
:
success
});
}
jumpserver
.
cluster_selected
=
{};
$
(
document
).
ready
(
function
()
{
$
(
'.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-auto-push'
,
function
()
{
var
checked
=
$
(
this
).
prop
(
'checked'
);
var
the_url
=
"{% url 'api-assets:system-user-detail' pk=system_user.id %}"
;
var
body
=
{
'auto_push'
:
checked
};
APIUpdateAttr
({
url
:
the_url
,
body
:
JSON
.
stringify
(
body
)
});
})
.
on
(
'click'
,
'#btn-add-to-cluster'
,
function
()
{
if
(
Object
.
keys
(
jumpserver
.
cluster_selected
).
length
===
0
)
{
return
false
;
}
var
clusters
=
$
(
'.bdg_cluster'
).
map
(
function
()
{
return
$
(
this
).
data
(
'gid'
);
}).
get
();
$
.
map
(
jumpserver
.
cluster_selected
,
function
(
value
,
index
)
{
clusters
.
push
(
index
);
});
</script>
updateSystemUserCluster
(
clusters
);
})
.
on
(
'click'
,
'.btn-remove-from-cluster'
,
function
()
{
var
$this
=
$
(
this
);
var
$tr
=
$this
.
closest
(
'tr'
);
var
$badge
=
$tr
.
find
(
'.bdg_cluster'
);
var
gid
=
$badge
.
data
(
'gid'
);
var
cluster_name
=
$badge
.
html
()
||
$badge
.
text
();
$
(
'#groups_selected'
).
append
(
'<option value="'
+
gid
+
'" id="opt_'
+
gid
+
'">'
+
cluster_name
+
'</option>'
);
$tr
.
remove
();
var
clusters
=
$
(
'.bdg_cluster'
).
map
(
function
()
{
return
$
(
this
).
data
(
'gid'
);
}).
get
();
updateSystemUserCluster
(
clusters
);
})
</script>
{% endblock %}
apps/assets/templates/assets/system_user_list.html
View file @
b0eace6a
...
...
@@ -17,7 +17,9 @@
<th
class=
"text-center"
>
{% trans 'Name' %}
</th>
<th
class=
"text-center"
>
{% trans 'Username' %}
</th>
<th
class=
"text-center"
>
{% trans 'Asset' %}
</th>
<th
class=
"text-center"
>
{% trans 'Reachable' %}
</th>
<th
class=
"text-center"
>
{% trans 'Unreachable' %}
</th>
<th
class=
"text-center"
>
{% trans 'Ratio' %}
</th>
<th
class=
"text-center"
>
{% trans 'Comment' %}
</th>
<th
class=
"text-center"
>
{% trans 'Action' %}
</th>
</tr>
...
...
@@ -25,19 +27,6 @@
<tbody>
</tbody>
</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>
{% endblock %}
{% block custom_foot_js %}
<script>
...
...
@@ -49,19 +38,52 @@ $(document).ready(function(){
var
detail_btn
=
'<a href="{% url "assets:system-user-detail" pk=DEFAULT_PK %}">'
+
cellData
+
'</a>'
;
$
(
td
).
html
(
detail_btn
.
replace
(
'{{ DEFAULT_PK }}'
,
rowData
.
id
));
}},
{
targets
:
4
,
createdCell
:
function
(
td
,
cellData
)
{
var
innerHtml
=
""
;
if
(
cellData
!==
0
)
{
innerHtml
=
"<span class='text-navy'>"
+
cellData
+
"</span>"
;
}
else
{
innerHtml
=
"<span>"
+
cellData
+
"</span>"
;
}
$
(
td
).
html
(
'<span href="javascript:void(0);" data-toggle="tooltip" title="'
+
cellData
+
'">'
+
innerHtml
+
'</span>'
);
}},
{
targets
:
5
,
createdCell
:
function
(
td
,
cellData
)
{
var
innerHtml
=
cellData
.
length
>
30
?
cellData
.
substring
(
0
,
30
)
+
'...'
:
cellData
;
var
innerHtml
=
""
;
if
(
cellData
!==
0
)
{
innerHtml
=
"<span class='text-danger'>"
+
cellData
+
"</span>"
;
}
else
{
innerHtml
=
"<span>"
+
cellData
+
"</span>"
;
}
$
(
td
).
html
(
'<span href="javascript:void(0);" data-toggle="tooltip" title="'
+
cellData
+
'">'
+
innerHtml
+
'</span>'
);
}},
{
targets
:
6
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
val
=
0
;
var
innerHtml
=
""
;
var
total
=
rowData
.
assets_amount
;
var
reachable
=
rowData
.
reachable_amount
;
if
(
total
!==
0
)
{
val
=
reachable
/
total
*
100
;
}
if
(
val
===
100
)
{
innerHtml
=
"<span class='text-navy'>"
+
val
+
"% </span>"
;
}
else
{
innerHtml
=
"<span class='text-danger'>"
+
val
+
"% </span>"
;
}
$
(
td
).
html
(
'<span href="javascript:void(0);" data-toggle="tooltip" title="'
+
cellData
+
'">'
+
innerHtml
+
'</span>'
);
}},
{
targets
:
8
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
{
#
var
script_btn
=
'<a href="{% url "assets:system-user-update" pk=DEFAULT_PK %}" class="btn btn-xs btn-primary">{% trans "Script" %}</a>'
.
replace
(
'{{ DEFAULT_PK }}'
,
cellData
);
#
}
var
update_btn
=
'<a href="{% url "assets:system-user-update" pk=DEFAULT_PK %}" class="btn btn-xs m-l-xs btn-info">{% trans "Update" %}</a>'
.
replace
(
'{{ DEFAULT_PK }}'
,
cellData
);
var
del_btn
=
'<a class="btn btn-xs btn-danger m-l-xs btn_admin_user_delete" data-uid="{{ DEFAULT_PK }}">{% trans "Delete" %}</a>'
.
replace
(
'{{ DEFAULT_PK }}'
,
cellData
);
$
(
td
).
html
(
update_btn
+
del_btn
)
}}],
ajax_url
:
'{% url "api-assets:system-user-list" %}'
,
columns
:
[{
data
:
"id"
},
{
data
:
"name"
},
{
data
:
"username"
},
{
data
:
"assets_amount"
},
{
data
:
"unreachable_amount"
},
{
data
:
"comment"
},
{
data
:
"id"
}],
columns
:
[
{
data
:
"id"
},
{
data
:
"name"
},
{
data
:
"username"
},
{
data
:
"assets_amount"
},
{
data
:
"reachable_amount"
},
{
data
:
"unreachable_amount"
},
{
data
:
"id"
},
{
data
:
"comment"
},
{
data
:
"id"
}
],
op_html
:
$
(
'#actions'
).
html
()
};
jumpserver
.
initDataTable
(
options
);
...
...
apps/assets/templates/assets/system_user_update.html
View file @
b0eace6a
...
...
@@ -4,6 +4,15 @@
{% load bootstrap3 %}
{% block auth %}
<h3>
{% trans 'Auth' %}
</h3>
{% bootstrap_field form.private_key_file layout="horizontal" %}
{% bootstrap_field form.password layout="horizontal" %}
<div
class=
"form-group"
>
<label
for=
"{{ form.as_push.id_for_label }}"
class=
"col-sm-2 control-label"
>
{% trans 'Auto push' %}
</label>
<div
class=
"col-sm-8"
>
{{ form.auto_push}}
</div>
</div>
{% endblock %}
{% block custom_foot_js %}
...
...
apps/assets/urls/api_urls.py
View file @
b0eace6a
...
...
@@ -17,12 +17,10 @@ urlpatterns = [
url
(
r'^v1/assets-bulk/$'
,
api
.
AssetListUpdateApi
.
as_view
(),
name
=
'asset-bulk-update'
),
url
(
r'^v1/system-user/(?P<pk>[0-9a-zA-Z\-]{36})/auth-info/'
,
api
.
SystemUserAuthInfoApi
.
as_view
(),
name
=
'system-user-auth-info'
),
url
(
r'^v1/assets/(?P<pk>[0-9a-zA-Z\-]{36})/groups/$'
,
api
.
AssetUpdateGroupApi
.
as_view
(),
name
=
'asset-update-group'
),
url
(
r'^v1/assets/(?P<pk>[0-9a-zA-Z\-]{36})/refresh/$'
,
api
.
AssetRefreshHardware
View
.
as_view
(),
name
=
'asset-refresh'
),
url
(
r'^v1/assets/(?P<pk>[0-9a-zA-Z\-]{36})/a
dmin-user-test
/$'
,
api
.
AssetAdminUserTest
View
.
as_view
(),
name
=
'asset-admin-user
-test'
),
api
.
AssetRefreshHardware
Api
.
as_view
(),
name
=
'asset-refresh'
),
url
(
r'^v1/assets/(?P<pk>[0-9a-zA-Z\-]{36})/a
live
/$'
,
api
.
AssetAdminUserTest
Api
.
as_view
(),
name
=
'asset-alive
-test'
),
# 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/$'
,
api
.
GroupUpdateAssetsApi
.
as_view
(),
name
=
'group-update-assets'
),
...
...
@@ -35,6 +33,12 @@ urlpatterns = [
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'
),
url
(
r'^v1/admin-user/(?P<pk>[0-9a-zA-Z\-]{36})/connective/$'
,
api
.
AdminUserTestConnectiveApi
.
as_view
(),
name
=
'admin-user-connective'
),
url
(
r'^v1/system-user/(?P<pk>[0-9a-zA-Z\-]{36})/push/$'
,
api
.
SystemUserPushApi
.
as_view
(),
name
=
'system-user-push'
),
url
(
r'^v1/system-user/(?P<pk>[0-9a-zA-Z\-]{36})/connective/$'
,
api
.
SystemUserTestConnectiveApi
.
as_view
(),
name
=
'system-user-connective'
),
]
urlpatterns
+=
router
.
urls
...
...
apps/assets/urls/views_urls.py
View file @
b0eace6a
...
...
@@ -50,7 +50,6 @@ urlpatterns = [
url
(
r'^system-user/(?P<pk>[0-9a-zA-Z\-]{36})/update/$'
,
views
.
SystemUserUpdateView
.
as_view
(),
name
=
'system-user-update'
),
url
(
r'^system-user/(?P<pk>[0-9a-zA-Z\-]{36})/delete/$'
,
views
.
SystemUserDeleteView
.
as_view
(),
name
=
'system-user-delete'
),
url
(
r'^system-user/(?P<pk>[0-9a-zA-Z\-]{36})/asset/$'
,
views
.
SystemUserAssetView
.
as_view
(),
name
=
'system-user-asset'
),
url
(
r'^system-user/(?P<pk>[0-9a-zA-Z\-]{36})/auth/$'
,
views
.
SystemUserAuthView
.
as_view
(),
name
=
'system-user-auth'
),
# url(r'^system-user/(?P<pk>[0-9a-zA-Z\-]{36})/asset-group$', views.SystemUserAssetGroupView.as_view(),
# name='system-user-asset-group'),
...
...
apps/assets/views/admin_user.py
View file @
b0eace6a
...
...
@@ -106,7 +106,7 @@ class AdminUserAssetsView(AdminUserRequiredMixin, SingleObjectMixin, ListView):
def
get_queryset
(
self
):
queryset
=
[]
for
cluster
in
self
.
object
.
cluster_set
.
all
():
queryset
.
extend
(
list
(
cluster
.
assets
.
all
())
)
queryset
.
extend
(
[
asset
for
asset
in
cluster
.
assets
.
all
()
if
not
asset
.
admin_user
]
)
self
.
queryset
=
queryset
return
queryset
...
...
@@ -115,7 +115,7 @@ class AdminUserAssetsView(AdminUserRequiredMixin, SingleObjectMixin, ListView):
'app'
:
'assets'
,
'action'
:
'Admin user detail'
,
"total_amount"
:
len
(
self
.
queryset
),
'unreachable_amount'
:
len
([
asset
for
asset
in
self
.
queryset
if
asset
.
is_connective
()
is
False
])
'unreachable_amount'
:
len
([
asset
for
asset
in
self
.
queryset
if
asset
.
is_connective
is
False
])
}
kwargs
.
update
(
context
)
return
super
()
.
get_context_data
(
**
kwargs
)
...
...
apps/assets/views/cluster.py
View file @
b0eace6a
...
...
@@ -24,7 +24,7 @@ class ClusterListView(AdminUserRequiredMixin, TemplateView):
# 'keyword': self.request.GET.get('keyword', '')
}
kwargs
.
update
(
context
)
return
super
(
ClusterListView
,
self
)
.
get_context_data
(
**
kwargs
)
return
super
()
.
get_context_data
(
**
kwargs
)
class
ClusterCreateView
(
AdminUserRequiredMixin
,
CreateView
):
...
...
@@ -39,13 +39,13 @@ class ClusterCreateView(AdminUserRequiredMixin, CreateView):
'action'
:
_
(
'Create Cluster'
),
}
kwargs
.
update
(
context
)
return
super
(
ClusterCreateView
,
self
)
.
get_context_data
(
**
kwargs
)
return
super
()
.
get_context_data
(
**
kwargs
)
def
form_valid
(
self
,
form
):
cluster
=
form
.
save
(
commit
=
False
)
cluster
.
created_by
=
self
.
request
.
user
.
username
or
'System'
cluster
.
save
()
return
super
(
ClusterCreateView
,
self
)
.
form_valid
(
form
)
return
super
()
.
form_valid
(
form
)
class
ClusterUpdateView
(
AdminUserRequiredMixin
,
UpdateView
):
...
...
@@ -58,7 +58,7 @@ class ClusterUpdateView(AdminUserRequiredMixin, UpdateView):
def
form_valid
(
self
,
form
):
cluster
=
form
.
save
(
commit
=
False
)
cluster
.
save
()
return
super
(
ClusterUpdateView
,
self
)
.
form_valid
(
form
)
return
super
()
.
form_valid
(
form
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
...
...
@@ -66,7 +66,7 @@ class ClusterUpdateView(AdminUserRequiredMixin, UpdateView):
'action'
:
_
(
'Update Cluster'
),
}
kwargs
.
update
(
context
)
return
super
(
ClusterUpdateView
,
self
)
.
get_context_data
(
**
kwargs
)
return
super
()
.
get_context_data
(
**
kwargs
)
class
ClusterDetailView
(
AdminUserRequiredMixin
,
DetailView
):
...
...
@@ -74,6 +74,16 @@ class ClusterDetailView(AdminUserRequiredMixin, DetailView):
template_name
=
'assets/cluster_detail.html'
context_object_name
=
'cluster'
def
get_context_data
(
self
,
**
kwargs
):
admin_user_list
=
AdminUser
.
objects
.
exclude
()
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'Cluster detail'
),
'admin_user_list'
:
admin_user_list
,
}
kwargs
.
update
(
context
)
return
super
()
.
get_context_data
(
**
kwargs
)
class
ClusterAssetsView
(
AdminUserRequiredMixin
,
DetailView
):
model
=
Cluster
...
...
@@ -92,7 +102,7 @@ class ClusterAssetsView(AdminUserRequiredMixin, DetailView):
'assets'
:
[
asset
for
asset
in
Asset
.
objects
.
all
()
if
asset
not
in
assets_remain
],
}
kwargs
.
update
(
context
)
return
super
(
ClusterAssetsView
,
self
)
.
get_context_data
(
**
kwargs
)
return
super
()
.
get_context_data
(
**
kwargs
)
class
ClusterDeleteView
(
AdminUserRequiredMixin
,
DeleteView
):
...
...
apps/assets/views/system_user.py
View file @
b0eace6a
...
...
@@ -18,7 +18,6 @@ from ..hands import AdminUserRequiredMixin
__all__
=
[
'SystemUserCreateView'
,
'SystemUserUpdateView'
,
'SystemUserDetailView'
,
'SystemUserDeleteView'
,
'SystemUserAssetView'
,
'SystemUserListView'
,
'SystemUserAuthView'
,
]
...
...
@@ -115,35 +114,3 @@ class SystemUserAssetView(AdminUserRequiredMixin, DetailView):
}
kwargs
.
update
(
context
)
return
super
()
.
get_context_data
(
**
kwargs
)
class
SystemUserAuthView
(
AdminUserRequiredMixin
,
SingleObjectMixin
,
SuccessMessageMixin
,
FormView
):
model
=
SystemUser
template_name
=
'assets/system_user_auth.html'
context_object_name
=
'system_user'
form_class
=
SystemUserAuthForm
success_message
=
_
(
"Update auth info success"
)
object
=
None
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
object
=
self
.
get_object
()
return
super
()
.
get
(
request
,
*
args
,
**
kwargs
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
object
=
self
.
get_object
()
return
super
()
.
post
(
request
,
*
args
,
**
kwargs
)
def
form_valid
(
self
,
form
):
instance
=
form
.
update
(
self
.
object
)
success_url
=
reverse
(
'assets:system-user-detail'
,
kwargs
=
{
"pk"
:
instance
.
id
})
messages
.
success
(
self
.
request
,
self
.
success_message
)
return
redirect
(
success_url
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
'assets'
,
'action'
:
'System user auth'
,
}
kwargs
.
update
(
context
)
return
super
()
.
get_context_data
(
**
kwargs
)
apps/users/templates/users/user_detail.html
View file @
b0eace6a
...
...
@@ -156,7 +156,7 @@
<td>
{% trans 'Send reset password mail' %}:
</td>
<td>
<span
class=
"pull-right"
>
<button
type=
"button"
class=
"btn btn-primary btn-xs"
id=
"btn
_reset_
password"
style=
"width: 54px"
>
{% trans 'Send' %}
</button>
<button
type=
"button"
class=
"btn btn-primary btn-xs"
id=
"btn
-reset-
password"
style=
"width: 54px"
>
{% trans 'Send' %}
</button>
</span>
</td>
</tr>
...
...
@@ -164,7 +164,7 @@
<td>
{% trans 'Send reset ssh key mail' %}:
</td>
<td>
<span
class=
"pull-right"
>
<button
type=
"button"
class=
"btn btn-primary btn-xs"
id=
"btn
_reset_
pk"
style=
"width: 54px;"
>
{% trans 'Send' %}
</button>
<button
type=
"button"
class=
"btn btn-primary btn-xs"
id=
"btn
-reset-
pk"
style=
"width: 54px;"
>
{% trans 'Send' %}
</button>
</span>
</td>
</tr>
...
...
@@ -315,7 +315,7 @@ $(document).ready(function() {
return
$
(
this
).
data
(
'gid'
);
}).
get
();
updateUserGroups
(
groups
)
}).
on
(
'click'
,
'#btn
_reset_
password'
,
function
()
{
}).
on
(
'click'
,
'#btn
-reset-
password'
,
function
()
{
function
doReset
()
{
var
the_url
=
'{% url "api-users:user-reset-password" pk=user_object.id %}'
;
var
body
=
{};
...
...
@@ -340,7 +340,7 @@ $(document).ready(function() {
}, function() {
doReset();
});
}).on('
click
', '
#
btn
_reset_
pk
', function() {
}).on('
click
', '
#
btn
-
reset
-
pk
', function() {
function doReset() {
var the_url = '
{
%
url
"api-users:user-public-key-reset"
pk
=
user_object
.
id
%
}
';
var body = {};
...
...
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