From 5da6c309732d10758cb30d2f82f13386b3cdd5d2 Mon Sep 17 00:00:00 2001 From: sealday Date: Thu, 5 Sep 2024 15:07:31 +0800 Subject: [PATCH] feat(workflow): dispatcher support pass user info (#1512) Co-authored-by: sealday Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/1512 --- .../src/server/features/webhook/webhooks.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/features/webhook/webhooks.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/features/webhook/webhooks.ts index 6478802ec..23adfa7da 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/server/features/webhook/webhooks.ts +++ b/packages/plugins/@tachybase/plugin-workflow/src/server/features/webhook/webhooks.ts @@ -19,6 +19,14 @@ export class WebhookController { if (!name) { throw new Error('not support'); } + + const { currentUser, currentRole } = ctx.state; + const { model: UserModel } = ctx.db.getCollection('users'); + const userInfo = { + user: UserModel.build(currentUser).desensitize(), + roleName: currentRole, + }; + const pluginWorkflow = ctx.app.getPlugin(PluginWorkflow) as PluginWorkflow; const repo = ctx.db.getRepository('webhooks'); const webhook = await repo.findOne(where); @@ -38,7 +46,7 @@ export class WebhookController { if (webhook?.workflowKey) { const wfRepo = ctx.db.getRepository('workflows'); const wf = await wfRepo.findOne({ filter: { key: webhook.workflowKey, enabled: true } }); - const processor = await pluginWorkflow.trigger(wf, { data: webhookCtx.body }, { httpContext: ctx }); + const processor = await pluginWorkflow.trigger(wf, { data: webhookCtx.body, ...userInfo }, { httpContext: ctx }); if (!processor) { return ctx.throw('Workflow should be sync.', 500); }