feat(plugin-workflow-form): add role name to form trigger context (#3182)

* feat(plugin-workflow-form): add role name to form trigger context

* refactor(plugin-workflow-dynamic-calculation): move to extended group
This commit is contained in:
Junyi 2023-12-13 20:08:02 +08:00 committed by GitHub
parent 5c74cb6361
commit 58f1918e73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 6 deletions

View File

@ -36,7 +36,7 @@ function DynamicExpression({ value, onChange }) {
export default class extends Instruction { export default class extends Instruction {
title = `{{t("Dynamic Calculation", { ns: "${NAMESPACE}" })}}`; title = `{{t("Dynamic Calculation", { ns: "${NAMESPACE}" })}}`;
type = 'dynamic-calculation'; type = 'dynamic-calculation';
group = 'control'; group = 'extended';
description = `{{t("Calculate an expression based on a calculation engine and obtain a value as the result. Variables in the upstream nodes can be used in the expression. The expression is dynamic one from an expression collections.", { ns: "${NAMESPACE}" })}}`; description = `{{t("Calculate an expression based on a calculation engine and obtain a value as the result. Variables in the upstream nodes can be used in the expression. The expression is dynamic one from an expression collections.", { ns: "${NAMESPACE}" })}}`;
fieldset = { fieldset = {
expression: { expression: {

View File

@ -70,6 +70,8 @@ export default class extends Trigger {
const langTriggerData = useLang('Trigger data'); const langTriggerData = useLang('Trigger data');
// eslint-disable-next-line react-hooks/rules-of-hooks // eslint-disable-next-line react-hooks/rules-of-hooks
const langUserSubmittedForm = useLang('User submitted form'); const langUserSubmittedForm = useLang('User submitted form');
// eslint-disable-next-line react-hooks/rules-of-hooks
const langRoleSubmittedForm = useLang('Role of user submitted form');
const rootFields = [ const rootFields = [
{ {
collectionName: config.collection, collectionName: config.collection,
@ -89,6 +91,12 @@ export default class extends Trigger {
title: langUserSubmittedForm, title: langUserSubmittedForm,
}, },
}, },
{
name: 'roleName',
uiSchema: {
title: langRoleSubmittedForm,
},
},
]; ];
const result = getCollectionFieldOptions({ const result = getCollectionFieldOptions({
// depth, // depth,

View File

@ -4,5 +4,6 @@
"Form data model": "Form data model", "Form data model": "Form data model",
"Use a collection to match form data.": "Use a collection to match form data.", "Use a collection to match form data.": "Use a collection to match form data.",
"Associations to use": "Associations to use", "Associations to use": "Associations to use",
"User submitted form": "User submitted form" "User submitted form": "User submitted form",
"Role of user submitted form": "Role of user submitted form"
} }

View File

@ -4,5 +4,6 @@
"Form data model": "表单数据模型", "Form data model": "表单数据模型",
"Use a collection to match form data.": "使用一个数据表来匹配表单数据。", "Use a collection to match form data.": "使用一个数据表来匹配表单数据。",
"Associations to use": "待使用的关系数据", "Associations to use": "待使用的关系数据",
"User submitted form": "提交表单的用户" "User submitted form": "提交表单的用户",
"Role of user submitted form": "提交表单用户的角色"
} }

View File

@ -51,7 +51,11 @@ export default class extends Trigger {
private async trigger(context) { private async trigger(context) {
const { triggerWorkflows = '', values } = context.action.params; const { triggerWorkflows = '', values } = context.action.params;
const { currentUser } = context.state; const { currentUser, currentRole } = context.state;
const userInfo = {
user: toJSON(currentUser),
roleName: currentRole,
};
const triggers = triggerWorkflows.split(',').map((trigger) => trigger.split('!')); const triggers = triggerWorkflows.split(',').map((trigger) => trigger.split('!'));
const workflowRepo = this.plugin.db.getRepository('workflows'); const workflowRepo = this.plugin.db.getRepository('workflows');
@ -91,13 +95,13 @@ export default class extends Trigger {
appends, appends,
}); });
} }
this.plugin.trigger(workflow, { data: toJSON(payload), user: toJSON(currentUser) }); this.plugin.trigger(workflow, { data: toJSON(payload), ...userInfo });
}); });
} else { } else {
const data = trigger[1] ? get(values, trigger[1]) : values; const data = trigger[1] ? get(values, trigger[1]) : values;
this.plugin.trigger(workflow, { this.plugin.trigger(workflow, {
data, data,
user: currentUser, ...userInfo,
}); });
} }
}); });