Skip to content

Commit

Permalink
TSK-1032: add confirmation dialog for projects, fix sprint deleting a…
Browse files Browse the repository at this point in the history
…nd allow deleting for Owner or creator only (#2964)

Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
  • Loading branch information
ThetaDR authored Apr 17, 2023
1 parent 6bdb599 commit e4a53a1
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 59 deletions.
4 changes: 0 additions & 4 deletions models/server-tracker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
11 changes: 8 additions & 3 deletions models/tracker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -1137,8 +1142,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,
Expand Down
5 changes: 3 additions & 2 deletions plugins/tracker-assets/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@
"EditWorkflowStatuses": "Edit issue statuses",
"EditProject": "Edit project",
"DeleteProject": "Delete project",
"DeleteProjectName": "Delete project {name}?",
"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",
Expand Down
5 changes: 3 additions & 2 deletions plugins/tracker-assets/lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@
"EditWorkflowStatuses": "Редактировать статусы задач",
"EditProject": "Редактировать проект",
"DeleteProject": "Удалить проект",
"DeleteProjectName": "Удалить проект {name}?",
"ProjectHasIssues": "Для данного проекта существуют задачи, уверены, что хотите удалить? Задачи и проект будут удалены.",
"ArchiveProjectName": "Архивировать проект {name}?",
"ArchiveProjectConfirm": "Вы действительно хотите заархивировать этот проект?",
"ProjectHasIssues": "Для данного проекта существуют задачи, уверены, что хотите заархивировать?",
"ManageWorkflowStatuses": "Управлять статусами задач для команды",
"AddWorkflowStatus": "Добавить статус задачи",
"EditWorkflowStatus": "Редактировать статус задачи",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
}
function getQuery (mode: string, queries: { [key: string]: DocumentQuery<Issue> }) {
return queries[mode]
return { ...queries[mode], '$lookup.space.archived': false }
}
$: query = getQuery(mode, { assigned, created, subscribed })
</script>
Expand Down
33 changes: 24 additions & 9 deletions plugins/tracker-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ import {
issuePrioritySort,
issueStatusSort,
moveIssuesToAnotherSprint,
removeProject,
sprintSort,
subIssueQuery
} from './utils'
Expand Down Expand Up @@ -218,19 +217,32 @@ async function deleteProject (project: Project | undefined): Promise<void> {
showPopup(
MessageBox,
{
label: tracker.string.DeleteProjectName,
label: tracker.string.ArchiveProjectName,
labelProps: { name: project.name },
message: tracker.string.ProjectHasIssues
},
undefined,
(result?: boolean) => {
if (result === true) {
void removeProject(project)
void client.update(project, { archived: true })
}
}
)
} else {
await removeProject(project)
showPopup(
MessageBox,
{
label: tracker.string.ArchiveProjectName,
labelProps: { name: project.name },
message: tracker.string.ArchiveProjectConfirm
},
undefined,
(result?: boolean) => {
if (result === true) {
void client.update(project, { archived: true })
}
}
)
}
}
}
Expand Down Expand Up @@ -260,22 +272,25 @@ async function moveAndDeleteSprints (client: TxOperations, oldSprints: Sprint[],
)
}

async function deleteSprint (sprints: Sprint[]): Promise<void> {
async function deleteSprint (sprints: Sprint | Sprint[]): Promise<void> {
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)
}
}

Expand Down
3 changes: 2 additions & 1 deletion plugins/tracker-resources/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ export default mergeIds(trackerId, tracker, {
EditWorkflowStatuses: '' as IntlString,
EditProject: '' as IntlString,
DeleteProject: '' as IntlString,
DeleteProjectName: '' as IntlString,
ArchiveProjectName: '' as IntlString,
ArchiveProjectConfirm: '' as IntlString,
ProjectHasIssues: '' as IntlString,
ManageWorkflowStatuses: '' as IntlString,
AddWorkflowStatus: '' as IntlString,
Expand Down
7 changes: 1 addition & 6 deletions plugins/tracker-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -550,11 +550,6 @@ export async function getPreviousAssignees (issue: Issue): Promise<Array<Ref<Emp
})
}

export async function removeProject (project: Project): Promise<void> {
const client = getClient()
await client.removeDoc(tracker.class.Project, core.space.Space, project._id)
}

async function updateIssuesOnMove (
client: TxOperations,
applyOps: ApplyOperations,
Expand Down
6 changes: 6 additions & 0 deletions plugins/view-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
//

import core, {
AccountRole,
AttachedDoc,
CategoryType,
Class,
Client,
Collection,
Doc,
DocumentUpdate,
getCurrentAccount,
getObjectValue,
Hierarchy,
Lookup,
Expand Down Expand Up @@ -298,6 +300,8 @@ export async function buildModel (options: BuildModelOptions): Promise<Attribute
}

export async function deleteObject (client: TxOperations, object: Doc): Promise<void> {
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
Expand All @@ -309,6 +313,8 @@ export async function deleteObject (client: TxOperations, object: Doc): Promise<
}

export async function deleteObjects (client: TxOperations, objects: Doc[]): Promise<void> {
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)) {
Expand Down
31 changes: 2 additions & 29 deletions server-plugins/tracker-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import core, {
import { getMetadata } from '@hcengineering/platform'
import serverCore, { TriggerControl } from '@hcengineering/server-core'
import { addAssigneeNotification } from '@hcengineering/server-task-resources'
import tracker, { Component, Issue, IssueParentInfo, Project, TimeSpendReport, trackerId } from '@hcengineering/tracker'
import tracker, { Component, Issue, IssueParentInfo, TimeSpendReport, trackerId } from '@hcengineering/tracker'
import { workbenchId } from '@hcengineering/workbench'

async function updateSubIssues (
Expand Down Expand Up @@ -84,32 +84,6 @@ export async function addTrackerAssigneeNotification (
await addAssigneeNotification(control, res, issue, assignee, ptx)
}

/**
* @public
*/
export async function OnProjectDelete (tx: Tx, control: TriggerControl): Promise<Tx[]> {
const actualTx = TxProcessor.extractTx(tx)
if (actualTx._class !== core.class.TxRemoveDoc) {
return []
}

const ctx = actualTx as TxRemoveDoc<Project>

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
*/
Expand Down Expand Up @@ -216,8 +190,7 @@ export default async () => ({
},
trigger: {
OnIssueUpdate,
OnComponentRemove,
OnProjectDelete
OnComponentRemove
}
})

Expand Down
3 changes: 1 addition & 2 deletions server-plugins/tracker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export default plugin(serverTrackerId, {
},
trigger: {
OnIssueUpdate: '' as Resource<TriggerFunc>,
OnComponentRemove: '' as Resource<TriggerFunc>,
OnProjectDelete: '' as Resource<TriggerFunc>
OnComponentRemove: '' as Resource<TriggerFunc>
}
})

0 comments on commit e4a53a1

Please sign in to comment.