Added method to prevent making an issue dependent on itself

Signed-off-by: Konrad <konrad@kola-entertainments.de>
This commit is contained in:
Konrad Langenberg 2017-08-29 17:16:54 +02:00 committed by Jonas Franz
parent 6859c47397
commit 39f7f92b84
2 changed files with 16 additions and 11 deletions

View File

@ -44,7 +44,6 @@ func (iw *IssueDependency) BeforeUpdate() {
} }
// CreateIssueDependency creates a new dependency for an issue // CreateIssueDependency creates a new dependency for an issue
// TODO: prevent issues having itself as dependency
func CreateIssueDependency(userID, issueID int64, depID int64) (err error, exists bool, depExists bool) { func CreateIssueDependency(userID, issueID int64, depID int64) (err error, exists bool, depExists bool) {
err = x.Sync(new(IssueDependency)) err = x.Sync(new(IssueDependency))
if err != nil { if err != nil {

View File

@ -28,18 +28,24 @@ func AddDependency(c *context.Context) {
return return
} }
err, exists, depExists := models.CreateIssueDependency(c.User.ID, issue.ID, dep); // Check if issue and dependency is the same
if err != nil { if dep == issueIndex{
c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueDependency", err) c.Flash.Error("You cannot make an issue depend on itself!")
return } else {
}
if !depExists { err, exists, depExists := models.CreateIssueDependency(c.User.ID, issue.ID, dep);
c.Flash.Error("Dependend issue does not exist!") if err != nil {
} c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueDependency", err)
return
}
if exists { if !depExists {
c.Flash.Error("Dependency already exists!") c.Flash.Error("Dependend issue does not exist!")
}
if exists {
c.Flash.Error("Dependency already exists!")
}
} }
url := fmt.Sprintf("%s/issues/%d", c.Repo.RepoLink, issueIndex) url := fmt.Sprintf("%s/issues/%d", c.Repo.RepoLink, issueIndex)