diff --git a/apps/assets/templates/assets/admin_user_create_update.html b/apps/assets/templates/assets/admin_user_create_update.html index 5a2f3d6c9..c94a67a9e 100644 --- a/apps/assets/templates/assets/admin_user_create_update.html +++ b/apps/assets/templates/assets/admin_user_create_update.html @@ -70,8 +70,6 @@ $(document).ready(function () { {% endif %} var form = $("form"); var data = form.serializeObject(); - console.log($("#id_private_key").data("file")); - data["private_key"] = $("#id_private_key").data('file'); var props = { diff --git a/apps/assets/templates/assets/asset_list.html b/apps/assets/templates/assets/asset_list.html index 0cdcb176a..a20d4f35f 100644 --- a/apps/assets/templates/assets/asset_list.html +++ b/apps/assets/templates/assets/asset_list.html @@ -346,8 +346,8 @@ $(document).ready(function(){ var data = { 'resources': id_list }; - function refreshTag() { - $('#asset_list_table').DataTable().ajax.reload(); + function refreshPage() { + setTimeout( function () {window.location.reload();}, 300); } function doDeactive() { @@ -356,15 +356,11 @@ $(document).ready(function(){ var obj = {"pk": object_id, "is_active": false}; data.push(obj); }); - function success() { - setTimeout( function () { - window.location.reload();}, 500); - } requestApi({ url: the_url, method: 'PATCH', body: JSON.stringify(data), - success: success + success: refreshPage }); } function doActive() { @@ -373,15 +369,11 @@ $(document).ready(function(){ var obj = {"pk": object_id, "is_active": true}; data.push(obj); }); - function success() { - setTimeout( function () { - window.location.reload();}, 300); - } requestApi({ url: the_url, method: 'PATCH', body: JSON.stringify(data), - success: success + success: refreshPage }); } function doDelete() { @@ -400,7 +392,7 @@ $(document).ready(function(){ requestApi({ url:url, method:'DELETE', - success:refreshTag, + success:refreshPage, flash_message:false, }); var msg = "{% trans 'Asset Deleted.' %}"; diff --git a/apps/assets/templates/assets/system_user_list.html b/apps/assets/templates/assets/system_user_list.html index 621e18201..b48226f41 100644 --- a/apps/assets/templates/assets/system_user_list.html +++ b/apps/assets/templates/assets/system_user_list.html @@ -78,43 +78,9 @@ function initTable() { var detail_btn = '' + cellData + ''; $(td).html(detail_btn.replace('{{ DEFAULT_PK }}', rowData.id)); }}, - {#{targets: 6, createdCell: function (td, cellData) {#} - {# var innerHtml = "";#} - {# var data = cellData.reachable;#} - {# if (data !== 0) {#} - {# innerHtml = "" + data + "";#} - {# } else {#} - {# innerHtml = "" + data + "";#} - {# }#} - {# $(td).html(innerHtml)#} - {#}},#} - {#{targets: 7, createdCell: function (td, cellData) {#} - {# var data = cellData.unreachable;#} - {# var innerHtml = "";#} - {# if (data !== 0) {#} - {# innerHtml = "" + data + "";#} - {# } else {#} - {# innerHtml = "" + data + "";#} - {# }#} - {# $(td).html('' + innerHtml + '');#} - {#}},#} - {#{targets: 8, createdCell: function (td, cellData, rowData) {#} - {# var val = 0;#} - {# var innerHtml = "";#} - {# var total = rowData.assets_amount;#} - {# var reachable = cellData.reachable;#} - {# if (total && total !== 0) {#} - {# val = reachable/total * 100;#} - {# }#} - {##} - {# if (val === 100) {#} - {# innerHtml = "" + val + "% ";#} - {# } else {#} - {# var num = new Number(val);#} - {# innerHtml = "" + num.toFixed(1) + "% ";#} - {# }#} - {# $(td).html('' + innerHtml + '');#} - {#}},#} + {targets: 4, createdCell: function (td, cellData, rowData) { + $(td).html(rowData.login_mode_display); + }}, {targets: 7, createdCell: function (td, cellData, rowData) { var update_btn = '{% trans "Update" %}'.replace('{{ DEFAULT_PK }}', cellData); var del_btn = '{% trans "Delete" %}'.replace('{{ DEFAULT_PK }}', cellData); @@ -123,8 +89,9 @@ function initTable() { ], ajax_url: '{% url "api-assets:system-user-list" %}', columns: [ - {data: "id" }, {data: "name" }, {data: "username" }, {data: "protocol"}, {data: "login_mode_display"}, {data: "assets_amount" }, - {data: "comment" }, {data: "id" } + {data: "id" }, {data: "name" }, {data: "username" }, {data: "protocol"}, + {data: "login_mode"}, {data: "assets_amount", orderable: false }, + {data: "comment" }, {data: "id", orderable: false } ], op_html: $('#actions').html() }; diff --git a/apps/jumpserver/views.py b/apps/jumpserver/views.py index 9ad8f7b39..f9d692f31 100644 --- a/apps/jumpserver/views.py +++ b/apps/jumpserver/views.py @@ -100,13 +100,19 @@ class IndexView(PermissionsMixin, TemplateView): return self.session_month.values('user').distinct().count() def get_month_inactive_user_total(self): - return current_org.get_org_users().count() - self.get_month_active_user_total() + count = current_org.get_org_users().count() - self.get_month_active_user_total() + if count < 0: + count = 0 + return count def get_month_active_asset_total(self): return self.session_month.values('asset').distinct().count() def get_month_inactive_asset_total(self): - return Asset.objects.all().count() - self.get_month_active_asset_total() + count = Asset.objects.all().count() - self.get_month_active_asset_total() + if count < 0: + count = 0 + return count @staticmethod def get_user_disabled_total(): @@ -180,6 +186,7 @@ class IndexView(PermissionsMixin, TemplateView): 'week_asset_hot_ten': self.get_week_top10_asset(), 'last_login_ten': self.get_last10_sessions(), 'week_user_hot_ten': self.get_week_top10_user(), + 'app': _("Dashboard"), } kwargs.update(context) diff --git a/apps/perms/api/mixin.py b/apps/perms/api/mixin.py index 9c726691f..17c7c833d 100644 --- a/apps/perms/api/mixin.py +++ b/apps/perms/api/mixin.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -from functools import reduce +import uuid from hashlib import md5 from django.core.cache import cache from django.db.models import Q @@ -186,6 +186,20 @@ class GrantAssetsMixin(LabelFilterMixin): data = self.get_serializer_queryset(queryset_list) return super().get_serializer(data, many=True) + def filter_queryset_by_id(self, assets_items): + i = self.request.query_params.get("id") + if not i: + return assets_items + try: + pk = uuid.UUID(i) + except ValueError: + return assets_items + assets_map = {asset['id']: asset for asset in assets_items} + if pk in assets_map: + return [assets_map.get(pk)] + else: + return [] + def search_queryset(self, assets_items): search = self.request.query_params.get("search") if not search: @@ -221,7 +235,8 @@ class GrantAssetsMixin(LabelFilterMixin): return [assets_map.get(asset_id) for asset_id in assets_ids_search] def filter_queryset(self, assets_items): + assets_items = self.filter_queryset_by_id(assets_items) assets_items = self.search_queryset(assets_items) assets_items = self.filter_queryset_by_label(assets_items) assets_items = self.sort_queryset(assets_items) - return assets_items \ No newline at end of file + return assets_items diff --git a/apps/perms/api/user_permission.py b/apps/perms/api/user_permission.py index 13ee07951..bb7a49726 100644 --- a/apps/perms/api/user_permission.py +++ b/apps/perms/api/user_permission.py @@ -1,10 +1,6 @@ # -*- coding: utf-8 -*- # -import time -import traceback -from functools import reduce import uuid -from django.db.models import Q from django.shortcuts import get_object_or_404 from rest_framework.views import APIView, Response from rest_framework.generics import ( diff --git a/apps/templates/_header_bar.html b/apps/templates/_header_bar.html index 7c7f696b3..24469a633 100644 --- a/apps/templates/_header_bar.html +++ b/apps/templates/_header_bar.html @@ -110,9 +110,6 @@

-
- - -
+{#
#} +{# #} +{# #} +{#
#} diff --git a/apps/users/templates/users/user_list.html b/apps/users/templates/users/user_list.html index 2dfab41f7..0c74640de 100644 --- a/apps/users/templates/users/user_list.html +++ b/apps/users/templates/users/user_list.html @@ -76,10 +76,16 @@ function initTable() { var detail_btn = '' + cellData + ''; $(td).html(detail_btn.replace("{{ DEFAULT_PK }}", rowData.id)); }}, + {targets: 3, createdCell: function (td, cellData, rowData) { + $(td).html(rowData.role_display); + }}, {targets: 4, createdCell: function (td, cellData) { var innerHtml = cellData.length > 20 ? cellData.substring(0, 20) + '...': cellData; $(td).html('' + innerHtml + ''); }}, + {targets: 5, createdCell: function (td, cellData, rowData) { + $(td).html(rowData.source_display); + }}, {targets: 6, createdCell: function (td, cellData, rowData) { if (cellData) { $(td).html('') @@ -114,9 +120,9 @@ function initTable() { ajax_url: '{% url "api-users:user-list" %}', columns: [ {data: "id"}, {data: "name" }, {data: "username" }, - {data: "role_display", orderable: false}, + {data: "role"}, {data: "groups_display", orderable: false}, - {data: "source_display", orderable: false}, + {data: "source"}, {data: "is_valid", orderable: false}, {data: "id", orderable: false} ], @@ -209,8 +215,8 @@ $(document).ready(function(){ var data = { 'resources': id_list }; - function refreshTag() { - $('#user_list_table').DataTable().ajax.reload() + function reloadPage() { + setTimeout( function () {window.location.reload();}, 300); } function doDeactive() { var data = []; @@ -218,15 +224,11 @@ $(document).ready(function(){ var obj = {"pk": object_id, "is_active": false}; data.push(obj); }); - function success() { - setTimeout( function () { - window.location.reload();}, 300); - } requestApi({ url: the_url, method: 'PATCH', body: JSON.stringify(data), - success: success + success: reloadPage }); } function doActive() { @@ -235,15 +237,11 @@ $(document).ready(function(){ var obj = {"pk": object_id, "is_active": true}; data.push(obj); }); - function success() { - setTimeout( function () { - window.location.reload();}, 300); - } requestApi({ url: the_url, method: 'PATCH', body: JSON.stringify(data), - success: success + success: reloadPage }); } function doDelete() { @@ -262,7 +260,7 @@ $(document).ready(function(){ requestApi({ url:url, method:'DELETE', - success:refreshTag, + success:reloadPage, flash_message:false, }); var msg = "{% trans 'User Deleted.' %}";