-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
140 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
## 功能介绍 | ||
审批系统主要用于处理审批请求,插件开发者可以在处理审批请求逻辑中,将审批请求发送到不同的第三方系统,第三方系统在处理完审批请求后,可以将处理结果发送回来 | ||
|
||
## 实现思路 | ||
* 首先创建审批动作,指定接口Path, method和审批系统插件 | ||
|
||
|
||
```py title='创建审批动作接口' | ||
@api.post( | ||
"/tenant/{tenant_id}/approve_actions/", | ||
tags=["审批动作"], | ||
auth=None, | ||
response=ApproveActionCreateOut, | ||
) | ||
def create_approve_action(request, tenant_id: str, data: ApproveActionCreateIn): | ||
"""创建审批动作""" | ||
extension = Extension.valid_objects.get(id=data.extension_id) | ||
action = ApproveAction.valid_objects.filter( | ||
path=data.path, method=data.method, extension=extension, tenant=request.tenant | ||
).first() | ||
if action: | ||
return {'error': ErrorCode.APPROVE_ACTION_DUPLICATED.value} | ||
else: | ||
action = ApproveAction.valid_objects.create( | ||
name=data.name, | ||
description=data.description, | ||
path=data.path, | ||
method=data.method, | ||
extension=extension, | ||
tenant=request.tenant, | ||
) | ||
return {'error': ErrorCode.OK.value} | ||
``` | ||
|
||
* 在中间件**arkid.core.approve_request_middleware**中根据扫描审批动作,拦截HTTP Request, | ||
1. 如果某个审批动作没有创建审批请求,则创建审批请求,分发**CREATE_APPROVE_REQUEST**事件,将HTTP Request存储在审批请求中,同时使该请求返回未授权状态码401 | ||
2. 如果某个审批动作已经创建审批请求,判断该审批请求状态,如果状态为通过,那么恢复执行之前在审批请求中存储的HTTP Request对应的函数逻辑,如果状态为拒绝,返回未授权状态码401 | ||
|
||
* 在审批系统插件中监听**CREATE_APPROVE_REQUEST**事件,通过[create_approve_request](#arkid.core.extension.approve_system.ApproveSystemExtension.create_approve_request)将审批请求发送到其他第三方系统处理 | ||
|
||
* 其他第三方审批系统处理完审批请求后,可以将审批结果,通过覆盖接口 **/change_approve_request_status/{{approve_request_id}}/** 处理函数[change_approve_request_status](#arkid.core.extension.approve_system.ApproveSystemExtension.change_approve_request_status)处理审核结果 | ||
|
||
## 抽象方法 | ||
* [create_approve_request](#arkid.core.extension.approve_system.ApproveSystemExtension.create_approve_request) | ||
* [change_approve_request_status](#arkid.core.extension.approve_system.ApproveSystemExtension.change_approve_request_status) | ||
## 基类定义 | ||
|
||
::: arkid.core.extension.approve_system.ApproveSystemExtension | ||
rendering: | ||
show_source: true | ||
|
||
## 示例 | ||
|
||
::: extension_root.com_longgui_approve_system_arkid.ApproveSystemArkIDExtension | ||
rendering: | ||
show_source: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters