debug webhook don't require publish the app

This commit is contained in:
hjlarry 2025-10-02 20:07:57 +08:00
parent 9643fa1c9a
commit 6ea10cdaaf
2 changed files with 41 additions and 30 deletions

View File

@ -19,7 +19,7 @@ def _prepare_webhook_execution(webhook_id: str, is_debug: bool = False):
is_debug: If True, skip status validation for debug mode is_debug: If True, skip status validation for debug mode
""" """
webhook_trigger, workflow, node_config = WebhookService.get_webhook_trigger_and_workflow( webhook_trigger, workflow, node_config = WebhookService.get_webhook_trigger_and_workflow(
webhook_id, skip_status_check=is_debug webhook_id, is_debug=is_debug
) )
try: try:

View File

@ -37,13 +37,13 @@ class WebhookService:
@classmethod @classmethod
def get_webhook_trigger_and_workflow( def get_webhook_trigger_and_workflow(
cls, webhook_id: str, skip_status_check: bool = False cls, webhook_id: str, is_debug: bool = False
) -> tuple[WorkflowWebhookTrigger, Workflow, Mapping[str, Any]]: ) -> tuple[WorkflowWebhookTrigger, Workflow, Mapping[str, Any]]:
"""Get webhook trigger, workflow, and node configuration. """Get webhook trigger, workflow, and node configuration.
Args: Args:
webhook_id: The webhook ID to look up webhook_id: The webhook ID to look up
skip_status_check: If True, skip the enabled status check (for debug mode) is_debug: If True, use the draft workflow graph and skip the trigger enabled status check
Returns: Returns:
A tuple containing: A tuple containing:
@ -61,35 +61,46 @@ class WebhookService:
) )
if not webhook_trigger: if not webhook_trigger:
raise ValueError(f"Webhook not found: {webhook_id}") raise ValueError(f"Webhook not found: {webhook_id}")
# Check if the corresponding AppTrigger exists if is_debug:
app_trigger = ( workflow = (
session.query(AppTrigger) session.query(Workflow)
.filter( .filter(
AppTrigger.app_id == webhook_trigger.app_id, Workflow.app_id == webhook_trigger.app_id,
AppTrigger.node_id == webhook_trigger.node_id, Workflow.version == Workflow.VERSION_DRAFT,
AppTrigger.trigger_type == AppTriggerType.TRIGGER_WEBHOOK, )
.order_by(Workflow.created_at.desc())
.first()
) )
.first() else:
) # Check if the corresponding AppTrigger exists
app_trigger = (
if not app_trigger: session.query(AppTrigger)
raise ValueError(f"App trigger not found for webhook {webhook_id}") .filter(
AppTrigger.app_id == webhook_trigger.app_id,
# Only check enabled status if not in debug mode AppTrigger.node_id == webhook_trigger.node_id,
if not skip_status_check and app_trigger.status != AppTriggerStatus.ENABLED: AppTrigger.trigger_type == AppTriggerType.TRIGGER_WEBHOOK,
raise ValueError(f"Webhook trigger is disabled for webhook {webhook_id}") )
.first()
# Get workflow )
workflow = (
session.query(Workflow) if not app_trigger:
.filter( raise ValueError(f"App trigger not found for webhook {webhook_id}")
Workflow.app_id == webhook_trigger.app_id,
Workflow.version != Workflow.VERSION_DRAFT, # Only check enabled status if not in debug mode
if app_trigger.status != AppTriggerStatus.ENABLED:
raise ValueError(f"Webhook trigger is disabled for webhook {webhook_id}")
# Get workflow
workflow = (
session.query(Workflow)
.filter(
Workflow.app_id == webhook_trigger.app_id,
Workflow.version != Workflow.VERSION_DRAFT,
)
.order_by(Workflow.created_at.desc())
.first()
) )
.order_by(Workflow.created_at.desc())
.first()
)
if not workflow: if not workflow:
raise ValueError(f"Workflow not found for app {webhook_trigger.app_id}") raise ValueError(f"Workflow not found for app {webhook_trigger.app_id}")