Skip to content

Commit

Permalink
Revert "在前端独立展示审批流 (hhyo#2423)"
Browse files Browse the repository at this point in the history
  • Loading branch information
pengkang1991 authored Nov 29, 2023
1 parent 1b11e84 commit 6e0d553
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 233 deletions.
6 changes: 0 additions & 6 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,3 @@ def create_audit_workflow(normal_user, create_resource_group):
)
yield audit_wf
audit_wf.delete()


@pytest.fixture
def clean_auth_group(db):
yield
Group.objects.all().delete()
20 changes: 11 additions & 9 deletions sql/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
SqlWorkflowContent,
)
from sql.utils.resource_group import auth_group_users
from sql.utils.workflow_audit import Audit, AuditV2
from sql.utils.workflow_audit import Audit
from sql_api.serializers import (
WorkflowContentSerializer,
WorkflowAuditListSerializer,
Expand Down Expand Up @@ -156,8 +156,9 @@ def render_audit(self):
workflow_from = self.audit.create_user_display
group_name = self.audit.group_name
# 获取当前审批和审批流程
audit_handler = AuditV2(workflow=self.workflow, audit=self.audit)
review_info = audit_handler.get_review_info()
workflow_auditors, current_workflow_auditors = Audit.review_info(
self.audit.workflow_id, self.audit.workflow_type
)
# workflow content, 即申请通过后要执行什么东西
# 执行的 SQL 语句, 授权的范围
if workflow_type == WorkflowType.QUERY:
Expand Down Expand Up @@ -220,8 +221,8 @@ def render_audit(self):
group_name,
instance,
db_name,
review_info.readable_info,
review_info.current_node.group.name,
workflow_auditors,
current_workflow_auditors,
workflow_title,
workflow_url,
workflow_content,
Expand All @@ -237,7 +238,7 @@ def render_audit(self):
group_name,
instance,
db_name,
review_info.readable_info,
workflow_auditors,
workflow_title,
workflow_url,
workflow_content,
Expand Down Expand Up @@ -283,8 +284,9 @@ def render_execute(self):
base_url = self.sys_config.get(
"archery_base_url", "http://127.0.0.1:8000"
).rstrip("/")
audit_handler = AuditV2(workflow=self.workflow, audit=self.audit)
review_info = audit_handler.get_review_info()
audit_auth_group, current_audit_auth_group = Audit.review_info(
self.workflow.id, 2
)
audit_id = Audit.detail_by_workflow_id(self.workflow.id, 2).audit_id
url = "{base_url}/workflow/{audit_id}".format(
base_url=base_url, audit_id=audit_id
Expand All @@ -303,7 +305,7 @@ def render_execute(self):
组:{self.workflow.group_name}
目标实例:{self.workflow.instance.instance_name}
数据库:{self.workflow.db_name}
审批流程:{review_info.readable_info}
审批流程:{audit_auth_group}
工单名称:{self.workflow.workflow_name}
工单地址:{url}
工单详情预览:{preview}"""
Expand Down
22 changes: 13 additions & 9 deletions sql/templates/archivedetail.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,19 @@ <h4 style="display: inline;">工单名称:<span>{{ archive_config.title }}</sp
<input type="hidden" id="sqlMaxRowNumber" value="{{ rows|length }}">
<input type="hidden" id="editSqlContent" value="{{ archive_config.sql_content }}"/>
<hr>
<h4>
审批流
</h4>
<h5>
{% include "workflow_display.html" %}
<h4>
其他信息
</h4>
<table data-toggle="table" class="table table-striped table-hover"
style="table-layout:inherit;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">
<thead>
<tr>
<th>
申请人
</th>
<th>
审批流程
</th>
<th>
当前审批
</th>
<th>
实例
</th>
Expand Down Expand Up @@ -67,6 +65,12 @@ <h4>
<td>
{{ archive_config.user_display }}
</td>
<td>
{{ audit_auth_group }}
</td>
<td>
{{ current_audit_auth_group }}
</td>
<td>
{{ archive_config.src_instance }}
</td>
Expand Down Expand Up @@ -236,7 +240,7 @@ <h4><b>归档条件</b></h4>
<br>
{% endif %}
{% if archive_config.status == 0 %}
{% if can_review %}
{% if is_can_review %}
<textarea id="remark" name="remark" class="form-control" data-name="审核备注"
placeholder="请填写审核备注" rows=3></textarea>
<br>
Expand Down
20 changes: 12 additions & 8 deletions sql/templates/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,19 @@ <h4 style="display: inline;">
<input type="hidden" id="sqlMaxRowNumber" value="{{ rows|length }}">
<input type="hidden" id="editSqlContent" value="{{ workflow_detail.sqlworkflowcontent.sql_content }}"/>
<hr>
<h4>
审批流
</h4>
<h5>
{% include "workflow_display.html" %}
<h4>
其他信息
</h4>
<table data-toggle="table" class="table table-striped table-hover"
style="table-layout:inherit;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">
<thead>
<tr>
<th>
发起人
</th>
<th>
审批流程
</th>
<th>
当前审批
</th>
<th>
目标实例
</th>
Expand Down Expand Up @@ -67,6 +65,12 @@ <h4>
<td>
{{ workflow_detail.engineer_display }}
</td>
<td>
{{ audit_auth_group }}
</td>
<td>
{{ current_audit_auth_group }}
</td>
<td>
{{ workflow_detail.instance.instance_name }}
</td>
Expand Down
20 changes: 12 additions & 8 deletions sql/templates/queryapplydetail.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,19 @@ <h4 style="display: inline;">工单名称:<span>{{ workflow_detail.title }}</s
<input type="hidden" id="sqlMaxRowNumber" value="{{ rows|length }}">
<input type="hidden" id="editSqlContent" value="{{ workflow_detail.sql_content }}"/>
<hr>
<h4>
审批流
</h4>
<h5>
{% include "workflow_display.html" %}
<h4>
其他信息
</h4>
<table data-toggle="table" class="table table-striped table-hover"
style="table-layout:inherit;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">
<thead>
<tr>
<th>
申请人
</th>
<th>
审批流程
</th>
<th>
当前审批
</th>
<th>
实例
</th>
Expand Down Expand Up @@ -56,6 +54,12 @@ <h4>
<td>
{{ workflow_detail.user_display }}
</td>
<td>
{{ audit_auth_group }}
</td>
<td>
{{ current_audit_auth_group }}
</td>
<td>
{{ workflow_detail.instance.instance_name }}
</td>
Expand Down
19 changes: 0 additions & 19 deletions sql/templates/workflow_display.html

This file was deleted.

23 changes: 1 addition & 22 deletions sql/test_archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
from django.conf import settings
from django.contrib.auth.models import Permission
from django.test import TestCase, Client
from pytest_django.asserts import assertTemplateUsed

from common.config import SysConfig
from common.utils.const import WorkflowStatus, WorkflowType
from sql.utils.workflow_audit import AuditSetting, AuditV2
from sql.utils.workflow_audit import AuditSetting
from sql.archiver import add_archive_task, archive
from sql.models import (
Instance,
Expand Down Expand Up @@ -300,23 +299,3 @@ def test_archive_log(self, _async_task):
self.client.force_login(self.superuser)
r = self.client.post(path="/archive/log/", data=data)
self.assertDictEqual(json.loads(r.content), {"total": 0, "rows": []})


def test_archive_detail_view(
archive_apply,
resource_group,
admin_client,
fake_generate_audit_setting,
create_auth_group,
):
audit = AuditV2(workflow=archive_apply, resource_group=resource_group.group_name)
audit.create_audit()
audit.workflow.save()
response = admin_client.get(f"/archive/{archive_apply.id}/")
assert response.status_code == 200
assertTemplateUsed(response, "archivedetail.html")
review_info = response.context["review_info"]
assert len(review_info.nodes) == len(
fake_generate_audit_setting.return_value.audit_auth_groups
)
assert review_info.nodes[0].group.name == create_auth_group.name
12 changes: 6 additions & 6 deletions sql/test_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ def setUp(self):
workflow_type=1,
workflow_title="申请标题",
workflow_remark="申请备注",
audit_auth_groups=",".join([str(self.aug.id)]),
current_audit=str(self.aug.id),
next_audit="-1",
audit_auth_groups="1,2,3",
current_audit="1",
next_audit="2",
current_status=0,
)
self.audit_query_detail = WorkflowAuditDetail.objects.create(
Expand Down Expand Up @@ -167,9 +167,9 @@ def setUp(self):
workflow_type=3,
workflow_title=self.archive_apply.title,
workflow_remark="申请备注",
audit_auth_groups=",".join([str(self.aug.id)]),
current_audit=str(self.aug.id),
next_audit="-1",
audit_auth_groups="1,2,3",
current_audit="1",
next_audit="2",
current_status=0,
)

Expand Down
7 changes: 3 additions & 4 deletions sql/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def test_get_sql_workflow(
assert response.status_code == 200
assertTemplateUsed(response, "detail.html")
# 展示审批人用户名
review_info = response.context["review_info"]
assert len(review_info.nodes) == len(
fake_generate_audit_setting.return_value.audit_auth_groups
assert (
response.context["current_audit_auth_group"]
== f"{create_auth_group.name}: {super_user.username}"
)
assert review_info.nodes[0].group.name == create_auth_group.name
46 changes: 46 additions & 0 deletions sql/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,52 @@ def test_alter_run_date(self, _can_review):
r, f"/detail/{self.wf1.id}/", fetch_redirect_response=False
)

@patch("sql.utils.workflow_audit.Audit.logs")
@patch("sql.utils.workflow_audit.Audit.detail_by_workflow_id")
@patch("sql.utils.workflow_audit.Audit.review_info")
@patch("sql.utils.workflow_audit.Audit.can_review")
def testWorkflowDetailView(self, _can_review, _review_info, _detail_by_id, _logs):
"""测试工单详情"""
_review_info.return_value = ("some_auth_group", "current_auth_group")
_can_review.return_value = False
_detail_by_id.return_value.audit_id = 123
_logs.return_value.latest("id").operation_info = ""
c = Client()
c.force_login(self.u1)
r = c.get("/detail/{}/".format(self.wf1.id))
expected_status_display = r"""id="workflow_detail_disaply">已正常结束"""
self.assertContains(r, expected_status_display)
exepcted_status = r"""id="workflow_detail_status">workflow_finish"""
self.assertContains(r, exepcted_status)

# 测试执行详情解析失败
self.wfc1.execute_result = "cannotbedecode:1,:"
self.wfc1.save()
r = c.get("/detail/{}/".format(self.wf1.id))
self.assertContains(r, expected_status_display)
self.assertContains(r, exepcted_status)

# 执行详情为空
self.wfc1.review_content = [
{
"id": 1,
"stage": "CHECKED",
"errlevel": 0,
"stagestatus": "Audit completed",
"errormessage": "None",
"sql": "use archery",
"affected_rows": 0,
"sequence": "'0_0_0'",
"backup_dbname": "None",
"execute_time": "0",
"sqlsha1": "",
"actual_affected_rows": "",
}
]
self.wfc1.execute_result = ""
self.wfc1.save()
r = c.get("/detail/{}/".format(self.wf1.id))

def testWorkflowListView(self):
"""测试工单列表"""
c = Client()
Expand Down
Loading

0 comments on commit 6e0d553

Please sign in to comment.