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 1 commit
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
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?",
"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
28 changes: 22 additions & 6 deletions plugins/tracker-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,20 @@ async function deleteProject (project: Project | undefined): Promise<void> {
}
)
} 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)
}
}
)
}
}
}
Expand Down Expand Up @@ -260,22 +273,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
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