Skip to content

Commit

Permalink
新增跳过inception直接执行工单的流程
Browse files Browse the repository at this point in the history
提交工单支持上传sql文件
优化工单检测结果展示,提交时做二次确认
调整js加载,每个页面只加载所需的js文件
  • Loading branch information
hhyo authored and 李环焕 committed Mar 31, 2018
1 parent d16a341 commit ad20e58
Show file tree
Hide file tree
Showing 25 changed files with 1,195 additions and 579 deletions.
2 changes: 1 addition & 1 deletion sql/aliyun_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse
from .aliyun_api import Aliyun
from .query import superuser_required
from .permission import superuser_required

from .models import users, AliyunRdsConfig

Expand Down
28 changes: 28 additions & 0 deletions sql/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,34 @@ def mysql_query(self, masterHost, masterPort, masterUser, masterPassword, dbName
conn.close()
return result

# 连进指定的mysql实例里,执行sql并返回
def mysql_execute(self, masterHost, masterPort, masterUser, masterPassword, sql):
result = {}
conn = None
cursor = None

try:
conn = MySQLdb.connect(host=masterHost, port=masterPort, user=masterUser, passwd=masterPassword,
charset='utf8mb4', max_allowed_packet=1073741824)
cursor = conn.cursor()
effect_row = cursor.execute(sql)
# result = {}
# result['effect_row'] = effect_row
conn.commit()
except MySQLdb.Warning as w:
print(str(w))
result['Warning'] = str(w)
except MySQLdb.Error as e:
print(str(e))
result['Error'] = str(e)
finally:
if result.get('Error') or result.get('Warning'):
conn.close()
elif cursor is not None:
cursor.close()
conn.close()
return result

def getWorkChartsByMonth(self):
cursor = connection.cursor()
sql = "select date_format(create_time, '%%m-%%d'),count(*) from sql_workflow where create_time>=date_add(now(),interval -%s day) group by date_format(create_time, '%%m-%%d') order by 1 asc;" % (Dao._CHART_DAYS)
Expand Down
6 changes: 4 additions & 2 deletions sql/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class workflow(models.Model):
reviewok_time = models.DateTimeField('人工审核通过的时间', null=True, blank=True)
sql_content = models.TextField('具体sql内容')
execute_result = models.TextField('执行结果的JSON格式')
is_manual = models.IntegerField('是否手工执行', choices=((0, '否'), (1, '是')),default=0)
audit_remark = models.TextField('审核备注', null=True)

def __str__(self):
return self.workflow_name
Expand Down Expand Up @@ -111,6 +113,7 @@ def __int__(self):

class Meta:
db_table = 'workflow_audit'
unique_together = ('workflow_id', 'workflow_type')
verbose_name = u'工作流列表'
verbose_name_plural = u'工作流列表'

Expand All @@ -137,8 +140,7 @@ class Meta:
# 审批配置表
class WorkflowAuditSetting(models.Model):
audit_setting_id = models.AutoField(primary_key=True)
workflow_type = models.IntegerField('申请类型,',
choices=((1, '查询权限申请'),))
workflow_type = models.IntegerField('申请类型,',choices=((1, '查询权限申请'),), unique=True)
audit_users = models.CharField('审核人,单人审核格式为:user1,多级审核格式为:user1,user2', max_length=255)
create_time = models.DateTimeField(auto_now_add=True)
sys_time = models.DateTimeField(auto_now=True)
Expand Down
49 changes: 49 additions & 0 deletions sql/permission.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: UTF-8 -*-
import json
from django.shortcuts import render
from django.http import HttpResponse
from .models import users


# 管理员操作权限验证
def superuser_required(func):
def wrapper(request, *args, **kw):
# 获取用户信息,权限验证
loginUser = request.session.get('login_username', False)
loginUserOb = users.objects.get(username=loginUser)

if loginUserOb.is_superuser is False:
if request.is_ajax():
finalResult = {'status': 1, 'msg': '您无权操作,请联系管理员', 'data': []}
return HttpResponse(json.dumps(finalResult), content_type='application/json')
else:
context = {'errMsg': "您无权操作,请联系管理员"}
return render(request, "error.html", context)

return func(request, *args, **kw)

return wrapper


# 角色操作权限验证
def role_required(roles=()):
def _deco(func):
def wrapper(request, *args, **kw):
# 获取用户信息,权限验证
loginUser = request.session.get('login_username', False)
loginUserOb = users.objects.get(username=loginUser)
loginrole = loginUserOb.role

if loginrole not in roles and loginUserOb.is_superuser is False:
if request.is_ajax():
finalResult = {'status': 1, 'msg': '您无权操作,请联系管理员', 'data': []}
return HttpResponse(json.dumps(finalResult), content_type='application/json')
else:
context = {'errMsg': "您无权操作,请联系管理员"}
return render(request, "error.html", context)

return func(request, *args, **kw)

return wrapper

return _deco
4 changes: 2 additions & 2 deletions sql/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
)

