From 88245d51578aaccc0223b8918e4f7c78709d9e51 Mon Sep 17 00:00:00 2001 From: Vyacheslav Tumanov Date: Wed, 12 Apr 2023 19:20:35 +0500 Subject: [PATCH 1/6] TSK-1032: add confirmation dialog for projects, fix sprint deleting, allow deleting for Owner or creator only Signed-off-by: Vyacheslav Tumanov --- plugins/tracker-assets/lang/en.json | 1 + plugins/tracker-resources/src/index.ts | 28 +++++++++++++++++++------ plugins/tracker-resources/src/plugin.ts | 1 + plugins/view-resources/src/utils.ts | 6 ++++++ 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/plugins/tracker-assets/lang/en.json b/plugins/tracker-assets/lang/en.json index 89d7510743..f2d3073992 100644 --- a/plugins/tracker-assets/lang/en.json +++ b/plugins/tracker-assets/lang/en.json @@ -181,6 +181,7 @@ "EditProject": "Edit project", "DeleteProject": "Delete project", "DeleteProjectName": "Delete project {name}?", + "DeleteProjectConfirm": "Do you want to delete this project?", "ProjectHasIssues": "There are existing issues in this project, are you sure that you want to delete? Both the project and the issues will be deleted.", "ManageWorkflowStatuses": "Manage issue statuses within project", "AddWorkflowStatus": "Add issue status", diff --git a/plugins/tracker-resources/src/index.ts b/plugins/tracker-resources/src/index.ts index a8523cc887..9d3193c7b7 100644 --- a/plugins/tracker-resources/src/index.ts +++ b/plugins/tracker-resources/src/index.ts @@ -230,7 +230,20 @@ async function deleteProject (project: Project | undefined): Promise { } ) } else { - await removeProject(project) + showPopup( + MessageBox, + { + label: tracker.string.DeleteProjectName, + labelProps: { name: project.name }, + message: tracker.string.DeleteProjectConfirm + }, + undefined, + (result?: boolean) => { + if (result === true) { + void removeProject(project) + } + } + ) } } } @@ -260,22 +273,25 @@ async function moveAndDeleteSprints (client: TxOperations, oldSprints: Sprint[], ) } -async function deleteSprint (sprints: Sprint[]): Promise { +async function deleteSprint (sprints: Sprint | Sprint[]): Promise { const client = getClient() + const sprintArray = Array.isArray(sprints) ? sprints : [sprints] // Check if available to move issues to another sprint - const firstSearchedSprint = await client.findOne(tracker.class.Sprint, { _id: { $nin: sprints.map((p) => p._id) } }) + const firstSearchedSprint = await client.findOne(tracker.class.Sprint, { + _id: { $nin: sprintArray.map((p) => p._id) } + }) if (firstSearchedSprint !== undefined) { showPopup( MoveAndDeleteSprintPopup, { - sprints, + sprintArray, moveAndDeleteSprint: async (selectedSprint?: Sprint) => - await moveAndDeleteSprints(client, sprints, selectedSprint) + await moveAndDeleteSprints(client, sprintArray, selectedSprint) }, 'top' ) } else { - await moveAndDeleteSprints(client, sprints) + await moveAndDeleteSprints(client, sprintArray) } } diff --git a/plugins/tracker-resources/src/plugin.ts b/plugins/tracker-resources/src/plugin.ts index 266005e9a1..b401e5fbd6 100644 --- a/plugins/tracker-resources/src/plugin.ts +++ b/plugins/tracker-resources/src/plugin.ts @@ -99,6 +99,7 @@ export default mergeIds(trackerId, tracker, { EditProject: '' as IntlString, DeleteProject: '' as IntlString, DeleteProjectName: '' as IntlString, + DeleteProjectConfirm: '' as IntlString, ProjectHasIssues: '' as IntlString, ManageWorkflowStatuses: '' as IntlString, AddWorkflowStatus: '' as IntlString, diff --git a/plugins/view-resources/src/utils.ts b/plugins/view-resources/src/utils.ts index c841b1fec7..0477ae808d 100644 --- a/plugins/view-resources/src/utils.ts +++ b/plugins/view-resources/src/utils.ts @@ -15,6 +15,7 @@ // import core, { + AccountRole, AttachedDoc, CategoryType, Class, @@ -22,6 +23,7 @@ import core, { Collection, Doc, DocumentUpdate, + getCurrentAccount, getObjectValue, Hierarchy, Lookup, @@ -298,6 +300,8 @@ export async function buildModel (options: BuildModelOptions): Promise { + const currentAcc = getCurrentAccount() + if (currentAcc.role !== AccountRole.Owner && object.createdBy !== currentAcc._id) return if (client.getHierarchy().isDerived(object._class, core.class.AttachedDoc)) { const adoc = object as AttachedDoc await client @@ -309,6 +313,8 @@ export async function deleteObject (client: TxOperations, object: Doc): Promise< } export async function deleteObjects (client: TxOperations, objects: Doc[]): Promise { + const currentAcc = getCurrentAccount() + if (currentAcc.role !== AccountRole.Owner && objects.some((p) => p.createdBy !== currentAcc._id)) return const ops = client.apply('delete') for (const object of objects) { if (client.getHierarchy().isDerived(object._class, core.class.AttachedDoc)) { From e29ca88314066317a2d302974556d935a1e28dd1 Mon Sep 17 00:00:00 2001 From: Vyacheslav Tumanov Date: Thu, 13 Apr 2023 12:33:36 +0500 Subject: [PATCH 2/6] TSK-1032: Use generic function for deleting Signed-off-by: Vyacheslav Tumanov --- plugins/tracker-resources/src/index.ts | 5 ++--- plugins/tracker-resources/src/utils.ts | 4 ---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/plugins/tracker-resources/src/index.ts b/plugins/tracker-resources/src/index.ts index 9d3193c7b7..b731db314d 100644 --- a/plugins/tracker-resources/src/index.ts +++ b/plugins/tracker-resources/src/index.ts @@ -119,7 +119,6 @@ import { issuePrioritySort, issueStatusSort, moveIssuesToAnotherSprint, - removeProject, sprintSort, subIssueQuery } from './utils' @@ -225,7 +224,7 @@ async function deleteProject (project: Project | undefined): Promise { undefined, (result?: boolean) => { if (result === true) { - void removeProject(project) + void deleteObject(client, project) } } ) @@ -240,7 +239,7 @@ async function deleteProject (project: Project | undefined): Promise { undefined, (result?: boolean) => { if (result === true) { - void removeProject(project) + void deleteObject(client, project) } } ) diff --git a/plugins/tracker-resources/src/utils.ts b/plugins/tracker-resources/src/utils.ts index d9aa00bcc8..7c528ce5d9 100644 --- a/plugins/tracker-resources/src/utils.ts +++ b/plugins/tracker-resources/src/utils.ts @@ -550,10 +550,6 @@ export async function getPreviousAssignees (issue: Issue): Promise { - const client = getClient() - await client.removeDoc(tracker.class.Project, core.space.Space, project._id) -} async function updateIssuesOnMove ( client: TxOperations, From d704a7bb717134eade3ad0bf6f4527fd56bb623b Mon Sep 17 00:00:00 2001 From: Vyacheslav Tumanov Date: Fri, 14 Apr 2023 17:00:01 +0500 Subject: [PATCH 3/6] TSK-1032: Remove trigger when deleting projects and change deletion to archiving Signed-off-by: Vyacheslav Tumanov --- models/server-tracker/src/index.ts | 4 --- models/tracker/src/index.ts | 4 +-- plugins/tracker-resources/src/index.ts | 4 +-- plugins/tracker-resources/src/utils.ts | 3 +- server-plugins/tracker-resources/src/index.ts | 31 ++----------------- server-plugins/tracker/src/index.ts | 3 +- 6 files changed, 8 insertions(+), 41 deletions(-) diff --git a/models/server-tracker/src/index.ts b/models/server-tracker/src/index.ts index dba4f2ac14..fe1ebe0303 100644 --- a/models/server-tracker/src/index.ts +++ b/models/server-tracker/src/index.ts @@ -36,8 +36,4 @@ export function createModel (builder: Builder): void { builder.createDoc(serverCore.class.Trigger, core.space.Model, { trigger: serverTracker.trigger.OnComponentRemove }) - - builder.createDoc(serverCore.class.Trigger, core.space.Model, { - trigger: serverTracker.trigger.OnProjectDelete - }) } diff --git a/models/tracker/src/index.ts b/models/tracker/src/index.ts index 83e3768585..56af9339a7 100644 --- a/models/tracker/src/index.ts +++ b/models/tracker/src/index.ts @@ -1137,8 +1137,8 @@ export function createModel (builder: Builder): void { builder, { action: tracker.actionImpl.DeleteProject, - label: tracker.string.DeleteProject, - icon: view.icon.Delete, + label: workbench.string.Archive, + icon: view.icon.Archive, input: 'focus', category: tracker.category.Tracker, target: tracker.class.Project, diff --git a/plugins/tracker-resources/src/index.ts b/plugins/tracker-resources/src/index.ts index b731db314d..90334b1235 100644 --- a/plugins/tracker-resources/src/index.ts +++ b/plugins/tracker-resources/src/index.ts @@ -224,7 +224,7 @@ async function deleteProject (project: Project | undefined): Promise { undefined, (result?: boolean) => { if (result === true) { - void deleteObject(client, project) + void client.update(project, { archived: true }) } } ) @@ -239,7 +239,7 @@ async function deleteProject (project: Project | undefined): Promise { undefined, (result?: boolean) => { if (result === true) { - void deleteObject(client, project) + void client.update(project, { archived: true }) } } ) diff --git a/plugins/tracker-resources/src/utils.ts b/plugins/tracker-resources/src/utils.ts index 7c528ce5d9..bcc20dc93b 100644 --- a/plugins/tracker-resources/src/utils.ts +++ b/plugins/tracker-resources/src/utils.ts @@ -33,7 +33,7 @@ import core, { TxUpdateDoc } from '@hcengineering/core' import { Asset, IntlString } from '@hcengineering/platform' -import { createQuery, getClient } from '@hcengineering/presentation' +import { createQuery } from '@hcengineering/presentation' import { calcRank } from '@hcengineering/task' import { ComponentStatus, @@ -550,7 +550,6 @@ export async function getPreviousAssignees (issue: Issue): Promise { - const actualTx = TxProcessor.extractTx(tx) - if (actualTx._class !== core.class.TxRemoveDoc) { - return [] - } - - const ctx = actualTx as TxRemoveDoc - - if (ctx.objectClass !== tracker.class.Project) { - return [] - } - const issues = await control.findAll(tracker.class.Issue, { - space: ctx.objectId - }) - - const res: Tx[] = [] - issues.forEach((issue) => { - res.push(control.txFactory.createTxRemoveDoc(issue._class, issue.space, issue._id)) - }) - - return res -} - /** * @public */ @@ -216,8 +190,7 @@ export default async () => ({ }, trigger: { OnIssueUpdate, - OnComponentRemove, - OnProjectDelete + OnComponentRemove } }) diff --git a/server-plugins/tracker/src/index.ts b/server-plugins/tracker/src/index.ts index c2dda5a8ac..11cbd7dacc 100644 --- a/server-plugins/tracker/src/index.ts +++ b/server-plugins/tracker/src/index.ts @@ -33,7 +33,6 @@ export default plugin(serverTrackerId, { }, trigger: { OnIssueUpdate: '' as Resource, - OnComponentRemove: '' as Resource, - OnProjectDelete: '' as Resource + OnComponentRemove: '' as Resource } }) From 4a83cf13a6503cac6665ef3103d8aa0bee9300a7 Mon Sep 17 00:00:00 2001 From: Vyacheslav Tumanov Date: Fri, 14 Apr 2023 17:00:29 +0500 Subject: [PATCH 4/6] TSK-1032: do not show issues from archived projects in MyIssues Signed-off-by: Vyacheslav Tumanov --- models/tracker/src/index.ts | 7 ++++++- .../src/components/myissues/MyIssues.svelte | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/models/tracker/src/index.ts b/models/tracker/src/index.ts index 56af9339a7..cad953cb36 100644 --- a/models/tracker/src/index.ts +++ b/models/tracker/src/index.ts @@ -594,7 +594,12 @@ export function createModel (builder: Builder): void { presenter: tracker.component.AssigneePresenter, props: { defaultClass: contact.class.Employee, shouldShowLabel: false } } - ] + ], + options: { + lookup: { + space: tracker.class.Project + } + } }, tracker.viewlet.IssueList ) diff --git a/plugins/tracker-resources/src/components/myissues/MyIssues.svelte b/plugins/tracker-resources/src/components/myissues/MyIssues.svelte index e44aebb737..5f62778ae8 100644 --- a/plugins/tracker-resources/src/components/myissues/MyIssues.svelte +++ b/plugins/tracker-resources/src/components/myissues/MyIssues.svelte @@ -54,7 +54,7 @@ } function getQuery (mode: string, queries: { [key: string]: DocumentQuery }) { - return queries[mode] + return { ...queries[mode], '$lookup.space.archived': false } } $: query = getQuery(mode, { assigned, created, subscribed }) From 0a6929f9aae545fcc4c926ad1af2d79a94d8319d Mon Sep 17 00:00:00 2001 From: Vyacheslav Tumanov Date: Fri, 14 Apr 2023 17:06:45 +0500 Subject: [PATCH 5/6] TSK-1032: Ru translation for DeleteProjectConfirm Signed-off-by: Vyacheslav Tumanov --- plugins/tracker-assets/lang/ru.json | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/tracker-assets/lang/ru.json b/plugins/tracker-assets/lang/ru.json index dd8458e9e5..599fa3bf38 100644 --- a/plugins/tracker-assets/lang/ru.json +++ b/plugins/tracker-assets/lang/ru.json @@ -181,6 +181,7 @@ "EditProject": "Редактировать проект", "DeleteProject": "Удалить проект", "DeleteProjectName": "Удалить проект {name}?", + "DeleteProjectConfirm": "Вы действительно хотите удалить этот проект?", "ProjectHasIssues": "Для данного проекта существуют задачи, уверены, что хотите удалить? Задачи и проект будут удалены.", "ManageWorkflowStatuses": "Управлять статусами задач для команды", "AddWorkflowStatus": "Добавить статус задачи", From 7ce20e3ba3fe1bfe54f8024b97d05e2fbfd0c270 Mon Sep 17 00:00:00 2001 From: Vyacheslav Tumanov Date: Mon, 17 Apr 2023 10:36:17 +0500 Subject: [PATCH 6/6] TSK-1032: Redo translations for archiving Signed-off-by: Vyacheslav Tumanov --- plugins/tracker-assets/lang/en.json | 6 +++--- plugins/tracker-assets/lang/ru.json | 6 +++--- plugins/tracker-resources/src/index.ts | 6 +++--- plugins/tracker-resources/src/plugin.ts | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/plugins/tracker-assets/lang/en.json b/plugins/tracker-assets/lang/en.json index f2d3073992..e3d36b0fd2 100644 --- a/plugins/tracker-assets/lang/en.json +++ b/plugins/tracker-assets/lang/en.json @@ -180,9 +180,9 @@ "EditWorkflowStatuses": "Edit issue statuses", "EditProject": "Edit project", "DeleteProject": "Delete project", - "DeleteProjectName": "Delete project {name}?", - "DeleteProjectConfirm": "Do you want to delete this project?", - "ProjectHasIssues": "There are existing issues in this project, are you sure that you want to delete? Both the project and the issues will be deleted.", + "ArchiveProjectName": "Archive project {name}?", + "ArchiveProjectConfirm": "Do you want to archive this project?", + "ProjectHasIssues": "There are existing issues in this project, are you sure that you want to archive?", "ManageWorkflowStatuses": "Manage issue statuses within project", "AddWorkflowStatus": "Add issue status", "EditWorkflowStatus": "Edit issue status", diff --git a/plugins/tracker-assets/lang/ru.json b/plugins/tracker-assets/lang/ru.json index 599fa3bf38..a4ff6ed4a8 100644 --- a/plugins/tracker-assets/lang/ru.json +++ b/plugins/tracker-assets/lang/ru.json @@ -180,9 +180,9 @@ "EditWorkflowStatuses": "Редактировать статусы задач", "EditProject": "Редактировать проект", "DeleteProject": "Удалить проект", - "DeleteProjectName": "Удалить проект {name}?", - "DeleteProjectConfirm": "Вы действительно хотите удалить этот проект?", - "ProjectHasIssues": "Для данного проекта существуют задачи, уверены, что хотите удалить? Задачи и проект будут удалены.", + "ArchiveProjectName": "Архивировать проект {name}?", + "ArchiveProjectConfirm": "Вы действительно хотите заархивировать этот проект?", + "ProjectHasIssues": "Для данного проекта существуют задачи, уверены, что хотите заархивировать?", "ManageWorkflowStatuses": "Управлять статусами задач для команды", "AddWorkflowStatus": "Добавить статус задачи", "EditWorkflowStatus": "Редактировать статус задачи", diff --git a/plugins/tracker-resources/src/index.ts b/plugins/tracker-resources/src/index.ts index 90334b1235..5a1f556a1a 100644 --- a/plugins/tracker-resources/src/index.ts +++ b/plugins/tracker-resources/src/index.ts @@ -217,7 +217,7 @@ async function deleteProject (project: Project | undefined): Promise { showPopup( MessageBox, { - label: tracker.string.DeleteProjectName, + label: tracker.string.ArchiveProjectName, labelProps: { name: project.name }, message: tracker.string.ProjectHasIssues }, @@ -232,9 +232,9 @@ async function deleteProject (project: Project | undefined): Promise { showPopup( MessageBox, { - label: tracker.string.DeleteProjectName, + label: tracker.string.ArchiveProjectName, labelProps: { name: project.name }, - message: tracker.string.DeleteProjectConfirm + message: tracker.string.ArchiveProjectConfirm }, undefined, (result?: boolean) => { diff --git a/plugins/tracker-resources/src/plugin.ts b/plugins/tracker-resources/src/plugin.ts index b401e5fbd6..52361eb5c9 100644 --- a/plugins/tracker-resources/src/plugin.ts +++ b/plugins/tracker-resources/src/plugin.ts @@ -98,8 +98,8 @@ export default mergeIds(trackerId, tracker, { EditWorkflowStatuses: '' as IntlString, EditProject: '' as IntlString, DeleteProject: '' as IntlString, - DeleteProjectName: '' as IntlString, - DeleteProjectConfirm: '' as IntlString, + ArchiveProjectName: '' as IntlString, + ArchiveProjectConfirm: '' as IntlString, ProjectHasIssues: '' as IntlString, ManageWorkflowStatuses: '' as IntlString, AddWorkflowStatus: '' as IntlString,