Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bkflow/apigw/docs/apigw-docs.zip
Binary file not shown.
28 changes: 10 additions & 18 deletions bkflow/apigw/docs/zh/sdk_create_mock_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@

#### 接口参数

| 字段 | 类型 | 必选 | 描述 |
|----------------------|--------|----|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| name | string | 是 | 任务名 |
| creator | string | 是 | 创建者 |
| description | string | 否 | 描述 |
| constants | dict | 否 | 任务启动参数 |
| credentials | dict | 否 | 凭证字典,用于传递API调用所需的凭证信息,详见下方说明 |
| custom_span_attributes | dict | 否 | 自定义 Span 属性,会添加到所有节点上报的 Span 中,详见下方说明 |
| mock_data | dict | 否 | mock 数据,包含 nodes(mock 任务使用 mock 执行的节点),outputs(可选参数,mock 执行对应节点的节点输出),mock_data_ids(mock 执行对应节点使用的 mock 数据 id,如果 outputs 没有传参,则会自动将创建任务时对应的 mock 数据 作为 outputs) |
| 字段 | 类型 | 必选 | 描述 |
|------------------------|----------|----|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| name | string | 是 | 任务名 |
| creator | string | 是 | 创建者 |
| pipeline_tree | dict | 是 | 模板流程数据 |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ 文档标注 pipeline_tree 为必选参数(必选: 是),但实际代码中 CreateMockTaskWithTemplateIdSerializer 并没有此字段,pipeline_tree 是由后端根据 template_id 自动获取的(优先草稿版本)。此处文档与代码实现不一致,建议移除该字段或标注为「由系统自动填充,无需传入」。

| description | string | 否 | 描述 |
| constants | dict | 否 | 任务启动参数 |
| credentials | dict | 否 | 凭证字典,用于传递API调用所需的凭证信息,详见下方说明 |
| custom_span_attributes | dict | 否 | 自定义 Span 属性,会添加到所有节点上报的 Span 中,详见下方说明 |
| mock_data | dict | 否 | mock 数据,包含 nodes(mock 任务使用 mock 执行的节点),outputs(可选参数,mock 执行对应节点的节点输出),mock_data_ids(mock 执行对应节点使用的 mock 数据 id,如果 outputs 没有传参,则会自动将创建任务时对应的 mock 数据 作为 outputs) |

### credentials 参数说明

Expand Down Expand Up @@ -97,15 +98,6 @@
- 这些属性会通过 `TaskContext` 传递到所有节点的 Span 中
- 自定义属性的优先级高于默认的 Span 属性(如 space_id、task_id 等),如果 key 相同会被覆盖

### pipeline_tree 版本说明

创建 mock 任务时,系统会自动选择使用的流程版本:

1. **优先使用草稿版本**:如果当前模板存在草稿版本的流程(`draft=True`),则使用草稿版本的 `pipeline_tree` 创建调试任务
2. **使用最新发布版本**:如果当前模板没有草稿版本,则使用最新发布版本的 `pipeline_tree` 创建调试任务

这样可以确保在调试时优先使用最新的未发布修改,如果没有草稿版本则使用已发布的稳定版本。

### 请求参数示例

基础请求参数示例:
Expand Down
2 changes: 1 addition & 1 deletion bkflow/apigw/management/commands/data/api-resources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5435,7 +5435,7 @@ paths:
disabledStages: []
enableWebsocket: false
pluginConfigs: []
/sdk/api/plugin_service/logs/:
/sdk/plugin_service/logs/:
post:
operationId: sdk_get_plugin_service_logs
summary: Get plugin service logs
Expand Down
19 changes: 13 additions & 6 deletions bkflow/interface/task/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
)
from bkflow.interface.task.utils import StageConstantHandler, StageJobStateHandler
from bkflow.label.models import Label
from bkflow.permission.models import TASK_PERMISSION_TYPE, Token
from bkflow.permission.models import TASK_PERMISSION_TYPE, ResourceType, Token
from bkflow.space.configs import SuperusersConfig
from bkflow.space.models import SpaceConfig
from bkflow.space.permissions import SpaceSuperuserPermission
Expand Down Expand Up @@ -155,17 +155,24 @@ def _inject_user_task_auth(request, data):
resource_id=f"{task_detail['scope_type']}_{task_detail['scope_value']}", resource_type="SCOPE"
) | Q(resource_id=task_detail["id"], resource_type="TASK")

