diff --git a/pkg/models/project.go b/pkg/models/project.go index 035a2c73b33..509b7f567ec 100644 --- a/pkg/models/project.go +++ b/pkg/models/project.go @@ -1041,10 +1041,28 @@ func (p *Project) Delete(s *xorm.Session, a web.Auth) (err error) { return } - return events.Dispatch(&ProjectDeletedEvent{ + err = events.Dispatch(&ProjectDeletedEvent{ Project: fullProject, Doer: a, }) + if err != nil { + return + } + + childProjects := []*Project{} + err = s.Where("parent_project_id = ?", fullProject.ID).Find(&childProjects) + if err != nil { + return + } + + for _, child := range childProjects { + err = child.Delete(s, a) + if err != nil { + return + } + } + + return } // DeleteBackgroundFileIfExists deletes the list's background file from the db and the filesystem, diff --git a/pkg/models/user_delete.go b/pkg/models/user_delete.go index 8548daff545..ab6ef7cc6fe 100644 --- a/pkg/models/user_delete.go +++ b/pkg/models/user_delete.go @@ -137,6 +137,10 @@ func DeleteUser(s *xorm.Session, u *user.User) (err error) { } for _, p := range projectsToDelete { + if p.ParentProjectID != 0 { + // Child projects are deleted by p.Delete + continue + } err = p.Delete(s, u) // If the user is the owner of the default project it will be deleted, if they are not the owner // we can ignore the error as the project was shared in that case.