Skip to content

Commit

Permalink
修复 auto pass 无法正常显示的 bug (hhyo#2429)
Browse files Browse the repository at this point in the history
* 修复 auto pass 无法正常显示的 bug

* black
  • Loading branch information
LeoQuote authored and finovy committed Dec 1, 2023
1 parent db21e58 commit adb8fe5
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
4 changes: 3 additions & 1 deletion sql/templates/workflow_display.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{# review_info 应为 ReviewInfo 对象, 本模板为所有用到 audit 工作流的审批共用 #}
{% for n in review_info.nodes %}
{% if n.is_passed_node %}
{% if n.is_auto_pass %}
<span class="text-success">无需审批</span>
{% elif n.is_passed_node %}
<span class="text-success">{{ n.group.name }}</span>
{% elif n.is_current_node %}
<!-- 当前节点 -->
Expand Down
25 changes: 24 additions & 1 deletion sql/utils/test_workflow_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@
WorkflowAuditSetting,
)
from sql.utils.tests import User
from sql.utils.workflow_audit import Audit, AuditV2, AuditSetting, AuditException
from sql.utils.workflow_audit import (
Audit,
AuditV2,
AuditSetting,
AuditException,
ReviewNodeType,
)


class TestAudit(TestCase):
Expand Down Expand Up @@ -546,3 +552,20 @@ def test_get_review_info(
assert review_info.nodes[0].is_passed_node is True
assert review_info.nodes[1].is_current_node is True
assert review_info.nodes[1].is_passed_node is False


def test_get_review_info_auto_pass(
sql_query_apply,
fake_generate_audit_setting,
admin_client,
):
# 自动通过的情况
fake_generate_audit_setting.return_value = AuditSetting(auto_pass=True)
audit = AuditV2(workflow=sql_query_apply)
audit.create_audit()
review_info = audit.get_review_info()
assert review_info.nodes[0].node_type == ReviewNodeType.AUTO_PASS
# 测一下详情页 get
response = admin_client.get(f"/queryapplydetail/{sql_query_apply.apply_id}/")
assert response.status_code == 200
assert "无需审批" in response.content.decode("utf-8")
28 changes: 27 additions & 1 deletion sql/utils/workflow_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import re
from dataclasses import dataclass, field
from enum import Enum
from typing import Union, Optional, List
import logging

Expand Down Expand Up @@ -35,12 +36,28 @@ class AuditException(Exception):
pass


class ReviewNodeType(Enum):
GROUP = "group"
AUTO_PASS = "auto_pass"


@dataclass
class ReviewNode:
group: Group
group: Optional[Group] = None
node_type: ReviewNodeType = ReviewNodeType.GROUP
is_current_node: bool = False
is_passed_node: bool = False

def __post_init__(self):
if self.node_type == ReviewNodeType.GROUP and not self.group:
raise ValueError(
f"group not provided and node_type is set as {self.node_type}"
)

@property
def is_auto_pass(self):
return self.node_type == ReviewNodeType.AUTO_PASS


@dataclass
class ReviewInfo:
Expand Down Expand Up @@ -514,6 +531,15 @@ def get_review_info(self) -> ReviewInfo:
has_met_current_node = False
current_node_group_id = int(self.audit.current_audit)
for g in self.audit.audit_auth_groups.split(","):
if not g:
# 空的值, 代表的是自动通过
review_nodes.append(
ReviewNode(
node_type=ReviewNodeType.AUTO_PASS,
is_passed_node=True,
)
)
continue
g = int(g)
group_in_db = Group.objects.get(id=g)
if self.audit.current_status != WorkflowStatus.WAITING:
Expand Down
3 changes: 1 addition & 2 deletions sql/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: UTF-8 -*-
import os
import traceback
from django.conf import settings

from django.contrib.auth.decorators import permission_required
from django.contrib.auth.models import Group
Expand Down Expand Up @@ -32,7 +31,7 @@
AuditEntry,
TwoFactorAuthConfig,
)
from sql.utils.workflow_audit import Audit, AuditV2, AuditException
from sql.utils.workflow_audit import Audit, AuditV2, AuditException, ReviewNodeType
from sql.utils.sql_review import (
can_execute,
can_timingtask,
Expand Down

0 comments on commit adb8fe5

Please sign in to comment.