fix(projects): don't allow making a project child of itself
This commit is contained in:
parent
aafcb0bac4
commit
b482664d82
@ -63,6 +63,7 @@ This document describes the different errors Vikunja can return.
|
|||||||
| 3007 | 400 | A project with this identifier already exists. |
|
| 3007 | 400 | A project with this identifier already exists. |
|
||||||
| 3008 | 412 | The project is archived and can therefore only be accessed read only. This is also true for all tasks associated with this project. |
|
| 3008 | 412 | The project is archived and can therefore only be accessed read only. This is also true for all tasks associated with this project. |
|
||||||
| 3009 | 412 | The project cannot belong to a dynamically generated namespace like "Favorites". |
|
| 3009 | 412 | The project cannot belong to a dynamically generated namespace like "Favorites". |
|
||||||
|
| 3010 | 412 | This project cannot be a child of itself.|
|
||||||
|
|
||||||
## Task
|
## Task
|
||||||
|
|
||||||
|
@ -283,8 +283,35 @@ func (err *ErrProjectCannotBelongToAPseudoParentProject) HTTPError() web.HTTPErr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ErrProjectCannotBeChildOfItself represents an error where a project cannot become a child of its own
|
||||||
|
type ErrProjectCannotBeChildOfItself struct {
|
||||||
|
ProjectID int64
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsErrProjectCannotBeChildOfItsOwn checks if an error is a project is archived error.
|
||||||
|
func IsErrProjectCannotBeChildOfItsOwn(err error) bool {
|
||||||
|
_, ok := err.(*ErrProjectCannotBeChildOfItself)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func (err *ErrProjectCannotBeChildOfItself) Error() string {
|
||||||
|
return fmt.Sprintf("Project cannot be made a child of itself [ProjectID: %d]", err.ProjectID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrCodeProjectCannotBeChildOfItself holds the unique world-error code of this error
|
||||||
|
const ErrCodeProjectCannotBeChildOfItself = 3010
|
||||||
|
|
||||||
|
// HTTPError holds the http error description
|
||||||
|
func (err *ErrProjectCannotBeChildOfItself) HTTPError() web.HTTPError {
|
||||||
|
return web.HTTPError{
|
||||||
|
HTTPCode: http.StatusPreconditionFailed,
|
||||||
|
Code: ErrCodeProjectCannotBeChildOfItself,
|
||||||
|
Message: "This project cannot be a child of itself.",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ==============
|
// ==============
|
||||||
// Project errors
|
// Task errors
|
||||||
// ==============
|
// ==============
|
||||||
|
|
||||||
// ErrTaskCannotBeEmpty represents a "ErrProjectDoesNotExist" kind of error. Used if the project does not exist.
|
// ErrTaskCannotBeEmpty represents a "ErrProjectDoesNotExist" kind of error. Used if the project does not exist.
|
||||||
|
@ -641,6 +641,12 @@ func checkProjectBeforeUpdateOrDelete(s *xorm.Session, project *Project) error {
|
|||||||
|
|
||||||
// Check if the parent project exists
|
// Check if the parent project exists
|
||||||
if project.ParentProjectID > 0 {
|
if project.ParentProjectID > 0 {
|
||||||
|
if project.ParentProjectID == project.ID {
|
||||||
|
return &ErrProjectCannotBeChildOfItself{
|
||||||
|
ProjectID: project.ID,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_, err := GetProjectSimpleByID(s, project.ParentProjectID)
|
_, err := GetProjectSimpleByID(s, project.ParentProjectID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user