From d2de912c9566a5ca806da7920239b95869260e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Dachary?= Date: Sun, 26 Nov 2023 06:33:50 +0100 Subject: [PATCH] Revert "fix API usage of a PR index in place of issue index and vice versa" This reverts commit 3ddfca10acafee8d03941a46b8c59116539cf219. --- models/issues/comment.go | 6 +----- routers/api/v1/repo/issue.go | 22 ------------------- routers/api/v1/repo/issue_comment.go | 32 ---------------------------- 3 files changed, 1 insertion(+), 59 deletions(-) diff --git a/models/issues/comment.go b/models/issues/comment.go index 26b1f180ef..3feee16031 100644 --- a/models/issues/comment.go +++ b/models/issues/comment.go @@ -1014,7 +1014,6 @@ type FindCommentsOptions struct { Type CommentType IssueIDs []int64 Invalidated util.OptionalBool - IsPull util.OptionalBool } // ToConds implements FindOptions interface @@ -1049,9 +1048,6 @@ func (opts *FindCommentsOptions) ToConds() builder.Cond { if !opts.Invalidated.IsNone() { cond = cond.And(builder.Eq{"comment.invalidated": opts.Invalidated.IsTrue()}) } - if opts.IsPull != util.OptionalBoolNone { - cond = cond.And(builder.Eq{"issue.is_pull": opts.IsPull.IsTrue()}) - } return cond } @@ -1059,7 +1055,7 @@ func (opts *FindCommentsOptions) ToConds() builder.Cond { func FindComments(ctx context.Context, opts *FindCommentsOptions) (CommentList, error) { comments := make([]*Comment, 0, 10) sess := db.GetEngine(ctx).Where(opts.ToConds()) - if opts.RepoID > 0 || opts.IsPull != util.OptionalBoolNone { + if opts.RepoID > 0 { sess.Join("INNER", "issue", "issue.id = comment.issue_id") } diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index a587f8710c..3438443a2f 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -452,24 +452,6 @@ func ListIssues(ctx *context.APIContext) { isPull = util.OptionalBoolNone } - if isPull != util.OptionalBoolNone && !ctx.Repo.CanWriteIssuesOrPulls(isPull.IsTrue()) { - ctx.NotFound() - return - } - - if isPull == util.OptionalBoolNone { - canReadIssues := ctx.Repo.CanRead(unit.TypeIssues) - canReadPulls := ctx.Repo.CanRead(unit.TypePullRequests) - if !canReadIssues && !canReadPulls { - ctx.NotFound() - return - } else if !canReadIssues { - isPull = util.OptionalBoolTrue - } else if !canReadPulls { - isPull = util.OptionalBoolFalse - } - } - // FIXME: we should be more efficient here createdByID := getUserIDForFilter(ctx, "created_by") if ctx.Written() { @@ -580,10 +562,6 @@ func GetIssue(ctx *context.APIContext) { } return } - if !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull) { - ctx.NotFound() - return - } ctx.JSON(http.StatusOK, convert.ToAPIIssue(ctx, issue)) } diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go index 7f9eff04ec..2c03c7075e 100644 --- a/routers/api/v1/repo/issue_comment.go +++ b/routers/api/v1/repo/issue_comment.go @@ -12,11 +12,9 @@ import ( issues_model "code.gitea.io/gitea/models/issues" access_model "code.gitea.io/gitea/models/perm/access" repo_model "code.gitea.io/gitea/models/repo" - "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/routers/api/v1/utils" "code.gitea.io/gitea/services/convert" @@ -71,11 +69,6 @@ func ListIssueComments(ctx *context.APIContext) { ctx.Error(http.StatusInternalServerError, "GetRawIssueByIndex", err) return } - if !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull) { - ctx.NotFound() - return - } - issue.Repo = ctx.Repo.Repository opts := &issues_model.FindCommentsOptions{ @@ -272,27 +265,12 @@ func ListRepoIssueComments(ctx *context.APIContext) { return } - var isPull util.OptionalBool - canReadIssue := ctx.Repo.CanRead(unit.TypeIssues) - canReadPull := ctx.Repo.CanRead(unit.TypePullRequests) - if canReadIssue && canReadPull { - isPull = util.OptionalBoolNone - } else if canReadIssue { - isPull = util.OptionalBoolFalse - } else if canReadPull { - isPull = util.OptionalBoolTrue - } else { - ctx.NotFound() - return - } - opts := &issues_model.FindCommentsOptions{ ListOptions: utils.GetListOptions(ctx), RepoID: ctx.Repo.Repository.ID, Type: issues_model.CommentTypeComment, Since: since, Before: before, - IsPull: isPull, } comments, err := issues_model.FindComments(ctx, opts) @@ -379,11 +357,6 @@ func CreateIssueComment(ctx *context.APIContext) { return } - if !ctx.Repo.CanReadIssuesOrPulls(issue.IsPull) { - ctx.NotFound() - return - } - if issue.IsLocked && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) && !ctx.Doer.IsAdmin { ctx.Error(http.StatusForbidden, "CreateIssueComment", errors.New(ctx.Tr("repo.issues.comment_on_locked"))) return @@ -457,11 +430,6 @@ func GetIssueComment(ctx *context.APIContext) { return } - if !ctx.Repo.CanReadIssuesOrPulls(comment.Issue.IsPull) { - ctx.NotFound() - return - } - if comment.Type != issues_model.CommentTypeComment { ctx.Status(http.StatusNoContent) return