Skip to content

Commit

Permalink
审计功能交互优化 (#1395)
Browse files Browse the repository at this point in the history
* 审计功能交互优化

* 还原错误的修改
  • Loading branch information
weideguo authored Feb 25, 2022
1 parent 1cbd9dd commit 8e2a196
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 22 deletions.
18 changes: 18 additions & 0 deletions common/static/dist/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ var onLoadErrorCallback = function (status, jqXHR) {
}
};

var dateFormat = function(fmt, date) {
var o = {
"M+": date.getMonth() + 1, //月份
"d+": date.getDate(), //
"h+": date.getHours(), //小时
"m+": date.getMinutes(), //
"s+": date.getSeconds(), //
"q+": Math.floor((date.getMonth() + 3) / 3), //季度
"S": date.getMilliseconds() //毫秒
};
if(/(y+)/.test(fmt))
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
for(var k in o)
if(new RegExp("(" + k + ")").test(fmt))
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
};

// 实例配置页面根据db_type选择显示或隐藏mode字段mode字段只适用于redis实例
(function($) {
$(function() {
Expand Down
4 changes: 2 additions & 2 deletions sql/audit_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def audit_input(request):
@permission_required('sql.audit_user', raise_exception=True)
def audit_log(request):
"""获取审计日志列表"""
limit = int(request.POST.get('limit'))
offset = int(request.POST.get('offset'))
limit = int(request.POST.get('limit',0))
offset = int(request.POST.get('offset',0))
limit = offset + limit
limit = limit if limit else None
search = request.POST.get('search', '')
Expand Down
5 changes: 3 additions & 2 deletions sql/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,10 @@ def _querylog(request):
# 获取用户信息
user = request.user

limit = int(request.GET.get('limit'))
offset = int(request.GET.get('offset'))
limit = int(request.GET.get('limit',0))
offset = int(request.GET.get('offset',0))
limit = offset + limit
limit = limit if limit else None
star = True if request.GET.get('star') == 'true' else False
query_log_id = request.GET.get('query_log_id')
search = request.GET.get('search', '')
Expand Down
5 changes: 3 additions & 2 deletions sql/sql_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ def _sql_workflow_list(request):
resource_group_id = request.POST.get('group_id')
start_date = request.POST.get('start_date')
end_date = request.POST.get('end_date')
limit = int(request.POST.get('limit'))
offset = int(request.POST.get('offset'))
limit = int(request.POST.get('limit',0))
offset = int(request.POST.get('offset',0))
limit = offset + limit
limit = limit if limit else None
search = request.POST.get('search')
user = request.user

Expand Down
42 changes: 39 additions & 3 deletions sql/templates/audit.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
pageList: [20, 30, 50, 100], //可供选择的每页的行数*
showExport: true, //是否显示导出按钮
exportOptions: {
fileName: 'audit_log' //文件名称设置
fileName: "audit_log_" + dateFormat("yyyyMMddhhmmss",new Date())
},
search: true, //是否显示表格搜索
strictSearch: false, //是否全匹配搜索
Expand All @@ -112,7 +112,7 @@
uniqueId: "id", //每一行的唯一标识一般为主键列
showToggle: true, //是否显示详细视图和列表视图的切换按钮
cardView: false, //是否显示详细视图
detailView: false, //是否显示父子表
detailView: true, //是否显示父子表
locale: 'zh-CN', //本地化
toolbar: "#toolbar", //指明自定义的toolbar
queryParamsType: 'limit',
Expand All @@ -137,6 +137,26 @@
end_date: end_date,
}
},
//格式化详情
detailFormatter: function (index, row) {
var html = [];
$.each(row, function (key, value) {
if (key === 'extra_info') {
//替换标签
value = value.replace(/&/g, "&");
value = value.replace(/</g, "&lt;");
value = value.replace(/>/g, "&gt;");
value = value.replace(/"/g, "&quot;");
//替换所有的换行符
value = value.replace(/\r\n/g, "<br>");
value = value.replace(/\n/g, "<br>");
//替换所有的空格
value = value.replace(/\s/g, "&nbsp;");
html.push('<span>' + value + '</span>');
}
});
return html.join('');
},
columns: [{
title: '用户',
field: 'user_name',
Expand All @@ -149,9 +169,25 @@
},{
title: '动作',
field: 'action'

},{
title: '额外信息',
field: 'extra_info'
field: 'extra_info',
formatter: function (value, row, index) {
var _info=row.extra_info
if (!_info) {
return _info
}
if (_info.length > 100) {
return _info.substr(0, 100) + '...';
} else {
return value
}
}
},{
title: '完整额外信息',
field: 'extra_info',
visible: false
},{
title: '操作时间',
field: 'action_time'
Expand Down
25 changes: 13 additions & 12 deletions sql/templates/audit_sqlquery.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@
pageList: [10, 30, 50, 100, 500, 1000], //可供选择的每页的行数*
showExport: true, //是否显示导出按钮
exportTypes: ['json', 'sql', 'csv', 'txt', 'xml', 'xlsx'],
exportDataType: "all",
exportOptions: {
ignoreColumn: [0], //忽略某些列的索引数组
fileName: 'query_log' //文件名称设置
fileName: "query_log_" + dateFormat("yyyyMMddhhmmss",new Date())
},
search: true, //是否显示表格搜索
strictSearch: false, //是否全匹配搜索
Expand Down Expand Up @@ -137,18 +138,17 @@
var html = [];
$.each(row, function (key, value) {
if (key === 'sqllog') {
let sql = value;
//替换标签
sql = sql.replace(/&/g, "&amp;");
sql = sql.replace(/</g, "&lt;");
sql = sql.replace(/>/g, "&gt;");
sql = sql.replace(/"/g, "&quot;");
value = value.replace(/&/g, "&amp;");
value = value.replace(/</g, "&lt;");
value = value.replace(/>/g, "&gt;");
value = value.replace(/"/g, "&quot;");
//替换所有的换行符
sql = sql.replace(/\r\n/g, "<br>");
sql = sql.replace(/\n/g, "<br>");
value = value.replace(/\r\n/g, "<br>");
value = value.replace(/\n/g, "<br>");
//替换所有的空格
sql = sql.replace(/\s/g, "&nbsp;");
html.push('<span>' + sql + '</span>');
value = value.replace(/\s/g, "&nbsp;");
html.push('<span>' + value + '</span>');
}
});
return html.join('');
Expand All @@ -169,8 +169,9 @@
title: '语句',
field: 'sqllog',
formatter: function (value, row, index) {
if (value.length > 50) {
var sql = value.substr(0, 50) + '...';
var _sql=row.sqllog
if (_sql.length > 50) {
var sql = _sql.substr(0, 50) + '...';
return sql;
} else {
return value
Expand Down
3 changes: 2 additions & 1 deletion sql/templates/audit_sqlworkflow.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ <h4 class="modal-title text-danger">工单日志</h4>
pageSize: 14, //每页的记录行数*
pageList: [20, 30, 50, 100], //可供选择的每页的行数*
showExport: true, //是否显示导出按钮
exportDataType: "all",
exportOptions: {
fileName: 'sqlworkflow' //文件名称设置
fileName: "sqlworkflow_" + dateFormat("yyyyMMddhhmmss",new Date())
},
search: true, //是否显示表格搜索
strictSearch: false, //是否全匹配搜索
Expand Down

0 comments on commit 8e2a196

Please sign in to comment.