You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

issue_dependency.go 3.2KB

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
4 years ago
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
4 years ago
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
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "fmt"
  7. "net/http"
  8. "code.gitea.io/gitea/models"
  9. "code.gitea.io/gitea/modules/context"
  10. "code.gitea.io/gitea/modules/setting"
  11. )
  12. // AddDependency adds new dependencies
  13. func AddDependency(ctx *context.Context) {
  14. // Check if the Repo is allowed to have dependencies
  15. if !ctx.Repo.CanCreateIssueDependencies(ctx.User) {
  16. ctx.Error(http.StatusForbidden, "CanCreateIssueDependencies")
  17. return
  18. }
  19. depID := ctx.QueryInt64("newDependency")
  20. issueIndex := ctx.ParamsInt64("index")
  21. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, issueIndex)
  22. if err != nil {
  23. ctx.ServerError("GetIssueByIndex", err)
  24. return
  25. }
  26. // Redirect
  27. defer ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issueIndex), http.StatusSeeOther)
  28. // Dependency
  29. dep, err := models.GetIssueByID(depID)
  30. if err != nil {
  31. ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_issue_not_exist"))
  32. return
  33. }
  34. // Check if both issues are in the same repo if cross repository dependencies is not enabled
  35. if issue.RepoID != dep.RepoID && !setting.Service.AllowCrossRepositoryDependencies {
  36. ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_not_same_repo"))
  37. return
  38. }
  39. // Check if issue and dependency is the same
  40. if dep.ID == issue.ID {
  41. ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_same_issue"))
  42. return
  43. }
  44. err = models.CreateIssueDependency(ctx.User, issue, dep)
  45. if err != nil {
  46. if models.IsErrDependencyExists(err) {
  47. ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_exists"))
  48. return
  49. } else if models.IsErrCircularDependency(err) {
  50. ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_cannot_create_circular"))
  51. return
  52. } else {
  53. ctx.ServerError("CreateOrUpdateIssueDependency", err)
  54. return
  55. }
  56. }
  57. }
  58. // RemoveDependency removes the dependency
  59. func RemoveDependency(ctx *context.Context) {
  60. // Check if the Repo is allowed to have dependencies
  61. if !ctx.Repo.CanCreateIssueDependencies(ctx.User) {
  62. ctx.Error(http.StatusForbidden, "CanCreateIssueDependencies")
  63. return
  64. }
  65. depID := ctx.QueryInt64("removeDependencyID")
  66. issueIndex := ctx.ParamsInt64("index")
  67. issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, issueIndex)
  68. if err != nil {
  69. ctx.ServerError("GetIssueByIndex", err)
  70. return
  71. }
  72. // Redirect
  73. ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issueIndex), http.StatusSeeOther)
  74. // Dependency Type
  75. depTypeStr := ctx.Req.PostForm.Get("dependencyType")
  76. var depType models.DependencyType
  77. switch depTypeStr {
  78. case "blockedBy":
  79. depType = models.DependencyTypeBlockedBy
  80. case "blocking":
  81. depType = models.DependencyTypeBlocking
  82. default:
  83. ctx.Error(http.StatusBadRequest, "GetDependecyType")
  84. return
  85. }
  86. // Dependency
  87. dep, err := models.GetIssueByID(depID)
  88. if err != nil {
  89. ctx.ServerError("GetIssueByID", err)
  90. return
  91. }
  92. if err = models.RemoveIssueDependency(ctx.User, issue, dep, depType); err != nil {
  93. if models.IsErrDependencyNotExists(err) {
  94. ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_not_exist"))
  95. return
  96. }
  97. ctx.ServerError("RemoveIssueDependency", err)
  98. return
  99. }
  100. }