fix(projects): delete project in the correct order

This commit is contained in:
kolaente 2023-06-07 20:28:36 +02:00
parent 67825425a4
commit 7755b9cd49
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 15 additions and 15 deletions

View File

@ -915,17 +915,6 @@ func (p *Project) Create(s *xorm.Session, a web.Auth) (err error) {
// @Router /projects/{id} [delete]
func (p *Project) Delete(s *xorm.Session, a web.Auth) (err error) {
fullList, err := GetProjectSimpleByID(s, p.ID)
if err != nil {
return
}
// Delete the project
_, err = s.ID(p.ID).Delete(&Project{})
if err != nil {
return
}
// Delete all tasks on that project
// Using the loop to make sure all related entities to all tasks are properly deleted as well.
tasks, _, _, err := getRawTasksForProjects(s, []*Project{p}, a, &taskOptions{})
@ -940,13 +929,24 @@ func (p *Project) Delete(s *xorm.Session, a web.Auth) (err error) {
}
}
err = fullList.DeleteBackgroundFileIfExists()
fullProject, err := GetProjectSimpleByID(s, p.ID)
if err != nil {
return
}
err = fullProject.DeleteBackgroundFileIfExists()
if err != nil {
return
}
// Delete the project
_, err = s.ID(p.ID).Delete(&Project{})
if err != nil {
return
}
return events.Dispatch(&ProjectDeletedEvent{
Project: p,
Project: fullProject,
Doer: a,
})
}

View File

@ -136,8 +136,8 @@ func DeleteUser(s *xorm.Session, u *user.User) (err error) {
return err
}
for _, l := range projectsToDelete {
err = l.Delete(s, u)
for _, p := range projectsToDelete {
err = p.Delete(s, u)
if err != nil {
return err
}