leftMenuBtnsAliYun = (
{'key': 'slowquery', 'name': 'SQL慢查日志', 'url': '/slowquery/', 'class': 'glyphicon glyphicon-align-right'},
{'key': 'diagnosis', 'name': '实例问题诊断', 'url': '/diagnosis_process/','class': 'glyphicon glyphicon glyphicon-scissors'},
{'key': 'slowquery', 'name': 'RDS慢查日志', 'url': '/slowquery/', 'class': 'glyphicon glyphicon-align-right'},
{'key': 'diagnosis', 'name': 'RDS进程管理', 'url': '/diagnosis_process/','class': 'glyphicon glyphicon glyphicon-scissors'},
)

leftMenuBtnsSuper = (
Expand Down
45 changes: 1 addition & 44 deletions sql/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .models import users, master_config, slave_config, QueryPrivilegesApply, QueryPrivileges, QueryLog
from .data_masking import Masking
from .workflow import Workflow
from .permission import role_required, superuser_required

dao = Dao()
prpCryptor = Prpcrypt()
Expand All @@ -30,50 +31,6 @@
mailSenderOb = MailSender()


# 管理员操作权限验证
def superuser_required(func):
def wrapper(request, *args, **kw):
# 获取用户信息,权限验证
loginUser = request.session.get('login_username', False)
loginUserOb = users.objects.get(username=loginUser)

if loginUserOb.is_superuser is False:
if request.is_ajax():
finalResult = {'status': 1, 'msg': '您无权操作,请联系管理员', 'data': []}
return HttpResponse(json.dumps(finalResult), content_type='application/json')
else:
context = {'errMsg': "您无权操作,请联系管理员"}
return render(request, "error.html", context)

return func(request, *args, **kw)

return wrapper


# 角色操作权限验证
def role_required(roles=()):
def _deco(func):
def wrapper(request, *args, **kw):
# 获取用户信息,权限验证
loginUser = request.session.get('login_username', False)
loginUserOb = users.objects.get(username=loginUser)
loginrole = loginUserOb.role

if loginrole not in roles and loginUserOb.is_superuser is False:
if request.is_ajax():
finalResult = {'status': 1, 'msg': '您无权操作,请联系管理员', 'data': []}
return HttpResponse(json.dumps(finalResult), content_type='application/json')
else:
context = {'errMsg': "您无权操作,请联系管理员"}
return render(request, "error.html", context)

return func(request, *args, **kw)

return wrapper

return _deco


# 处理查询结果的时间格式
class DateEncoder(json.JSONEncoder):
def default(self, obj):
Expand Down
6 changes: 0 additions & 6 deletions sql/static/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@ <h4 class="modal-title" id="myModalLabel">
<script src="{% static 'dist/js/bootstrap-select.js' %}"></script>
<script src="{% static 'bootstrap-table/js/bootstrap-table.min.js' %}"></script>
<script src="{% static 'bootstrap-table/js/bootstrap-table-zh-CN.min.js' %}"></script>
<script src="{% static 'user/js/detail.js' %}"></script>
<script src="{% static 'user/js/rollback.js' %}"></script>
<script src="{% static 'user/js/autoreview.js' %}"></script>
<script src="{% static 'user/js/submitsql.js' %}"></script>
<script src="{% static 'highcharts/highcharts.js' %}"></script>
<script src="{% static 'user/js/charts.js' %}"></script>
<script src="{% static 'user/js/ldapsync.js' %}"></script>
<script src="{% static 'user/js/formatter.js' %}"></script>
</body>
Expand Down
6 changes: 5 additions & 1 deletion sql/static/charts.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
</div>
</div>
</div>
</script>
{% endblock content %}
{% block js %}
{% load staticfiles %}
<script src="{% static 'highcharts/highcharts.js' %}"></script>
<script src="{% static 'user/js/charts.js' %}"></script>
{% endblock %}

2 changes: 2 additions & 0 deletions sql/static/crypto-js-3.1.9/core.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions sql/static/crypto-js-3.1.9/enc-base64.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions sql/static/crypto-js-3.1.9/enc-utf8.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ad20e58

Please sign in to comment.