Commit b0eace6a authored by ibuler's avatar ibuler

[Bugfix] 基本完成assets模块

parent b4e1ac19
...@@ -18,14 +18,16 @@ from rest_framework.response import Response ...@@ -18,14 +18,16 @@ from rest_framework.response import Response
from rest_framework_bulk import BulkModelViewSet from rest_framework_bulk import BulkModelViewSet
from rest_framework_bulk import ListBulkCreateUpdateDestroyAPIView from rest_framework_bulk import ListBulkCreateUpdateDestroyAPIView
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.db.models import Q
from common.mixins import IDInFilterMixin from common.mixins import IDInFilterMixin
from common.utils import get_object_or_none
from .hands import IsSuperUser, IsValidUser, IsSuperUserOrAppUser, \ 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 .models import AssetGroup, Asset, Cluster, SystemUser, AdminUser
from . import serializers 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): class AssetViewSet(IDInFilterMixin, BulkModelViewSet):
...@@ -51,8 +53,9 @@ class AssetViewSet(IDInFilterMixin, BulkModelViewSet): ...@@ -51,8 +53,9 @@ class AssetViewSet(IDInFilterMixin, BulkModelViewSet):
queryset = queryset.filter(groups__id=asset_group_id) queryset = queryset.filter(groups__id=asset_group_id)
if admin_user_id: if admin_user_id:
admin_user = get_object_or_404(AdminUser, id=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()] 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 return queryset
...@@ -65,15 +68,6 @@ class AssetGroupViewSet(IDInFilterMixin, BulkModelViewSet): ...@@ -65,15 +68,6 @@ class AssetGroupViewSet(IDInFilterMixin, BulkModelViewSet):
permission_classes = (IsSuperUser,) 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): class GroupUpdateAssetsApi(generics.RetrieveUpdateAPIView):
""" """
Asset group, update it's asset member Asset group, update it's asset member
...@@ -117,6 +111,18 @@ class ClusterViewSet(IDInFilterMixin, BulkModelViewSet): ...@@ -117,6 +111,18 @@ class ClusterViewSet(IDInFilterMixin, BulkModelViewSet):
permission_classes = (IsSuperUser,) 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): class ClusterAddAssetsApi(generics.UpdateAPIView):
queryset = Cluster.objects.all() queryset = Cluster.objects.all()
serializer_class = serializers.ClusterUpdateAssetsSerializer serializer_class = serializers.ClusterUpdateAssetsSerializer
...@@ -162,7 +168,7 @@ class AdminUserAddClustersApi(generics.UpdateAPIView): ...@@ -162,7 +168,7 @@ class AdminUserAddClustersApi(generics.UpdateAPIView):
return Response({'error': serializer.errors}, status=400) 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 System user api set, for add,delete,update,list,retrieve resource
""" """
...@@ -170,6 +176,10 @@ class SystemUserViewSet(IDInFilterMixin, BulkModelViewSet): ...@@ -170,6 +176,10 @@ class SystemUserViewSet(IDInFilterMixin, BulkModelViewSet):
serializer_class = serializers.SystemUserSerializer serializer_class = serializers.SystemUserSerializer
permission_classes = (IsSuperUserOrAppUser,) permission_classes = (IsSuperUserOrAppUser,)
def update(self, request, *args, **kwargs):
print(request.data)
return super().update(request, *args, **kwargs)
class AssetListUpdateApi(IDInFilterMixin, ListBulkCreateUpdateDestroyAPIView): class AssetListUpdateApi(IDInFilterMixin, ListBulkCreateUpdateDestroyAPIView):
""" """
...@@ -199,7 +209,7 @@ class SystemUserAuthInfoApi(generics.RetrieveAPIView): ...@@ -199,7 +209,7 @@ class SystemUserAuthInfoApi(generics.RetrieveAPIView):
return Response(data) return Response(data)
class AssetRefreshHardwareView(generics.RetrieveAPIView): class AssetRefreshHardwareApi(generics.RetrieveAPIView):
""" """
Refresh asset hardware info Refresh asset hardware info
""" """
...@@ -217,7 +227,7 @@ class AssetRefreshHardwareView(generics.RetrieveAPIView): ...@@ -217,7 +227,7 @@ class AssetRefreshHardwareView(generics.RetrieveAPIView):
return Response({"msg": "ok"}) return Response({"msg": "ok"})
class AssetAdminUserTestView(AssetRefreshHardwareView): class AssetAdminUserTestApi(generics.RetrieveAPIView):
""" """
Test asset admin user connectivity Test asset admin user connectivity
""" """
...@@ -227,9 +237,47 @@ class AssetAdminUserTestView(AssetRefreshHardwareView): ...@@ -227,9 +237,47 @@ class AssetAdminUserTestView(AssetRefreshHardwareView):
def retrieve(self, request, *args, **kwargs): def retrieve(self, request, *args, **kwargs):
asset_id = kwargs.get('pk') asset_id = kwargs.get('pk')
asset = get_object_or_404(Asset, pk=asset_id) asset = get_object_or_404(Asset, pk=asset_id)
result = test_admin_user_connectability_manual(asset) ok, msg = test_admin_user_connectability_manual(asset)
if result: if ok:
return Response('1') return Response({"msg": "pong"})
else: 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"})
...@@ -273,26 +273,24 @@ class SystemUserForm(forms.ModelForm): ...@@ -273,26 +273,24 @@ class SystemUserForm(forms.ModelForm):
} }
class SystemUserUpdateForm(forms.ModelForm): class SystemUserUpdateForm(SystemUserForm):
class Meta: def save(self, commit=True):
model = SystemUser # Because we define custom field, so we need rewrite :method: `save`
fields = [ password = self.cleaned_data.get('password', None)
'name', 'username', 'protocol', 'priority', private_key_file = self.cleaned_data.get('private_key_file')
'sudo', 'comment', 'shell', 'cluster' system_user = super(forms.ModelForm, self).save()
]
widgets = { if private_key_file:
'name': forms.TextInput(attrs={'placeholder': _('Name')}), print(private_key_file)
'username': forms.TextInput(attrs={'placeholder': _('Username')}), private_key = private_key_file.read().strip().decode('utf-8')
'cluster': forms.SelectMultiple( public_key = ssh_pubkey_gen(private_key=private_key)
attrs={'class': 'select2', else:
'data-placeholder': _(' Select clusters')}), private_key = public_key = None
} system_user.set_auth(password=password, private_key=private_key, public_key=public_key)
help_texts = { return system_user
'name': '* required',
'username': '* required', def clean_password(self):
'cluster': 'If auto push checked, then push system user to that cluster assets', return self.cleaned_data['password']
'priority': 'High level will be using login asset as default, if user was granted more than 2 system user',
}
class SystemUserAuthForm(forms.Form): class SystemUserAuthForm(forms.Form):
......
...@@ -116,6 +116,23 @@ class Asset(models.Model): ...@@ -116,6 +116,23 @@ class Asset(models.Model):
else: else:
return False 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): def to_json(self):
return { return {
'id': self.id, 'id': self.id,
...@@ -133,12 +150,8 @@ class Asset(models.Model): ...@@ -133,12 +150,8 @@ class Asset(models.Model):
Todo: May be move to ops implements it Todo: May be move to ops implements it
""" """
data = self.to_json() data = self.to_json()
admin_user = None if self.admin_user_avail:
if self.admin_user: admin_user = self.admin_user_avail
admin_user = self.admin_user
elif self.cluster and self.cluster.admin_user:
admin_user = self.cluster.admin_user
if admin_user:
data.update({ data.update({
'username': admin_user.username, 'username': admin_user.username,
'password': admin_user.password, 'password': admin_user.password,
......
...@@ -8,12 +8,14 @@ import uuid ...@@ -8,12 +8,14 @@ import uuid
from hashlib import md5 from hashlib import md5
import sshpubkeys import sshpubkeys
from django.core.cache import cache
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.conf import settings from django.conf import settings
from common.utils import signer, ssh_key_string_to_obj, ssh_key_gen from common.utils import signer, ssh_key_string_to_obj, ssh_key_gen
from .utils import private_key_validator from .utils import private_key_validator
from ..const import SYSTEM_USER_CONN_CACHE_KEY
__all__ = ['AdminUser', 'SystemUser',] __all__ = ['AdminUser', 'SystemUser',]
...@@ -103,6 +105,7 @@ class AssetUser(models.Model): ...@@ -103,6 +105,7 @@ class AssetUser(models.Model):
update_fields.append('_public_key') update_fields.append('_public_key')
if update_fields: if update_fields:
print(update_fields)
self.save(update_fields=update_fields) self.save(update_fields=update_fields)
def auto_gen_auth(self): def auto_gen_auth(self):
...@@ -195,7 +198,7 @@ class SystemUser(AssetUser): ...@@ -195,7 +198,7 @@ class SystemUser(AssetUser):
('P', 'Password'), ('P', 'Password'),
('K', 'Public key'), ('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 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')) protocol = models.CharField(max_length=16, choices=PROTOCOL_CHOICES, default='ssh', verbose_name=_('Protocol'))
auto_push = models.BooleanField(default=True, verbose_name=_('Auto push')) auto_push = models.BooleanField(default=True, verbose_name=_('Auto push'))
...@@ -224,6 +227,19 @@ class SystemUser(AssetUser): ...@@ -224,6 +227,19 @@ class SystemUser(AssetUser):
'auto_push': self.auto_push, '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: class Meta:
ordering = ['name'] ordering = ['name']
......
...@@ -25,17 +25,6 @@ class AssetGroupSerializer(BulkSerializerMixin, serializers.ModelSerializer): ...@@ -25,17 +25,6 @@ class AssetGroupSerializer(BulkSerializerMixin, serializers.ModelSerializer):
return obj.assets.count() 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): class AssetUpdateSystemUserSerializer(serializers.ModelSerializer):
""" """
资产更新其系统用户请求的数据结构定义 资产更新其系统用户请求的数据结构定义
...@@ -90,11 +79,7 @@ class AdminUserSerializer(serializers.ModelSerializer): ...@@ -90,11 +79,7 @@ class AdminUserSerializer(serializers.ModelSerializer):
@staticmethod @staticmethod
def get_assets_amount(obj): def get_assets_amount(obj):
amount = 0 return obj.assets_amount
clusters = obj.cluster_set.all()
for cluster in clusters:
amount += len(cluster.assets.all())
return amount
class SystemUserSerializer(serializers.ModelSerializer): class SystemUserSerializer(serializers.ModelSerializer):
...@@ -102,6 +87,9 @@ class SystemUserSerializer(serializers.ModelSerializer): ...@@ -102,6 +87,9 @@ class SystemUserSerializer(serializers.ModelSerializer):
系统用户 系统用户
""" """
unreachable_amount = serializers.SerializerMethodField() unreachable_amount = serializers.SerializerMethodField()
reachable_amount = serializers.SerializerMethodField()
unreachable_assets = serializers.SerializerMethodField()
reachable_assets = serializers.SerializerMethodField()
assets_amount = serializers.SerializerMethodField() assets_amount = serializers.SerializerMethodField()
class Meta: class Meta:
...@@ -109,12 +97,18 @@ class SystemUserSerializer(serializers.ModelSerializer): ...@@ -109,12 +97,18 @@ class SystemUserSerializer(serializers.ModelSerializer):
exclude = ('_password', '_private_key', '_public_key') exclude = ('_password', '_private_key', '_public_key')
@staticmethod @staticmethod
def get_unreachable_amount(obj): def get_unreachable_assets(obj):
data = cache.get(SYSTEM_USER_CONN_CACHE_KEY.format(obj.name)) return obj.unreachable_assets
if data:
return len(data.get('dark')) @staticmethod
else: def get_reachable_assets(obj):
return "Unknown" 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 @staticmethod
def get_assets_amount(obj): def get_assets_amount(obj):
......
...@@ -181,10 +181,10 @@ def test_admin_user_connectability_manual(asset, task_name=None): ...@@ -181,10 +181,10 @@ def test_admin_user_connectability_manual(asset, task_name=None):
if result.results_summary['dark']: if result.results_summary['dark']:
cache.set(const.ASSET_ADMIN_CONN_CACHE_KEY.format(asset.hostname), 0, CACHE_MAX_TIME) cache.set(const.ASSET_ADMIN_CONN_CACHE_KEY.format(asset.hostname), 0, CACHE_MAX_TIME)
return False return False, result.results_summary['dark']
else: else:
cache.set(const.ASSET_ADMIN_CONN_CACHE_KEY.format(asset.hostname), 1, CACHE_MAX_TIME) cache.set(const.ASSET_ADMIN_CONN_CACHE_KEY.format(asset.hostname), 1, CACHE_MAX_TIME)
return True return True, ""
@shared_task @shared_task
...@@ -211,7 +211,8 @@ def test_system_user_connectability(system_user, force=False): ...@@ -211,7 +211,8 @@ def test_system_user_connectability(system_user, force=False):
) )
cache.set(lock_key, 1, CACHE_MAX_TIME) cache.set(lock_key, 1, CACHE_MAX_TIME)
result = task.run() 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) cache.set(cache_key, result.results_summary, CACHE_MAX_TIME)
return result.results_summary return result.results_summary
...@@ -369,7 +370,7 @@ def update_asset_info_when_created(sender, instance=None, created=False, **kwarg ...@@ -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") @receiver(post_save, sender=Asset, dispatch_uid="my_unique_identifier")
def update_asset_conn_info_when_created(sender, instance=None, created=False, **kwargs): def update_asset_conn_info_on_created(sender, instance=None, created=False, **kwargs):
if instance and created: if instance and created:
task_name = 'TEST-ASSET-CONN-WHEN-CREATED-{}'.format(instance) task_name = 'TEST-ASSET-CONN-WHEN-CREATED-{}'.format(instance)
msg = "Receive asset {} create signal, test asset connectability".format( 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, ** ...@@ -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") @receiver(post_save, sender=Asset, dispatch_uid="my_unique_identifier")
def push_system_user_when_created(sender, instance=None, created=False, **kwargs): def push_system_user_on_created(sender, instance=None, created=False, **kwargs):
if instance and created: if instance and created:
task_name = 'PUSH-SYSTEM-USER-WHEN-ASSET-CREATED-{}'.format(instance) task_name = 'PUSH-SYSTEM-USER-WHEN-ASSET-CREATED-{}'.format(instance)
system_users = instance.cluster.systemuser_set.all() system_users = instance.cluster.systemuser_set.all()
...@@ -392,15 +393,7 @@ def push_system_user_when_created(sender, instance=None, created=False, **kwargs ...@@ -392,15 +393,7 @@ def push_system_user_when_created(sender, instance=None, created=False, **kwargs
@receiver(post_save, sender=SystemUser) @receiver(post_save, sender=SystemUser)
def push_system_user_on_change(sender, instance=None, created=False, **kwargs): def push_system_user_on_auth_change(sender, instance=None, update_fields=None, **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):
fields_check = {'_password', '_private_key', '_public_key'} fields_check = {'_password', '_private_key', '_public_key'}
auth_changed = update_fields & fields_check if update_fields else None auth_changed = update_fields & fields_check if update_fields else None
if instance and instance.auto_push and auth_changed: if instance and instance.auto_push and auth_changed:
......
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
<th>{% trans 'IP' %}</th> <th>{% trans 'IP' %}</th>
<th>{% trans 'Port' %}</th> <th>{% trans 'Port' %}</th>
<th>{% trans 'Type' %}</th> <th>{% trans 'Type' %}</th>
<th>{% trans 'Valid' %}</th> <th>{% trans 'Alive' %}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
...@@ -78,10 +78,10 @@ ...@@ -78,10 +78,10 @@
<table class="table"> <table class="table">
<tbody> <tbody>
<tr class="no-borders-tr"> <tr class="no-borders-tr">
<td width="50%">{% trans 'Retest connectivity' %}:</td> <td width="50%">{% trans 'Test connective' %}:</td>
<td> <td>
<span style="float: right"> <span style="float: right">
<button type="button" class="btn btn-primary btn-xs" style="width: 54px">{% trans 'Start' %}</button> <button type="button" class="btn btn-primary btn-xs btn-test-connective" style="width: 54px">{% trans 'Test' %}</button>
</span> </span>
</td> </td>
</tr> </tr>
...@@ -98,56 +98,6 @@ ...@@ -98,56 +98,6 @@
{% endblock %} {% endblock %}
{% block custom_foot_js %} {% block custom_foot_js %}
<script> <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() { function initTable() {
var options = { var options = {
...@@ -168,56 +118,13 @@ function initTable() { ...@@ -168,56 +118,13 @@ function initTable() {
}}], }}],
ajax_url: '{% url "api-assets:asset-list" %}?admin_user_id={{ admin_user.id }}', ajax_url: '{% url "api-assets:asset-list" %}?admin_user_id={{ admin_user.id }}',
columns: [{data: function(){return ""}}, {data: "hostname" }, {data: "ip" }, {data: "port" }, columns: [{data: function(){return ""}}, {data: "hostname" }, {data: "ip" }, {data: "port" },
{data: "type" }, {data: "is_active" }], {data: "type" }, {data: "is_connective" }],
op_html: $('#actions').html() op_html: $('#actions').html()
}; };
jumpserver.initDataTable(options); 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 () { $(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(); initTable();
}) })
.on('click', '.btn-delete-admin-user', function () { .on('click', '.btn-delete-admin-user', function () {
...@@ -228,5 +135,17 @@ $(document).ready(function () { ...@@ -228,5 +135,17 @@ $(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-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> </script>
{% endblock %} {% endblock %}
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
</ul> </ul>
</div> </div>
<div class="tab-content"> <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 float-e-margins">
<div class="ibox-title"> <div class="ibox-title">
<span class="label"><b>{{ admin_user.name }}</b></span> <span class="label"><b>{{ admin_user.name }}</b></span>
...@@ -77,26 +77,8 @@ ...@@ -77,26 +77,8 @@
</div> </div>
</div> </div>
</div> </div>
<div class="col-sm-4" style="padding-left: 0;padding-right: 0"> <div class="col-sm-5" 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="panel panel-info"> <div class="panel panel-info">
<div class="panel-heading"> <div class="panel-heading">
<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' %}
......
...@@ -71,8 +71,8 @@ ...@@ -71,8 +71,8 @@
</tr> </tr>
<tr> <tr>
<td>{% trans 'Admin user' %}:</td> <td>{% trans 'Admin user' %}:</td>
{% if asset.admin_user %} {% if asset.admin_user_avail %}
<td><b>{{ asset.admin_user.name }}</b></td> <td><b>{{ asset.admin_user_avail.name }}</b></td>
{% else %} {% else %}
<td><b>None</b></td> <td><b>None</b></td>
{% endif %} {% endif %}
...@@ -195,6 +195,14 @@ ...@@ -195,6 +195,14 @@
</span> </span>
</td> </td>
</tr> </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> </tbody>
</table> </table>
</div> </div>
...@@ -248,7 +256,7 @@ ...@@ -248,7 +256,7 @@
<script> <script>
jumpserver.groups_selected = {}; jumpserver.groups_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-detail' pk=asset.id %}";
var body = { var body = {
groups: Object.assign([], groups) groups: Object.assign([], groups)
}; };
...@@ -355,14 +363,18 @@ $(document).ready(function () { ...@@ -355,14 +363,18 @@ $(document).ready(function () {
}).on('click', '#btn_refresh_asset', function () { }).on('click', '#btn_refresh_asset', function () {
alert('关闭alert, 等待完成, 自动刷新页面'); alert('关闭alert, 等待完成, 自动刷新页面');
refreshAssetHardware() refreshAssetHardware()
}).on('click', '#btn_test_admin_user', function () { }).on('click', '#btn-test-is-alive', function () {
$.ajax({ var the_url = "{% url 'api-assets:asset-alive-test' pk=asset.id %}";
url: '{% url "api-assets:asset-admin-user-test" pk=asset.id %}' var error = function (data) {
}).done(function (data, textStatue, jqXHR) { alert(data)
toastr.success('Success') };
}).fail(function (data, textStaue, errorThrown) { alert('关闭alert, 等待完成');
toastr.error('Error') APIUpdateAttr({
}) url: the_url,
error: error,
method: 'GET',
success_message: "{% trans "Pong" %}"
});
}) })
</script> </script>
......
...@@ -64,6 +64,25 @@ ...@@ -64,6 +64,25 @@
</div> </div>
<div class="col-sm-4" style="padding-left: 0;padding-right: 0"> <div class="col-sm-4" style="padding-left: 0;padding-right: 0">
<div class="panel panel-primary"> <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"> <div class="panel-heading">
<i class="fa fa-info-circle"></i> {% trans 'Add assets to' %} {{ cluster.name }} <i class="fa fa-info-circle"></i> {% trans 'Add assets to' %} {{ cluster.name }}
</div> </div>
...@@ -173,7 +192,6 @@ $(document).ready(function () { ...@@ -173,7 +192,6 @@ $(document).ready(function () {
}); });
initTable(); initTable();
}) })
.on('click', '.btn-add-assets', function () { .on('click', '.btn-add-assets', function () {
if (Object.keys(jumpserver.assets_selected).length === 0) { if (Object.keys(jumpserver.assets_selected).length === 0) {
return false; return false;
...@@ -185,5 +203,8 @@ $(document).ready(function () { ...@@ -185,5 +203,8 @@ $(document).ready(function () {
addAssets(assets_id); addAssets(assets_id);
}) })
.on('click', '#btn-test-assets', function () {
console.log('ok');
})
</script> </script>
{% endblock %} {% endblock %}
...@@ -102,6 +102,44 @@ ...@@ -102,6 +102,44 @@
</div> </div>
</div> </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> </div>
</div> </div>
...@@ -111,46 +149,16 @@ ...@@ -111,46 +149,16 @@
{% endblock %} {% endblock %}
{% block custom_foot_js %} {% block custom_foot_js %}
<script> <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 () { $(document).ready(function () {
$('.select2').select2(); $('.select2').select2();
}) })
.on('click', '.btn-delete-cluster', function () { .on('click', '.btn-delete-cluster', function () {
var name = $('.cluster-details > tbody > tr').attr("data-name"); var name = "{{ cluster.name }}";
var id = {{ cluster.id }}; var id = "{{ cluster.id }}";
var the_url = '{% url "api-assets:cluster-detail" pk=DEFAULT_PK %}'.replace("{{ DEFAULT_PK }}", 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> </script>
{% endblock %} {% endblock %}
...@@ -16,11 +16,6 @@ ...@@ -16,11 +16,6 @@
<li> <li>
<a href="{% url 'assets:system-user-detail' pk=system_user.id %}" class="text-center"><i class="fa fa-laptop"></i> {% trans 'Detail' %} </a> <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>
<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"> <li class="active">
<a href="{% url 'assets:system-user-asset' pk=system_user.id %}" class="text-center"> <a href="{% url 'assets:system-user-asset' pk=system_user.id %}" class="text-center">
<i class="fa fa-bar-chart-o"></i> {% trans 'Assets' %} <i class="fa fa-bar-chart-o"></i> {% trans 'Assets' %}
...@@ -78,15 +73,15 @@ ...@@ -78,15 +73,15 @@
<td width="50%">{% trans 'Push system user manually' %}:</td> <td width="50%">{% trans 'Push system user manually' %}:</td>
<td> <td>
<span style="float: right"> <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> </span>
</td> </td>
</tr> </tr>
<tr> <tr>
<td width="50%">{% trans 'Refresh assets connectivity' %}:</td> <td width="50%">{% trans 'Test assets connective' %}:</td>
<td> <td>
<span style="float: right"> <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> </span>
</td> </td>
</tr> </tr>
...@@ -103,26 +98,8 @@ ...@@ -103,26 +98,8 @@
{% endblock %} {% endblock %}
{% block custom_foot_js %} {% block custom_foot_js %}
<script> <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() { function initAssetsTable() {
var unreachable = {{ system_user.unreachable_assets|safe}};
var options = { var options = {
ele: $('#system_user_list'), ele: $('#system_user_list'),
buttons: [], buttons: [],
...@@ -133,7 +110,7 @@ function initAssetsTable() { ...@@ -133,7 +110,7 @@ function initAssetsTable() {
$(td).html(detail_btn.replace('{{ DEFAULT_PK }}', rowData.id)); $(td).html(detail_btn.replace('{{ DEFAULT_PK }}', rowData.id));
}}, }},
{targets: 3, createdCell: function (td, cellData) { {targets: 3, createdCell: function (td, cellData) {
if (!cellData) { if (unreachable.indexOf(cellData) >= 0) {
$(td).html('<i class="fa fa-times text-danger"></i>') $(td).html('<i class="fa fa-times text-danger"></i>')
} else { } else {
$(td).html('<i class="fa fa-check text-navy"></i>') $(td).html('<i class="fa fa-check text-navy"></i>')
...@@ -141,67 +118,12 @@ function initAssetsTable() { ...@@ -141,67 +118,12 @@ function initAssetsTable() {
}} }}
], ],
ajax_url: '{% url "api-assets:asset-list" %}?system_user_id={{ system_user.id }}', ajax_url: '{% url "api-assets:asset-list" %}?system_user_id={{ system_user.id }}',
columns: [{data: "hostname" }, {data: "ip" }, {data: "port" }, {data: "is_connective" }], columns: [{data: "hostname" }, {data: "ip" }, {data: "port" }, {data: "hostname" }],
op_html: $('#actions').html() op_html: $('#actions').html()
}; };
jumpserver.initDataTable(options); 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 () { $(document).ready(function () {
$('.select2').select2() $('.select2').select2()
.on("select2:select", function (evt) { .on("select2:select", function (evt) {
...@@ -216,106 +138,30 @@ $(document).ready(function () { ...@@ -216,106 +138,30 @@ $(document).ready(function () {
}); });
initAssetsTable(); initAssetsTable();
}) })
.on('click', '.btn-push', function () {
.on('click', '.btn-add-asset2system-user', function () { var the_url = "{% url 'api-assets:system-user-push' pk=system_user.id %}";
if (Object.keys(jumpserver.assets_selected).length === 0) { var error = function (data) {
return false; alert(data)
} };
var $data_table = $("#system_user_list").DataTable(); APIUpdateAttr({
var assets = []; url: the_url,
$.ajax({ error: error,
url: '{% url "api-assets:asset-list" %}?system_user_id={{ system_user.id }}', method: 'GET',
method: 'GET', success_message: "{% trans "Task has been send, Go to ops task list seen result" %}"
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};
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-test-connective', function () {
.on('click', '#btn_add_user_group', function () { var the_url = "{% url 'api-assets:system-user-connective' pk=system_user.id %}";
jumpserver.assets_selected = {}; var error = function (data) {
if (Object.keys(jumpserver.asset_groups_selected).length === 0) { alert(data)
return false; };
} APIUpdateAttr({
asset_groups = []; url: the_url,
$.ajax({ error: error,
url: '{% url "api-assets:systemuser-update-assetgroups" pk=system_user.id %}', method: 'GET',
method: 'GET', success_message: "{% trans "Task has been send, seen left assets status" %}"
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));
});
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};
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 %}"#}
}
});
}) })
.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);
});
......
{% 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 %}
...@@ -17,11 +17,6 @@ ...@@ -17,11 +17,6 @@
<li class="active"> <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> <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>
<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> <li>
<a href="{% url 'assets:system-user-asset' pk=system_user.id %}" class="text-center"> <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' %} <i class="fa fa-bar-chart-o"></i> {% trans 'Attached assets' %}
...@@ -120,8 +115,8 @@ ...@@ -120,8 +115,8 @@
<span class="pull-right"> <span class="pull-right">
<div class="switch"> <div class="switch">
<div class="onoffswitch"> <div class="onoffswitch">
<input type="checkbox" {% if system_user.auto_push %} checked {% endif %} class="onoffswitch-checkbox" id="is_active"> <input type="checkbox" {% if system_user.auto_push %} checked {% endif %} class="onoffswitch-checkbox" id="btn-auto-push">
<label class="onoffswitch-label" for="is_active"> <label class="onoffswitch-label" for="btn-auto-push">
<span class="onoffswitch-inner"></span> <span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span> <span class="onoffswitch-switch"></span>
</label> </label>
...@@ -147,12 +142,12 @@ ...@@ -147,12 +142,12 @@
<i class="fa fa-info-circle"></i> {% trans 'Clusters' %} <i class="fa fa-info-circle"></i> {% trans 'Clusters' %}
</div> </div>
<div class="panel-body"> <div class="panel-body">
<table class="table group_edit" id="add-asset2group"> <table class="table cluster_edit" id="add-asset2group">
<tbody> <tbody>
<form> <form>
<tr> <tr>
<td colspan="2" class="no-borders"> <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 %} {% 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 %}
...@@ -161,16 +156,16 @@ ...@@ -161,16 +156,16 @@
</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-to-cluster">{% trans 'Confirm' %}</button>
</td> </td>
</tr> </tr>
</form> </form>
{% for cluster in system_user.cluster.all %} {% for cluster in system_user.cluster.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> <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> </td>
</tr> </tr>
{% endfor %} {% endfor %}
...@@ -186,27 +181,84 @@ ...@@ -186,27 +181,84 @@
</div> </div>
{% endblock %} {% endblock %}
{% block custom_foot_js %} {% block custom_foot_js %}
<script> <script>
// Todo: 添加自动推送的js function updateSystemUserCluster(clusters) {
{# function switch_user_status(obj) {#} var the_url = "{% url 'api-assets:system-user-detail' pk=system_user.id %}";
{# var status = $(obj).prop('checked');#} var body = {
{##} cluster: Object.assign([], clusters)
{# $.ajax({#} };
{# url: "{% url 'users:user-active-api' pk=user.id %}",#} var success = function(data) {
{# type: "PUT",#} // remove all the selected groups from select > option and rendered ul element;
{# data: {#} $('.select2-selection__rendered').empty();
{# 'is_active': status#} $('#cluster_selected').val('');
{# },#} $.map(jumpserver.cluster_selected, function(cluster_name, index) {
{# success: function (data, status) {#} $('#opt_' + index).remove();
{# console.log(data)#} // change tr html of user groups.
{# },#} $('.cluster_edit tbody').append(
{# error: function () {#} '<tr>' +
{# console.log('error')#} '<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>'
{# }#} )
$(document).ready(function () {
$('.select2').select2();
}); });
</script> // 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);
});
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 %} {% endblock %}
...@@ -17,7 +17,9 @@ ...@@ -17,7 +17,9 @@
<th class="text-center">{% trans 'Name' %}</th> <th class="text-center">{% trans 'Name' %}</th>
<th class="text-center">{% trans 'Username' %}</th> <th class="text-center">{% trans 'Username' %}</th>
<th class="text-center">{% trans 'Asset' %}</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 'Unreachable' %}</th>
<th class="text-center">{% trans 'Ratio' %}</th>
<th class="text-center">{% trans 'Comment' %}</th> <th class="text-center">{% trans 'Comment' %}</th>
<th class="text-center">{% trans 'Action' %}</th> <th class="text-center">{% trans 'Action' %}</th>
</tr> </tr>
...@@ -25,19 +27,6 @@ ...@@ -25,19 +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>
<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 %} {% endblock %}
{% block custom_foot_js %} {% block custom_foot_js %}
<script> <script>
...@@ -49,19 +38,52 @@ $(document).ready(function(){ ...@@ -49,19 +38,52 @@ $(document).ready(function(){
var detail_btn = '<a href="{% url "assets:system-user-detail" pk=DEFAULT_PK %}">' + cellData + '</a>'; var detail_btn = '<a href="{% url "assets:system-user-detail" pk=DEFAULT_PK %}">' + cellData + '</a>';
$(td).html(detail_btn.replace('{{ DEFAULT_PK }}', rowData.id)); $(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) { {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>'); $(td).html('<span href="javascript:void(0);" data-toggle="tooltip" title="' + cellData + '">' + innerHtml + '</span>');
}}, }},
{targets: 6, createdCell: function (td, cellData, rowData) { {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 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 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); 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) $(td).html(update_btn + del_btn)
}}], }}],
ajax_url: '{% url "api-assets:system-user-list" %}', ajax_url: '{% url "api-assets:system-user-list" %}',
columns: [{data: "id" }, {data: "name" }, {data: "username" }, {data: "assets_amount" }, {data: "unreachable_amount"}, columns: [
{data: "comment" }, {data: "id" }], {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() op_html: $('#actions').html()
}; };
jumpserver.initDataTable(options); jumpserver.initDataTable(options);
......
...@@ -4,6 +4,15 @@ ...@@ -4,6 +4,15 @@
{% load bootstrap3 %} {% load bootstrap3 %}
{% block auth %} {% 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 %} {% endblock %}
{% block custom_foot_js %} {% block custom_foot_js %}
......
...@@ -17,12 +17,10 @@ urlpatterns = [ ...@@ -17,12 +17,10 @@ urlpatterns = [
url(r'^v1/assets-bulk/$', api.AssetListUpdateApi.as_view(), name='asset-bulk-update'), 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(), url(r'^v1/system-user/(?P<pk>[0-9a-zA-Z\-]{36})/auth-info/', api.SystemUserAuthInfoApi.as_view(),
name='system-user-auth-info'), 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/$', url(r'^v1/assets/(?P<pk>[0-9a-zA-Z\-]{36})/refresh/$',
api.AssetRefreshHardwareView.as_view(), name='asset-refresh'), api.AssetRefreshHardwareApi.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})/alive/$',
api.AssetAdminUserTestView.as_view(), name='asset-admin-user-test'), api.AssetAdminUserTestApi.as_view(), name='asset-alive-test'),
# 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.GroupUpdateAssetsApi.as_view(), name='group-update-assets'), api.GroupUpdateAssetsApi.as_view(), name='group-update-assets'),
...@@ -35,6 +33,12 @@ urlpatterns = [ ...@@ -35,6 +33,12 @@ urlpatterns = [
api.ClusterAddAssetsApi.as_view(), name='cluster-add-assets'), api.ClusterAddAssetsApi.as_view(), name='cluster-add-assets'),
url(r'^v1/admin-user/(?P<pk>[0-9a-zA-Z\-]{36})/clusters/$', url(r'^v1/admin-user/(?P<pk>[0-9a-zA-Z\-]{36})/clusters/$',
api.AdminUserAddClustersApi.as_view(), name='admin-user-add-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 urlpatterns += router.urls
......
...@@ -50,7 +50,6 @@ urlpatterns = [ ...@@ -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})/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})/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})/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(), # url(r'^system-user/(?P<pk>[0-9a-zA-Z\-]{36})/asset-group$', views.SystemUserAssetGroupView.as_view(),
# name='system-user-asset-group'), # name='system-user-asset-group'),
......
...@@ -106,7 +106,7 @@ class AdminUserAssetsView(AdminUserRequiredMixin, SingleObjectMixin, ListView): ...@@ -106,7 +106,7 @@ class AdminUserAssetsView(AdminUserRequiredMixin, SingleObjectMixin, ListView):
def get_queryset(self): def get_queryset(self):
queryset = [] queryset = []
for cluster in self.object.cluster_set.all(): 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 self.queryset = queryset
return queryset return queryset
...@@ -115,7 +115,7 @@ class AdminUserAssetsView(AdminUserRequiredMixin, SingleObjectMixin, ListView): ...@@ -115,7 +115,7 @@ class AdminUserAssetsView(AdminUserRequiredMixin, SingleObjectMixin, ListView):
'app': 'assets', 'app': 'assets',
'action': 'Admin user detail', 'action': 'Admin user detail',
"total_amount": len(self.queryset), "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) kwargs.update(context)
return super().get_context_data(**kwargs) return super().get_context_data(**kwargs)
......
...@@ -24,7 +24,7 @@ class ClusterListView(AdminUserRequiredMixin, TemplateView): ...@@ -24,7 +24,7 @@ class ClusterListView(AdminUserRequiredMixin, TemplateView):
# 'keyword': self.request.GET.get('keyword', '') # 'keyword': self.request.GET.get('keyword', '')
} }
kwargs.update(context) kwargs.update(context)
return super(ClusterListView, self).get_context_data(**kwargs) return super().get_context_data(**kwargs)
class ClusterCreateView(AdminUserRequiredMixin, CreateView): class ClusterCreateView(AdminUserRequiredMixin, CreateView):
...@@ -39,13 +39,13 @@ class ClusterCreateView(AdminUserRequiredMixin, CreateView): ...@@ -39,13 +39,13 @@ class ClusterCreateView(AdminUserRequiredMixin, CreateView):
'action': _('Create Cluster'), 'action': _('Create Cluster'),
} }
kwargs.update(context) kwargs.update(context)
return super(ClusterCreateView, self).get_context_data(**kwargs) return super().get_context_data(**kwargs)
def form_valid(self, form): def form_valid(self, form):
cluster = form.save(commit=False) cluster = form.save(commit=False)
cluster.created_by = self.request.user.username or 'System' cluster.created_by = self.request.user.username or 'System'
cluster.save() cluster.save()
return super(ClusterCreateView, self).form_valid(form) return super().form_valid(form)
class ClusterUpdateView(AdminUserRequiredMixin, UpdateView): class ClusterUpdateView(AdminUserRequiredMixin, UpdateView):
...@@ -58,7 +58,7 @@ class ClusterUpdateView(AdminUserRequiredMixin, UpdateView): ...@@ -58,7 +58,7 @@ class ClusterUpdateView(AdminUserRequiredMixin, UpdateView):
def form_valid(self, form): def form_valid(self, form):
cluster = form.save(commit=False) cluster = form.save(commit=False)
cluster.save() cluster.save()
return super(ClusterUpdateView, self).form_valid(form) return super().form_valid(form)
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = { context = {
...@@ -66,7 +66,7 @@ class ClusterUpdateView(AdminUserRequiredMixin, UpdateView): ...@@ -66,7 +66,7 @@ class ClusterUpdateView(AdminUserRequiredMixin, UpdateView):
'action': _('Update Cluster'), 'action': _('Update Cluster'),
} }
kwargs.update(context) kwargs.update(context)
return super(ClusterUpdateView, self).get_context_data(**kwargs) return super().get_context_data(**kwargs)
class ClusterDetailView(AdminUserRequiredMixin, DetailView): class ClusterDetailView(AdminUserRequiredMixin, DetailView):
...@@ -74,6 +74,16 @@ class ClusterDetailView(AdminUserRequiredMixin, DetailView): ...@@ -74,6 +74,16 @@ class ClusterDetailView(AdminUserRequiredMixin, DetailView):
template_name = 'assets/cluster_detail.html' template_name = 'assets/cluster_detail.html'
context_object_name = 'cluster' 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): class ClusterAssetsView(AdminUserRequiredMixin, DetailView):
model = Cluster model = Cluster
...@@ -92,7 +102,7 @@ class ClusterAssetsView(AdminUserRequiredMixin, DetailView): ...@@ -92,7 +102,7 @@ class ClusterAssetsView(AdminUserRequiredMixin, DetailView):
'assets': [asset for asset in Asset.objects.all() if asset not in assets_remain], 'assets': [asset for asset in Asset.objects.all() if asset not in assets_remain],
} }
kwargs.update(context) kwargs.update(context)
return super(ClusterAssetsView, self).get_context_data(**kwargs) return super().get_context_data(**kwargs)
class ClusterDeleteView(AdminUserRequiredMixin, DeleteView): class ClusterDeleteView(AdminUserRequiredMixin, DeleteView):
......
...@@ -18,7 +18,6 @@ from ..hands import AdminUserRequiredMixin ...@@ -18,7 +18,6 @@ from ..hands import AdminUserRequiredMixin
__all__ = ['SystemUserCreateView', 'SystemUserUpdateView', __all__ = ['SystemUserCreateView', 'SystemUserUpdateView',
'SystemUserDetailView', 'SystemUserDeleteView', 'SystemUserDetailView', 'SystemUserDeleteView',
'SystemUserAssetView', 'SystemUserListView', 'SystemUserAssetView', 'SystemUserListView',
'SystemUserAuthView',
] ]
...@@ -115,35 +114,3 @@ class SystemUserAssetView(AdminUserRequiredMixin, DetailView): ...@@ -115,35 +114,3 @@ class SystemUserAssetView(AdminUserRequiredMixin, DetailView):
} }
kwargs.update(context) kwargs.update(context)
return super().get_context_data(**kwargs) 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)
...@@ -156,7 +156,7 @@ ...@@ -156,7 +156,7 @@
<td>{% trans 'Send reset password mail' %}:</td> <td>{% trans 'Send reset password mail' %}:</td>
<td> <td>
<span class="pull-right"> <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> </span>
</td> </td>
</tr> </tr>
...@@ -164,7 +164,7 @@ ...@@ -164,7 +164,7 @@
<td>{% trans 'Send reset ssh key mail' %}:</td> <td>{% trans 'Send reset ssh key mail' %}:</td>
<td> <td>
<span class="pull-right"> <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> </span>
</td> </td>
</tr> </tr>
...@@ -315,7 +315,7 @@ $(document).ready(function() { ...@@ -315,7 +315,7 @@ $(document).ready(function() {
return $(this).data('gid'); return $(this).data('gid');
}).get(); }).get();
updateUserGroups(groups) updateUserGroups(groups)
}).on('click', '#btn_reset_password', function() { }).on('click', '#btn-reset-password', function() {
function doReset() { function doReset() {
var the_url = '{% url "api-users:user-reset-password" pk=user_object.id %}'; var the_url = '{% url "api-users:user-reset-password" pk=user_object.id %}';
var body = {}; var body = {};
...@@ -340,7 +340,7 @@ $(document).ready(function() { ...@@ -340,7 +340,7 @@ $(document).ready(function() {
}, function() { }, function() {
doReset(); doReset();
}); });
}).on('click', '#btn_reset_pk', function() { }).on('click', '#btn-reset-pk', function() {
function doReset() { function doReset() {
var the_url = '{% url "api-users:user-public-key-reset" pk=user_object.id %}'; var the_url = '{% url "api-users:user-public-key-reset" pk=user_object.id %}';
var body = {}; var body = {};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment