From 0fe4b6a09ff67852ea3fae92a384b9c091e19457 Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Mon, 12 Feb 2024 16:30:31 +0600 Subject: [PATCH] Restrict taskType descriptors (#4605) Signed-off-by: Denis Bykhov --- models/board/src/index.ts | 3 +- models/lead/src/index.ts | 3 +- models/recruit/src/index.ts | 3 +- models/task/src/index.ts | 2 + models/tracker/src/index.ts | 3 +- .../taskTypes/CreateTaskType.svelte | 47 +++++++++++-------- plugins/task/src/index.ts | 1 + 7 files changed, 38 insertions(+), 24 deletions(-) diff --git a/models/board/src/index.ts b/models/board/src/index.ts index e3e1e34ea3..e0b91e6c2f 100644 --- a/models/board/src/index.ts +++ b/models/board/src/index.ts @@ -504,7 +504,8 @@ export function createModel (builder: Builder): void { name: board.string.BoardApplication, description: board.string.ManageBoardStatuses, icon: board.icon.Board, - baseClass: board.class.Board + baseClass: board.class.Board, + allowedTaskTypeDescriptors: [board.descriptors.Card] }, board.descriptors.BoardType ) diff --git a/models/lead/src/index.ts b/models/lead/src/index.ts index 2cb82dfea5..12ce255aef 100644 --- a/models/lead/src/index.ts +++ b/models/lead/src/index.ts @@ -703,7 +703,8 @@ export function createModel (builder: Builder): void { name: lead.string.LeadApplication, description: lead.string.ManageFunnelStatuses, icon: lead.icon.LeadApplication, - baseClass: lead.class.Funnel + baseClass: lead.class.Funnel, + allowedTaskTypeDescriptors: [lead.descriptors.Lead] }, lead.descriptors.FunnelType ) diff --git a/models/recruit/src/index.ts b/models/recruit/src/index.ts index eb9dc6f9e2..5dfeb8048a 100644 --- a/models/recruit/src/index.ts +++ b/models/recruit/src/index.ts @@ -1779,7 +1779,8 @@ export function createModel (builder: Builder): void { description: recruit.string.ManageVacancyStatuses, icon: recruit.icon.RecruitApplication, editor: recruit.component.VacancyTemplateEditor, - baseClass: recruit.class.Vacancy + baseClass: recruit.class.Vacancy, + allowedTaskTypeDescriptors: [recruit.descriptors.Application] }, recruit.descriptors.VacancyType ) diff --git a/models/task/src/index.ts b/models/task/src/index.ts index 7f38c27629..12b89a4551 100644 --- a/models/task/src/index.ts +++ b/models/task/src/index.ts @@ -236,6 +236,8 @@ export class TProjectTypeDescriptor extends TDoc implements ProjectTypeDescripto description!: IntlString icon!: Asset editor?: AnyComponent + allowedClassic?: boolean + allowedTaskTypeDescriptors?: Ref[] // if undefined we allow all possible baseClass!: Ref> } diff --git a/models/tracker/src/index.ts b/models/tracker/src/index.ts index e7ee968ec3..30a1ce183c 100644 --- a/models/tracker/src/index.ts +++ b/models/tracker/src/index.ts @@ -673,7 +673,8 @@ export function createModel (builder: Builder): void { description: tracker.string.ManageWorkflowStatuses, icon: task.icon.Task, baseClass: tracker.class.Project, - allowedClassic: true + allowedClassic: true, + allowedTaskTypeDescriptors: [tracker.descriptors.Issue] }, tracker.descriptors.ProjectType ) diff --git a/plugins/task-resources/src/components/taskTypes/CreateTaskType.svelte b/plugins/task-resources/src/components/taskTypes/CreateTaskType.svelte index 79b49497af..0815cc41a1 100644 --- a/plugins/task-resources/src/components/taskTypes/CreateTaskType.svelte +++ b/plugins/task-resources/src/components/taskTypes/CreateTaskType.svelte @@ -57,7 +57,12 @@ const taskTypeDescriptors = client .getModel() - .findAllSync(task.class.TaskTypeDescriptor, { allowCreate: true }) + .findAllSync( + task.class.TaskTypeDescriptor, + descriptor.allowedTaskTypeDescriptors + ? { allowCreate: true, _id: { $in: descriptor.allowedTaskTypeDescriptors } } + : { allowCreate: true } + ) .filter((p) => hasResource(p._id as any as Resource)) let { kind, name, targetClass, statusCategories, statuses, allowedAsChildOf } = @@ -176,24 +181,26 @@ -
- - - { - if (evt.detail != null) { - const tt = taskTypeDescriptors.find((tt) => tt._id === evt.detail) - if (tt) taskTypeDescriptor = tt - } - }} - /> -
+ {#if taskTypeDescriptors.length > 1} +
+ + + { + if (evt.detail != null) { + const tt = taskTypeDescriptors.find((tt) => tt._id === evt.detail) + if (tt) taskTypeDescriptor = tt + } + }} + /> +
+ {/if} diff --git a/plugins/task/src/index.ts b/plugins/task/src/index.ts index c6f15684ca..0810883c4f 100644 --- a/plugins/task/src/index.ts +++ b/plugins/task/src/index.ts @@ -176,6 +176,7 @@ export interface ProjectTypeDescriptor extends Doc { icon: Asset editor?: AnyComponent allowedClassic?: boolean + allowedTaskTypeDescriptors?: Ref[] // if undefined we allow all possible baseClass: Ref> }