Files
dify/api/services/openapi_execution_service.py
583615e412 feat: support personal access token (#45540)
Co-authored-by: twwu <twwu@dify.ai>
Co-authored-by: Eldar Dadashov <52511672+eldardada@users.noreply.github.com>
Co-authored-by: Byron.wang <byron@dify.ai>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Yunlu Wen <yunlu.wen@dify.ai>
2026-11-11 03:00:24 +00:00

39 lines
1.1 KiB
Python

"""App ownership checks for OpenAPI operations on previously started executions."""
from collections.abc import Callable
from models.enums import CreatorUserRole
from repositories.api_workflow_run_repository import APIWorkflowRunRepository
class OpenApiExecutionNotFoundError(Exception):
"""The execution is absent or belongs to another app."""
class OpenApiExecutionService:
def __init__(
self,
*,
runs: Callable[[], APIWorkflowRunRepository],
) -> None:
self._runs = runs
def require_workflow_owner(
self,
*,
run_id: str | None,
tenant_id: str,
app_id: str,
account_id: str,
) -> None:
if run_id is None:
raise OpenApiExecutionNotFoundError()
run = self._runs().get_workflow_run_by_id_and_tenant_id(tenant_id=tenant_id, run_id=run_id)
if (
run is None
or run.app_id != app_id
or run.created_by_role != CreatorUserRole.ACCOUNT
or run.created_by != account_id
):
raise OpenApiExecutionNotFoundError()