diff --git a/routers/web/repo/issue_dependency.go b/routers/web/repo/issue_dependency.go index 7570147fc4..1223f1868c 100644 --- a/routers/web/repo/issue_dependency.go +++ b/routers/web/repo/issue_dependency.go @@ -4,8 +4,6 @@ package repo import ( - "net/http" - issues_model "gitea.dev/models/issues" access_model "gitea.dev/models/perm/access" "gitea.dev/modules/setting" @@ -23,7 +21,7 @@ func AddDependency(ctx *context.Context) { // Check if the Repo is allowed to have dependencies if !ctx.Repo.CanCreateIssueDependencies(ctx, ctx.Doer, issue.IsPull) { - ctx.HTTPError(http.StatusForbidden, "CanCreateIssueDependencies") + ctx.JSONError(ctx.Locale.TrString("error.permission_denied")) return } @@ -34,20 +32,17 @@ func AddDependency(ctx *context.Context) { return } - // Redirect - defer ctx.Redirect(issue.Link()) - // Dependency dep, err := issues_model.GetIssueByID(ctx, depID) if err != nil { - ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_issue_not_exist")) + ctx.JSONError(ctx.Tr("repo.issues.dependency.add_error_dep_issue_not_exist")) return } // Check if both issues are in the same repo if cross repository dependencies is not enabled if issue.RepoID != dep.RepoID { if !setting.Service.AllowCrossRepositoryDependencies { - ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_not_same_repo")) + ctx.JSONError(ctx.Tr("repo.issues.dependency.add_error_dep_not_same_repo")) return } if err := dep.LoadRepo(ctx); err != nil { @@ -61,29 +56,29 @@ func AddDependency(ctx *context.Context) { return } if !depRepoPerm.CanReadIssuesOrPulls(dep.IsPull) { - // you can't see this dependency + ctx.JSONError(ctx.Locale.TrString("error.permission_denied")) return } } // Check if issue and dependency is the same if dep.ID == issue.ID { - ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_same_issue")) + ctx.JSONError(ctx.Tr("repo.issues.dependency.add_error_same_issue")) return } err = issues_model.CreateIssueDependency(ctx, ctx.Doer, issue, dep) - if err != nil { - if issues_model.IsErrDependencyExists(err) { - ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_exists")) - return - } else if issues_model.IsErrCircularDependency(err) { - ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_cannot_create_circular")) - return - } + if issues_model.IsErrDependencyExists(err) { + ctx.JSONError(ctx.Tr("repo.issues.dependency.add_error_dep_exists")) + return + } else if issues_model.IsErrCircularDependency(err) { + ctx.JSONError(ctx.Tr("repo.issues.dependency.add_error_cannot_create_circular")) + return + } else if err != nil { ctx.ServerError("CreateOrUpdateIssueDependency", err) return } + ctx.JSONOK() } // RemoveDependency removes the dependency @@ -97,7 +92,7 @@ func RemoveDependency(ctx *context.Context) { // Check if the Repo is allowed to have dependencies if !ctx.Repo.CanCreateIssueDependencies(ctx, ctx.Doer, issue.IsPull) { - ctx.HTTPError(http.StatusForbidden, "CanCreateIssueDependencies") + ctx.JSONError(ctx.Locale.TrString("error.permission_denied")) return } @@ -119,7 +114,7 @@ func RemoveDependency(ctx *context.Context) { case "blocking": depType = issues_model.DependencyTypeBlocking default: - ctx.HTTPError(http.StatusBadRequest, "GetDependencyType") + ctx.JSONError("invalid dependency type") return } @@ -144,20 +139,18 @@ func RemoveDependency(ctx *context.Context) { return } if !depRepoPerm.CanReadIssuesOrPulls(dep.IsPull) { - ctx.Redirect(issue.Link()) + ctx.JSONError(ctx.Locale.TrString("error.permission_denied")) return } } - if err = issues_model.RemoveIssueDependency(ctx, ctx.Doer, issue, dep, depType); err != nil { - if issues_model.IsErrDependencyNotExists(err) { - ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_not_exist")) - return - } + err = issues_model.RemoveIssueDependency(ctx, ctx.Doer, issue, dep, depType) + if issues_model.IsErrDependencyNotExists(err) { + ctx.JSONError(ctx.Tr("repo.issues.dependency.add_error_dep_not_exist")) + return + } else if err != nil { ctx.ServerError("RemoveIssueDependency", err) return } - - // Redirect - ctx.Redirect(issue.Link()) + ctx.JSONOK() } diff --git a/templates/repo/issue/sidebar/issue_dependencies.tmpl b/templates/repo/issue/sidebar/issue_dependencies.tmpl index f1555dfa39..58dd61fb69 100644 --- a/templates/repo/issue/sidebar/issue_dependencies.tmpl +++ b/templates/repo/issue/sidebar/issue_dependencies.tmpl @@ -18,10 +18,10 @@ {{ctx.Locale.Tr "repo.issues.dependency.blocks_short"}} -