1
0

fix(user): allow deleting a user if they have a default project

Resolves https://github.com/go-vikunja/api/issues/78
This commit is contained in:
kolaente
2023-08-23 16:10:51 +02:00
parent 40037f25f2
commit acb03c430e
5 changed files with 44 additions and 3 deletions

View File

@ -960,7 +960,8 @@ func (p *Project) Delete(s *xorm.Session, a web.Auth) (err error) {
if err != nil {
return err
}
if isDefaultProject {
// Owners should be allowed to delete the default project
if isDefaultProject && p.OwnerID != a.GetID() {
return &ErrCannotDeleteDefaultProject{ProjectID: p.ID}
}
@ -988,6 +989,16 @@ func (p *Project) Delete(s *xorm.Session, a web.Auth) (err error) {
return
}
// If we're deleting a default project, remove it as default
if isDefaultProject {
_, err = s.Where("default_project_id = ?", p.ID).
Cols("default_project_id").
Update(&user.User{DefaultProjectID: 0})
if err != nil {
return
}
}
// Delete the project
_, err = s.ID(p.ID).Delete(&Project{})
if err != nil {