From 935f2dd8429623af1c5a4d3ffb3027f4544ba5e4 Mon Sep 17 00:00:00 2001 From: "Welliam.Cao" <303350019@qq.com> Date: Sun, 10 May 2020 11:15:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=A8=E6=88=B7=E4=B8=AD?= =?UTF-8?q?=E5=BF=83=E6=89=B9=E9=87=8F=E5=88=A0=E9=99=A4=E8=B5=84=E4=BA=A7?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/asset/views.py | 2 +- apps/databases/mysql/consumers.py | 5 +- static/js/account/center.js | 131 ++++++------------------------ 3 files changed, 30 insertions(+), 108 deletions(-) diff --git a/apps/asset/views.py b/apps/asset/views.py index 9ef34d98..c5dbfaf2 100644 --- a/apps/asset/views.py +++ b/apps/asset/views.py @@ -212,7 +212,7 @@ def post(self, request, *args, **kwagrs): @method_decorator_adaptor(permission_required, "asset.assets_delete_assets","/403/") def delete(self, request, *args, **kwagrs): - for ast in QueryDict(request.body).getlist('assetsIds[]'): + for ast in QueryDict(request.body).getlist('ids[]'): try: assets = Assets.objects.get(id=int(ast)) except Exception as ex: diff --git a/apps/databases/mysql/consumers.py b/apps/databases/mysql/consumers.py index 880278df..3cdd2c59 100644 --- a/apps/databases/mysql/consumers.py +++ b/apps/databases/mysql/consumers.py @@ -151,9 +151,10 @@ def __check_sql_parse(self, sql, allow_sql): if len(keywords) > 1: if keywords[0] + '_' + keywords[1] in grant_sql: return True -# print(_first_token, keywords, grant_sql, allow_sql) + +# print(sql_type, _first_token , keywords) - if _first_token in allow_sql: return True + if _first_token in allow_sql and sql_type in ["dml", "ddl"]: return True return "SQL未授权, 联系管理员授权" diff --git a/static/js/account/center.js b/static/js/account/center.js index bd69e4f6..8933818b 100644 --- a/static/js/account/center.js +++ b/static/js/account/center.js @@ -147,26 +147,24 @@ function RefreshAssetsTable(tableId, urlData){ }); } -function RefreshChoiceAssets(){ - var btnObj = $(this); - btnObj.attr('disabled',true); +function batchManageChoiceAssets(dataList, title, content, type){ var serverId = []; - var ips = '' - $.each($('input[type=checkbox]input[name="ckbox"]:checked'),function(){ - ips += '' + $(this).parent().parent().find("td").eq(5).text() + ' ' - serverId.push($(this).val()) - }); + let ips = '' + for (var i=0; i 0){ $.confirm({ - type: 'blue', - title: '更新资产', - content: '确认更新这些资产:
' + ips, + type: 'red', + title: title, + content: content + ips, buttons: { - '更新': { + '确定': { btnClass: 'btn-blue', action: function() { $.ajax({ - type: 'POST', + type: type, url: '/assets/batch/', dataType:"json", data:{ @@ -202,14 +200,12 @@ function RefreshChoiceAssets(){ styling: 'bootstrap3', delay: 18000 }); - } - btnObj.removeAttr('disabled'); + } }, error:function(response){ - btnObj.removeAttr('disabled'); new PNotify({ title: 'Ops Failed!', - text: '资产修改失败', + text: '批量操作失败', type: 'error', styling: 'bootstrap3' }); @@ -223,96 +219,13 @@ function RefreshChoiceAssets(){ } else{ $.alert({ - title: '批量更新资产', + title: '批量操作资产', content: '请至少选择一个资产!', type: 'red', }); - btnObj.removeAttr('disabled'); } } -function DeleteChoiceAssets(){ - var btnObj = $(this); - btnObj.attr('disabled',true); - var serverId = []; - var ips = '' - $.each($('input[type=checkbox]input[name="ckbox"]:checked'),function(){ - ips += '' + $(this).parent().parent().find("td").eq(5).text() + ' ' - serverId.push($(this).val()) - }); - if (serverId.length > 0){ - $.confirm({ - type: 'red', - title: '删除资产', - content: '确认删除这些资产:
' + ips, - buttons: { - '删除': { - btnClass: 'btn-blue', - action: function() { - $.ajax({ - type: 'DELETE', - url: '/assets/batch/', - dataType:"json", - data:{ - 'assetsIds':serverId, - }, - success:function(response){ - var sip = ''; - var fip = ''; - var modal = ''; - for (var i = 0; i < response['data']['success'].length; i++){ - sip += response['data']['success'][i] + '
' - } - for (var i = 0; i < response['data']['failed'].length; i++){ - fip += response['data']['failed'][i] + '
' - } - msg = '成功:'+ '
' + sip + '
' + '失败:'+ '
' + fip; - if (response['code']==200){ - new PNotify({ - title: 'Success!', - text: msg, - type: 'success', - styling: 'bootstrap3', - delay: 18000 - }); - } - else{ - new PNotify({ - title: 'Ops Failed!', - text: response["msg"], - type: 'error', - styling: 'bootstrap3', - delay: 18000 - }); - } - btnObj.removeAttr('disabled'); - }, - error:function(response){ - btnObj.removeAttr('disabled'); - new PNotify({ - title: 'Ops Failed!', - text: '资产修改失败', - type: 'error', - styling: 'bootstrap3' - }); - } - }); - } - }, - '取消': function() {}, - } - }); - } - else{ - $.alert({ - title: '批量删除资产', - content: '请至少选择一个资产!', - type: 'red', - }); - btnObj.removeAttr('disabled'); - } -}; - $(document).ready(function() { if($("#assetsListTable").length){ @@ -398,8 +311,17 @@ $(document).ready(function() { { text: '', className: "btn-sm", - action: function ( e, dt, node, config ) { - DeleteChoiceAssets() + action: function ( e, dt, node, config ) { + let dataList = dt.rows('.selected').data() + if (dataList.length==0){ + $.alert({ + title: '操作失败', + content: '批量删除资产失败,请先选择资产', + type: 'red', + }); + }else{ + batchManageChoiceAssets(dataList, '批量删除', '批量删除资产:' ,'DELETE') + } } }, { @@ -407,7 +329,6 @@ $(document).ready(function() { className: "btn-sm", action: function ( e, dt, node, config ) { let dataList = dt.rows('.selected').data() - var vips = '' if (dataList.length==0){ $.alert({ title: '操作失败', @@ -415,7 +336,7 @@ $(document).ready(function() { type: 'red', }); }else{ - updateAssetsByAnsible(dataList) + batchManageChoiceAssets(dataList, '批量更新', '批量更新资产:' ,'POST') } } },