Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSK-1032: add confirmation dialog for projects, fix sprint deleting and allow deleting for Owner or creator only #2964

Merged
merged 6 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions plugins/tracker-assets/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
"EditProject": "Edit project",
"DeleteProject": "Delete project",
"DeleteProjectName": "Delete project {name}?",
"DeleteProjectConfirm": "Do you want to delete this project?",
ThetaDR marked this conversation as resolved.
Show resolved Hide resolved
"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",
Expand Down
1 change: 1 addition & 0 deletions plugins/tracker-assets/lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
"EditProject": "Редактировать проект",
"DeleteProject": "Удалить проект",
"DeleteProjectName": "Удалить проект {name}?",
"DeleteProjectConfirm": "Вы действительно хотите удалить этот проект?",
"ProjectHasIssues": "Для данного проекта существуют задачи, уверены, что хотите удалить? Задачи и проект будут удалены.",
"ManageWorkflowStatuses": "Управлять статусами задач для команды",
"AddWorkflowStatus": "Добавить статус задачи",
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 }
ThetaDR marked this conversation as resolved.
Show resolved Hide resolved
}
$: query = getQuery(mode, { assigned, created, subscribed })
</script>
Expand Down
31 changes: 23 additions & 8 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 @@ -225,12 +224,25 @@ async function deleteProject (project: Project | undefined): Promise<void> {
undefined,
(result?: boolean) => {
if (result === true) {
void removeProject(project)
void client.update(project, { archived: true })
}
}
)
} else {
await removeProject(project)
showPopup(
ThetaDR marked this conversation as resolved.
Show resolved Hide resolved
MessageBox,
{
label: tracker.string.DeleteProjectName,
labelProps: { name: project.name },
message: tracker.string.DeleteProjectConfirm
},
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
1 change: 1 addition & 0 deletions plugins/tracker-resources/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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>
}
})