From cc48a29c723eb2249be88548e600ea5ff0b22ce8 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Fri, 10 Jan 2025 22:54:12 +0700 Subject: [PATCH] Remove Import from Tracker (#7632) Signed-off-by: Andrey Sobolev --- models/tracker/src/plugin.ts | 3 +- .../src/components/NewIssueHeader.svelte | 32 +--- plugins/tracker-resources/src/index.ts | 172 +----------------- 3 files changed, 6 insertions(+), 201 deletions(-) diff --git a/models/tracker/src/plugin.ts b/models/tracker/src/plugin.ts index 3f62f5a3c9..080bbd0113 100644 --- a/models/tracker/src/plugin.ts +++ b/models/tracker/src/plugin.ts @@ -98,8 +98,7 @@ export default mergeIds(trackerId, tracker, { EditProject: '' as ViewAction, DeleteProject: '' as ViewAction, DeleteIssue: '' as ViewAction, - DeleteMilestone: '' as ViewAction, - ImportIssues: '' as ViewAction + DeleteMilestone: '' as ViewAction }, action: { NewRelatedIssue: '' as Ref>, diff --git a/plugins/tracker-resources/src/components/NewIssueHeader.svelte b/plugins/tracker-resources/src/components/NewIssueHeader.svelte index 2495971967..6e6c81a88a 100644 --- a/plugins/tracker-resources/src/components/NewIssueHeader.svelte +++ b/plugins/tracker-resources/src/components/NewIssueHeader.svelte @@ -13,17 +13,16 @@ // limitations under the License. -->
- ): Promise { - const reader = new FileReader() - reader.readAsText(tasks) - - const personAccountById = get(personAccountByIdStore) - const personAccountList = Array.from(personAccountById.values()) - const personAccountPersonById = get(personAccountPersonByIdStore) - const personList = Array.from(get(personByIdStore).values()) - - const client = getClient() - const statuses = await client.findAll(tracker.class.IssueStatus, {}) - reader.onload = async () => { - let tasksArray: ImportIssue[] = Array.from(JSON.parse(reader.result as string)) - const personToImport = Array.from( - new Set(tasksArray.flatMap((t) => [t.createdBy, t.modifiedBy, ...t.activity.flatMap((act) => act.modifiedBy)])) - ).filter((x) => x !== undefined) as string[] - const peopleToAdd = personToImport.filter((p) => personList.find((x) => x.name === p) === undefined) - if (peopleToAdd.length > 0) { - console.log('Next people will be created to import properly', peopleToAdd) - for (const personToCreate of peopleToAdd) { - const personId = await client.createDoc(contact.class.Person, contact.space.Contacts, { - name: personToCreate, - avatarType: AvatarType.COLOR, - city: '', - comments: 0, - channels: 0, - attachments: 0 - }) - await client.createDoc(contact.class.PersonAccount, core.space.Model, { - email: `imported:${personId}`, - person: personId, - role: AccountRole.User - }) - } - } - const idsParent: Array<{ id: Ref, identifier: string }> = [] - - while (tasksArray.length > 0) { - let taskParsing: ImportIssue | undefined = tasksArray.find((t: ImportIssue) => t?.parents?.length === 0) - if (taskParsing === undefined) { - taskParsing = tasksArray.find((t: Issue) => - t?.parents?.every((p) => idsParent.findIndex((par) => par.id === p.parentId) !== -1) - ) - } - if (taskParsing != null) { - tasksArray = tasksArray.filter((t) => t._id !== taskParsing?._id) - const proj = await client.findOne(tracker.class.Project, { _id: space }) - const modifiedByPerson = personList.find((p) => p.name === taskParsing?.modifiedBy)?._id - const assignee = - taskParsing.assignee !== null ? personList.find((p) => p.name === taskParsing?.assignee)?._id ?? null : null - if (modifiedByPerson === undefined) throw new Error('Person not found') - const modifiedBy = personAccountList.find((pA) => pA.person === modifiedByPerson)?._id - if (modifiedBy === undefined) throw new Error('modifiedBy account not found') - - const collaborators = (taskParsing as any)['notification:mixin:Collaborators']?.collaborators - const collaboratorsToImport = - collaborators !== undefined - ? collaborators - .map((name: string) => { - const person = personList.find((p) => p.name === name)?._id - if (person === undefined) return undefined - const account = personAccountPersonById.get(person) - return account?._id - }) - .filter((c: any) => c !== undefined) - : undefined - - const incResult = await client.updateDoc( - tracker.class.Project, - core.space.Space, - space, - { - $inc: { sequence: 1 } - }, - true - ) - const number = (incResult as any).object.sequence - const identifier = `${proj?.identifier}-${number}` - idsParent.push({ id: taskParsing._id, identifier }) - const taskKind = proj?.type !== undefined ? { parent: proj.type } : {} - const kind = (await client.findOne(task.class.TaskType, taskKind)) as TaskType - const status = statuses.find((s) => s.name === taskParsing?.status)?._id - if (status === undefined) throw new Error('status not found') - const taskToCreate = { - title: taskParsing.title, - description: taskParsing.description, - component: taskParsing.component, - milestone: taskParsing.milestone, - number, - status, - priority: taskParsing.priority, - rank: taskParsing.rank, - comments: 0, - subIssues: 0, - dueDate: taskParsing.dueDate, - parents: taskParsing.parents.map((p) => ({ - ...p, - space, - identifier: idsParent.find((par) => par.id === p.parentId)?.identifier ?? p.identifier - })), - reportedTime: 0, - remainingTime: 0, - estimation: taskParsing.estimation, - reports: 0, - childInfo: taskParsing.childInfo, - identifier, - modifiedBy, - assignee, - kind: kind._id - } - await client.addCollection( - tracker.class.Issue, - space, - taskParsing?.attachedTo ?? tracker.ids.NoParent, - taskParsing._class, - 'subIssues', - taskToCreate, - taskParsing._id - ) - - if (collaboratorsToImport !== undefined) { - await client.createMixin( - taskParsing._id, - taskParsing._class, - space, - notification.mixin.Collaborators, - { - collaborators: collaboratorsToImport - } - ) - } - - // Push activity - if (taskParsing.activity !== undefined) { - const act = taskParsing.activity.sort((a, b) => a.modifiedOn - b.modifiedOn) - for (const activityMessage of act) { - const modifiedByPerson = personList.find((p) => p.name === activityMessage.modifiedBy)?._id - const modifiedBy = personAccountList.find((pA) => pA.person === modifiedByPerson)?._id - if (modifiedBy === undefined) throw new Error('modifiedBy account not found') - await client.addCollection( - chunter.class.ChatMessage, - space, - taskParsing._id, - tracker.class.Issue, - 'comments', - { - message: activityMessage.message - }, - activityMessage._id, - activityMessage.modifiedOn, - modifiedBy - ) - } - } - } - } - } -} - function filterComponents (doc: Component, target: Component): boolean { return doc.label.toLowerCase().trim() === target.label.toLowerCase().trim() && doc._id !== target._id } @@ -702,8 +535,7 @@ export default async (): Promise => ({ EditProject: editProject, DeleteMilestone: deleteMilestone, DeleteProject: deleteProject, - DeleteIssue: deleteIssue, - ImportIssues: importTasks + DeleteIssue: deleteIssue }, resolver: { Location: resolveLocation