Skip to content

Commit

Permalink
修复sql query 审核回调 (#2370)
Browse files Browse the repository at this point in the history
* 修复sql query 审核回调

* 新增 query privilege 审核单元测试

* black

* 删除无用函数
  • Loading branch information
LeoQuote authored Nov 7, 2023
1 parent 9183bcc commit 3af3588
Show file tree
Hide file tree
Showing 6 changed files with 713 additions and 718 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ sonar-project.properties
.env
local_settings.py
src/docker-compose-dev
.coverage
.coverage
archery_custom
15 changes: 14 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime

import pytest
from pytest_mock import MockFixture

from common.utils.const import WorkflowStatus
from sql.models import (
Expand All @@ -12,6 +13,7 @@
ArchiveConfig,
)
from common.config import SysConfig
from sql.utils.workflow_audit import AuditV2, AuditSetting


@pytest.fixture
Expand Down Expand Up @@ -91,7 +93,7 @@ def sql_query_apply(db_instance):
valid_date=tomorrow,
priv_type=1,
status=0,
audit_auth_groups="some_audit_group",
audit_auth_groups="1",
)
yield query_apply_1
query_apply_1.delete()
Expand Down Expand Up @@ -127,3 +129,14 @@ def setup_sys_config(db):
sys_config = SysConfig()
yield sys_config
sys_config.purge()


@pytest.fixture
def fake_generate_audit_setting(mocker: MockFixture):
mock_generate_audit_setting = mocker.patch.object(AuditV2, "generate_audit_setting")
fake_audit_setting = AuditSetting(
auto_pass=False,
audit_auth_groups=[123],
)
mock_generate_audit_setting.return_value = fake_audit_setting
yield mock_generate_audit_setting
10 changes: 4 additions & 6 deletions sql/query_privileges.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ def query_priv_audit(request):
:return:
"""
# 获取用户信息
user = request.user
apply_id = int(request.POST["apply_id"])
try:
audit_status = WorkflowAction(int(request.POST["audit_status"]))
Expand All @@ -437,11 +436,10 @@ def query_priv_audit(request):
)
except AuditException as e:
return render(request, "error.html", {"errMsg": f"审核失败: {str(e)}"})
if auditor.audit.current_status == WorkflowStatus.PASSED:
# 通过了, 授权
_query_apply_audit_call_back(
auditor.audit.workflow_id, auditor.audit.current_status
)
# 统一 call back, 内部做授权和更新数据库内容
_query_apply_audit_call_back(
auditor.audit.workflow_id, auditor.audit.current_status
)

# 消息通知
async_task(
Expand Down
Loading

0 comments on commit 3af3588

Please sign in to comment.