# 只有当任务是MOCK调试任务时,可以TEMPLATE的MOCK权限条件
if task_detail.get("create_method") == "MOCK":
base_query |= Q(resource_id=task_detail["template_id"], resource_type="TEMPLATE")
base_query |= Q(resource_id=task_detail["template_id"], resource_type="TEMPLATE")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ 移除了 create_method == "MOCK" 的条件判断后,所有任务都会查询 TEMPLATE 权限。但 Task 模型中 template_id 允许为 null(null=True, blank=True),对于没有关联模板的任务,task_detail["template_id"] 可能为 None,会产生 Q(resource_id=None, resource_type="TEMPLATE") 的无效查询。建议加判空保护:if task_detail.get("template_id"): base_query |= ...

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ 此前报告的 template_id 判空问题仍存在。Task 模型中 template_id = BigIntegerField(null=True),对于非模板创建的任务此值可能为 None,会产生无效查询。建议:if task_detail.get("template_id"): base_query |= Q(...)


permissions = Token.objects.filter(
base_query,
space_id=task_detail["space_id"],
user=request.user.username,
expired_time__gte=timezone.now(),
).values_list("permission_type", flat=True)
task_detail["auth"] = list(set(permissions))
).values_list("resource_type", "permission_type")

# 模板权限增加 FLOW_ 前缀,便于前端区分模板权限与任务/作用域权限
auth_set = set()
for resource_type, permission_type in permissions:
if resource_type == ResourceType.TEMPLATE.value:
auth_set.add(f"FLOW_{permission_type}")
else:
auth_set.add(permission_type)

task_detail["auth"] = list(auth_set)

def get_space_id(self, request):
request_space_id = request.query_params.get("space_id", None) or request.data.get("space_id", None)
Expand Down
Binary file removed packages/bamboo_engine-2.11.1rc6-py3-none-any.whl
Binary file not shown.
Binary file removed packages/bamboo_pipeline-3.29.6rc6-py3-none-any.whl
Binary file not shown.
Binary file not shown.
7 changes: 2 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,14 @@ bk-notice-sdk==1.3.0

# engine service
boto3==1.26.133
# bamboo-pipeline==3.29.5
./packages/bamboo_engine-2.11.1rc6-py3-none-any.whl
./packages/bamboo_pipeline-3.29.6rc6-py3-none-any.whl
bamboo-pipeline==3.29.7
pydantic==1.10.6
django-extensions==3.2.1

# bkflow feel
bkflow-feel==1.2.0
bkflow-dmn==0.2.0
# bkflow-django-webhook==1.2.4
./packages/bkflow_django_webhook-1.2.5-py2.py3-none-any.whl
bkflow-django-webhook==1.2.5

# pytimeparse
pytimeparse == 1.1.8
Expand Down
5 changes: 4 additions & 1 deletion tests/interface/task/test_task_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ def test_inject_user_task_auth_with_token_permissions(self):
"data": {
"id": "123",
"space_id": self.space.id,
"template_id": "123",
"scope_type": "project",
"scope_value": "456",
},
Expand Down Expand Up @@ -320,6 +321,7 @@ def test_inject_user_task_auth_with_scope_permissions(self):
"data": {
"id": "123",
"space_id": self.space.id,
"template_id": "123",
"scope_type": "project",
"scope_value": "456",
},
Expand Down Expand Up @@ -361,7 +363,7 @@ def test_inject_user_task_auth_mock_task_with_template_permission(self):

TaskInterfaceViewSet._inject_user_task_auth(request, data)

assert PermissionType.MOCK.value in data["data"]["auth"]
assert "FLOW_MOCK" in data["data"]["auth"]

def test_inject_user_task_auth_result_false(self):
"""Test _inject_user_task_auth when result is False"""
Expand Down Expand Up @@ -486,6 +488,7 @@ def test_get_task_detail(self, mock_client_class):
"id": "123",
"name": "Test Task",
"space_id": self.space.id,
"template_id": "123",
"scope_type": "project",
"scope_value": "456",
},
Expand Down
Loading