Skip to content

Commit

Permalink
修复用户中心批量删除资产失败的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
welliamcao committed May 10, 2020
1 parent d49b782 commit 935f2dd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 108 deletions.
2 changes: 1 addition & 1 deletion apps/asset/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions apps/databases/mysql/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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未授权, 联系管理员授权"

Expand Down
131 changes: 26 additions & 105 deletions static/js/account/center.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 += '<strong><code>' + $(this).parent().parent().find("td").eq(5).text() + '</code></strong>&nbsp;'
serverId.push($(this).val())
});
let ips = ''
for (var i=0; i <dataList.length; i++){
serverId.push(dataList[i]["id"])
ips = ips + dataList[i]["detail"]['ip'] + ' '
}
if (serverId.length > 0){
$.confirm({
type: 'blue',
title: '更新资产',
content: '确认更新这些资产:<br>' + 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:{
Expand Down Expand Up @@ -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'
});
Expand All @@ -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 += '<strong><code>' + $(this).parent().parent().find("td").eq(5).text() + '</code></strong>&nbsp;'
serverId.push($(this).val())
});
if (serverId.length > 0){
$.confirm({
type: 'red',
title: '删除资产',
content: '确认删除这些资产:<br>' + 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] + '<br>'
}
for (var i = 0; i < response['data']['failed'].length; i++){
fip += response['data']['failed'][i] + '<br>'
}
msg = '成功:'+ '<br>' + sip + '<br>' + '失败:'+ '<br>' + 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){
Expand Down Expand Up @@ -398,24 +311,32 @@ $(document).ready(function() {
{
text: '<span class="fa fa-trash-o"></span>',
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')
}
}
},
{
text: '更新',
className: "btn-sm",
action: function ( e, dt, node, config ) {
let dataList = dt.rows('.selected').data()
var vips = ''
if (dataList.length==0){
$.alert({
title: '操作失败',
content: '批量更新资产失败,请先选择资产',
type: 'red',
});
}else{
updateAssetsByAnsible(dataList)
batchManageChoiceAssets(dataList, '批量更新', '批量更新资产:' ,'POST')
}
}
},
Expand Down

0 comments on commit 935f2dd

Please sign in to comment.