]> source.dussan.org Git - gitea.git/commitdiff
User specific repoID or xorm builder conditions for issue search (#19475) (#19476)
author6543 <6543@obermui.de>
Mon, 25 Apr 2022 13:28:47 +0000 (15:28 +0200)
committerGitHub <noreply@github.com>
Mon, 25 Apr 2022 13:28:47 +0000 (15:28 +0200)
models/issue.go
models/issue_label.go
models/issue_test.go
modules/indexer/issues/indexer.go
routers/api/v1/repo/issue.go
routers/web/repo/issue.go
routers/web/user/home.go
services/migrations/gitea_uploader_test.go

index a30e77a91b266593adb1173005913d7f3142dce7..fe2b04ce21484908dc8b7b51b76698332597c2b8 100644 (file)
@@ -1165,7 +1165,8 @@ func GetIssuesByIDs(issueIDs []int64) ([]*Issue, error) {
 // IssuesOptions represents options of an issue.
 type IssuesOptions struct {
        db.ListOptions
-       RepoIDs            []int64 // include all repos if empty
+       RepoID             int64 // overwrites RepoCond if not 0
+       RepoCond           builder.Cond
        AssigneeID         int64
        PosterID           int64
        MentionedID        int64
@@ -1256,15 +1257,15 @@ func (opts *IssuesOptions) setupSessionNoLimit(sess *xorm.Session) {
                sess.In("issue.id", opts.IssueIDs)
        }
 
-       if len(opts.RepoIDs) > 0 {
-               applyReposCondition(sess, opts.RepoIDs)
+       if opts.RepoID != 0 {
+               opts.RepoCond = builder.Eq{"issue.repo_id": opts.RepoID}
+       }
+       if opts.RepoCond != nil {
+               sess.And(opts.RepoCond)
        }
 
-       switch opts.IsClosed {
-       case util.OptionalBoolTrue:
-               sess.And("issue.is_closed=?", true)
-       case util.OptionalBoolFalse:
-               sess.And("issue.is_closed=?", false)
+       if !opts.IsClosed.IsNone() {
+               sess.And("issue.is_closed=?", opts.IsClosed.IsTrue())
        }
 
        if opts.AssigneeID > 0 {
@@ -1383,10 +1384,6 @@ func issuePullAccessibleRepoCond(repoIDstr string, userID int64, org *Organizati
        return cond
 }
 
-func applyReposCondition(sess *xorm.Session, repoIDs []int64) *xorm.Session {
-       return sess.In("issue.repo_id", repoIDs)
-}
-
 func applyAssigneeCondition(sess *xorm.Session, assigneeID int64) *xorm.Session {
        return sess.Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
                And("issue_assignees.assignee_id = ?", assigneeID)
index 53d28c05963861e873039fb58aa2f7ae0beededc..4124f3d74a1646bab9802ffeb3aaef9601f70666 100644 (file)
@@ -101,12 +101,9 @@ func (label *Label) CalOpenIssues() {
 
 // CalOpenOrgIssues calculates the open issues of a label for a specific repo
 func (label *Label) CalOpenOrgIssues(repoID, labelID int64) {
-       repoIDs := []int64{repoID}
-       labelIDs := []int64{labelID}
-
        counts, _ := CountIssuesByRepo(&IssuesOptions{
-               RepoIDs:  repoIDs,
-               LabelIDs: labelIDs,
+               RepoID:   repoID,
+               LabelIDs: []int64{labelID},
        })
 
        for _, count := range counts {
index aee9a50184ac6f55200295143800e2d601ffe4e1..2581398acf30edaaa012480e79fb676677823502 100644 (file)
@@ -17,6 +17,7 @@ import (
        user_model "code.gitea.io/gitea/models/user"
 
        "github.com/stretchr/testify/assert"
+       "xorm.io/builder"
 )
 
 func TestIssue_ReplaceLabels(t *testing.T) {
@@ -153,7 +154,7 @@ func TestIssues(t *testing.T) {
                },
                {
                        IssuesOptions{
-                               RepoIDs:  []int64{1, 3},
+                               RepoCond: builder.In("repo_id", 1, 3),
                                SortType: "oldest",
                                ListOptions: db.ListOptions{
                                        Page:     1,
@@ -340,7 +341,7 @@ func TestGetRepoIDsForIssuesOptions(t *testing.T) {
                },
                {
                        IssuesOptions{
-                               RepoIDs: []int64{1, 2},
+                               RepoCond: builder.In("repo_id", 1, 2),
                        },
                        []int64{1, 2},
                },
index 4db5091762c1e0e1eb0aa271882adf2ad343220d..6aa4d8185bf59fbd08bcd315f1ed92c6409016cb 100644 (file)
@@ -272,7 +272,7 @@ func populateIssueIndexer(ctx context.Context) {
 // UpdateRepoIndexer add/update all issues of the repositories
 func UpdateRepoIndexer(repo *repo_model.Repository) {
        is, err := models.Issues(&models.IssuesOptions{
-               RepoIDs:  []int64{repo.ID},
+               RepoID:   repo.ID,
                IsClosed: util.OptionalBoolNone,
                IsPull:   util.OptionalBoolNone,
        })
index c6e08b00f38cdb0e06354007858b72f4f5631a69..b5b1659c9332482196f21b4ef028f648554da141 100644 (file)
@@ -173,6 +173,7 @@ func SearchIssues(ctx *context.APIContext) {
                opts.TeamID = team.ID
        }
 
+       repoCond := models.SearchRepositoryCondition(opts)
        repoIDs, _, err := models.SearchRepositoryIDs(opts)
        if err != nil {
                ctx.Error(http.StatusInternalServerError, "SearchRepositoryByName", err)
@@ -233,7 +234,7 @@ func SearchIssues(ctx *context.APIContext) {
                                Page:     ctx.FormInt("page"),
                                PageSize: limit,
                        },
-                       RepoIDs:            repoIDs,
+                       RepoCond:           repoCond,
                        IsClosed:           isClosed,
                        IssueIDs:           issueIDs,
                        IncludedLabelNames: includedLabelNames,
@@ -460,7 +461,7 @@ func ListIssues(ctx *context.APIContext) {
        if len(keyword) == 0 || len(issueIDs) > 0 || len(labelIDs) > 0 {
                issuesOpt := &models.IssuesOptions{
                        ListOptions:       listOptions,
-                       RepoIDs:           []int64{ctx.Repo.Repository.ID},
+                       RepoID:            ctx.Repo.Repository.ID,
                        IsClosed:          isClosed,
                        IssueIDs:          issueIDs,
                        LabelIDs:          labelIDs,
index bb24d0462cd7cd67c26cfe6213ef987fc40e67eb..248743471b2a5cf4e17ace8ec7156a436f6bd064 100644 (file)
@@ -226,7 +226,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
                                Page:     pager.Paginater.Current(),
                                PageSize: setting.UI.IssuePagingNum,
                        },
-                       RepoIDs:           []int64{repo.ID},
+                       RepoID:            repo.ID,
                        AssigneeID:        assigneeID,
                        PosterID:          posterID,
                        MentionedID:       mentionedID,
index 6f1234d09681e6766e4e591fef003fc4afa6a366..b2d9a9ca5005000f6a1596160a3a3fcd1b6458d0 100644 (file)
@@ -462,13 +462,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
                        // to check if it's in the team(which possible isn't the case).
                        opts.User = nil
                }
-               userRepoIDs, _, err := models.SearchRepositoryIDs(repoOpts)
-               if err != nil {
-                       ctx.ServerError("models.SearchRepositoryIDs: %v", err)
-                       return
-               }
-
-               opts.RepoIDs = userRepoIDs
+               opts.RepoCond = models.SearchRepositoryCondition(repoOpts)
        }
 
        // keyword holds the search term entered into the search field.
@@ -532,7 +526,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
        // Gets set when clicking filters on the issues overview page.
        repoIDs := getRepoIDs(ctx.FormString("repos"))
        if len(repoIDs) > 0 {
-               opts.RepoIDs = repoIDs
+               opts.RepoCond = builder.In("issue.repo_id", repoIDs)
        }
 
        // ------------------------------
index 7d4f77eac87342f718630c04030d7e55bddfbcda..ed3e32952c176f9c641098c95d1e90cb643427be 100644 (file)
@@ -97,7 +97,7 @@ func TestGiteaUploadRepo(t *testing.T) {
        assert.Len(t, releases, 1)
 
        issues, err := models.Issues(&models.IssuesOptions{
-               RepoIDs:  []int64{repo.ID},
+               RepoID:   repo.ID,
                IsPull:   util.OptionalBoolFalse,
                SortType: "oldest",
        })