2018-07-17 17:23:58 -04:00
|
|
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
"code.gitea.io/gitea/modules/context"
|
Allow cross-repository dependencies on issues (#7901)
* in progress changes for #7405, added ability to add cross-repo dependencies
* removed unused repolink var
* fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes
* reverted removal of string in local files becasue these are done via crowdin, not updated manually
* removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review
* changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result
* simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository
* made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line)
* replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard
* some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies
* added Name to the RepositoryMeta struct
* updated swagger doc
* fixed total count for link header on SearchIssues
* fixed indentation
* fixed aligment of remove icon on dependencies in issue sidebar
* removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block)
* reverting .css change, somehow missed or forgot that less is used
* updated less file and generated css; updated sidebar template with styles to line up delete and issue index
* added ordering to the blocked by/depends on queries
* fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository)
* re-applied my swagger changes after merge
* fixed split string condition in issue search
* changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter
* when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled
* updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here
* fixed incorrect setting of user id parameter in search repos call
2019-10-31 01:06:10 -04:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2018-07-17 17:23:58 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// AddDependency adds new dependencies
|
|
|
|
func AddDependency(ctx *context.Context) {
|
|
|
|
issueIndex := ctx.ParamsInt64("index")
|
|
|
|
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, issueIndex)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("GetIssueByIndex", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-19 01:43:38 -05:00
|
|
|
// Check if the Repo is allowed to have dependencies
|
2022-03-22 03:03:22 -04:00
|
|
|
if !ctx.Repo.CanCreateIssueDependencies(ctx.Doer, issue.IsPull) {
|
2020-01-19 01:43:38 -05:00
|
|
|
ctx.Error(http.StatusForbidden, "CanCreateIssueDependencies")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-28 21:42:15 -04:00
|
|
|
depID := ctx.FormInt64("newDependency")
|
2020-01-19 01:43:38 -05:00
|
|
|
|
2022-04-08 05:11:15 -04:00
|
|
|
if err = issue.LoadRepo(ctx); err != nil {
|
2019-12-24 18:46:16 -05:00
|
|
|
ctx.ServerError("LoadRepo", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-17 17:23:58 -04:00
|
|
|
// Redirect
|
2022-03-23 00:54:07 -04:00
|
|
|
defer ctx.Redirect(issue.HTMLURL())
|
2018-07-17 17:23:58 -04:00
|
|
|
|
|
|
|
// Dependency
|
|
|
|
dep, err := models.GetIssueByID(depID)
|
|
|
|
if err != nil {
|
|
|
|
ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_issue_not_exist"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
Allow cross-repository dependencies on issues (#7901)
* in progress changes for #7405, added ability to add cross-repo dependencies
* removed unused repolink var
* fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes
* reverted removal of string in local files becasue these are done via crowdin, not updated manually
* removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review
* changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result
* simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository
* made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line)
* replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard
* some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies
* added Name to the RepositoryMeta struct
* updated swagger doc
* fixed total count for link header on SearchIssues
* fixed indentation
* fixed aligment of remove icon on dependencies in issue sidebar
* removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block)
* reverting .css change, somehow missed or forgot that less is used
* updated less file and generated css; updated sidebar template with styles to line up delete and issue index
* added ordering to the blocked by/depends on queries
* fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository)
* re-applied my swagger changes after merge
* fixed split string condition in issue search
* changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter
* when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled
* updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here
* fixed incorrect setting of user id parameter in search repos call
2019-10-31 01:06:10 -04:00
|
|
|
// Check if both issues are in the same repo if cross repository dependencies is not enabled
|
|
|
|
if issue.RepoID != dep.RepoID && !setting.Service.AllowCrossRepositoryDependencies {
|
2018-07-17 17:23:58 -04:00
|
|
|
ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_not_same_repo"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if issue and dependency is the same
|
Allow cross-repository dependencies on issues (#7901)
* in progress changes for #7405, added ability to add cross-repo dependencies
* removed unused repolink var
* fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes
* reverted removal of string in local files becasue these are done via crowdin, not updated manually
* removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review
* changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result
* simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository
* made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line)
* replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard
* some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies
* added Name to the RepositoryMeta struct
* updated swagger doc
* fixed total count for link header on SearchIssues
* fixed indentation
* fixed aligment of remove icon on dependencies in issue sidebar
* removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block)
* reverting .css change, somehow missed or forgot that less is used
* updated less file and generated css; updated sidebar template with styles to line up delete and issue index
* added ordering to the blocked by/depends on queries
* fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository)
* re-applied my swagger changes after merge
* fixed split string condition in issue search
* changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter
* when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled
* updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here
* fixed incorrect setting of user id parameter in search repos call
2019-10-31 01:06:10 -04:00
|
|
|
if dep.ID == issue.ID {
|
2018-07-17 17:23:58 -04:00
|
|
|
ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_same_issue"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-22 03:03:22 -04:00
|
|
|
err = models.CreateIssueDependency(ctx.Doer, issue, dep)
|
2018-07-17 17:23:58 -04:00
|
|
|
if err != nil {
|
|
|
|
if models.IsErrDependencyExists(err) {
|
|
|
|
ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_exists"))
|
|
|
|
return
|
|
|
|
} else if models.IsErrCircularDependency(err) {
|
|
|
|
ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_cannot_create_circular"))
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
ctx.ServerError("CreateOrUpdateIssueDependency", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveDependency removes the dependency
|
|
|
|
func RemoveDependency(ctx *context.Context) {
|
|
|
|
issueIndex := ctx.ParamsInt64("index")
|
|
|
|
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, issueIndex)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("GetIssueByIndex", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-01-19 01:43:38 -05:00
|
|
|
// Check if the Repo is allowed to have dependencies
|
2022-03-22 03:03:22 -04:00
|
|
|
if !ctx.Repo.CanCreateIssueDependencies(ctx.Doer, issue.IsPull) {
|
2020-01-19 01:43:38 -05:00
|
|
|
ctx.Error(http.StatusForbidden, "CanCreateIssueDependencies")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-28 21:42:15 -04:00
|
|
|
depID := ctx.FormInt64("removeDependencyID")
|
2020-01-19 01:43:38 -05:00
|
|
|
|
2022-04-08 05:11:15 -04:00
|
|
|
if err = issue.LoadRepo(ctx); err != nil {
|
2019-12-24 18:46:16 -05:00
|
|
|
ctx.ServerError("LoadRepo", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-17 17:23:58 -04:00
|
|
|
// Dependency Type
|
|
|
|
depTypeStr := ctx.Req.PostForm.Get("dependencyType")
|
|
|
|
|
|
|
|
var depType models.DependencyType
|
|
|
|
|
|
|
|
switch depTypeStr {
|
|
|
|
case "blockedBy":
|
|
|
|
depType = models.DependencyTypeBlockedBy
|
|
|
|
case "blocking":
|
|
|
|
depType = models.DependencyTypeBlocking
|
|
|
|
default:
|
|
|
|
ctx.Error(http.StatusBadRequest, "GetDependecyType")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dependency
|
|
|
|
dep, err := models.GetIssueByID(depID)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("GetIssueByID", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-22 03:03:22 -04:00
|
|
|
if err = models.RemoveIssueDependency(ctx.Doer, issue, dep, depType); err != nil {
|
2018-07-17 17:23:58 -04:00
|
|
|
if models.IsErrDependencyNotExists(err) {
|
|
|
|
ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_not_exist"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.ServerError("RemoveIssueDependency", err)
|
|
|
|
return
|
|
|
|
}
|
2020-01-20 07:00:32 -05:00
|
|
|
|
|
|
|
// Redirect
|
2022-03-23 00:54:07 -04:00
|
|
|
ctx.Redirect(issue.HTMLURL())
|
2018-07-17 17:23:58 -04:00
|
|
|
}
|