From 4ecb25a5495e9ae03ac3bc3c164faa9afaae3c0e Mon Sep 17 00:00:00 2001 From: Shiny Nematoda Date: Sun, 17 May 2026 12:00:25 +0200 Subject: [PATCH] enh(issue-search): support filtering by project in user/org listing (#12596) Support filtering `/issue` & `/pulls` (and corresponding org paths) by a project ID. Closes #12559 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12596 Reviewed-by: Gusted --- models/fixtures/project.yml | 2 +- models/fixtures/project_board.yml | 10 +++++++ models/fixtures/project_issue.yml | 21 +++++++++++++++ routers/web/user/home.go | 33 +++++++++++++++++++++++ templates/user/dashboard/issues.tmpl | 39 +++++++++++++++++++++------- tests/integration/issue_test.go | 34 ++++++++++++++++++++++++ 6 files changed, 129 insertions(+), 10 deletions(-) diff --git a/models/fixtures/project.yml b/models/fixtures/project.yml index 54a3061859..c1011dc5e3 100644 --- a/models/fixtures/project.yml +++ b/models/fixtures/project.yml @@ -78,6 +78,6 @@ is_closed: false creator_id: 2 board_type: 1 - type: 1 + type: 3 created_unix: 1688973000 updated_unix: 1688973000 diff --git a/models/fixtures/project_board.yml b/models/fixtures/project_board.yml index e205c01a21..30708afb55 100644 --- a/models/fixtures/project_board.yml +++ b/models/fixtures/project_board.yml @@ -84,3 +84,13 @@ sorting: 1 created_unix: 1588117528 updated_unix: 1588117528 + +- + id: 10 + project_id: 7 + title: Default + creator_id: 2 + default: true + sorting: 1 + created_unix: 1588117528 + updated_unix: 1588117528 diff --git a/models/fixtures/project_issue.yml b/models/fixtures/project_issue.yml index 61ad79cd3e..606ec56008 100644 --- a/models/fixtures/project_issue.yml +++ b/models/fixtures/project_issue.yml @@ -25,3 +25,24 @@ project_id: 1 project_board_id: 3 sorting: 0 + +- + id: 5 + issue_id: 16 + project_id: 4 + project_board_id: 4 + sorting: 0 + +- + id: 6 + issue_id: 15 + project_id: 7 + project_board_id: 10 + sorting: 0 + +- + id: 7 + issue_id: 17 + project_id: 7 + project_board_id: 10 + sorting: 1 diff --git a/routers/web/user/home.go b/routers/web/user/home.go index 4fe3f7c9a0..d4acdaa7ac 100644 --- a/routers/web/user/home.go +++ b/routers/web/user/home.go @@ -18,6 +18,7 @@ import ( "forgejo.org/models/db" issues_model "forgejo.org/models/issues" "forgejo.org/models/organization" + project_model "forgejo.org/models/project" repo_model "forgejo.org/models/repo" "forgejo.org/models/unit" user_model "forgejo.org/models/user" @@ -538,6 +539,37 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { PageSize: setting.UI.IssuePagingNum, } + // Projects + // + // We do not consider listing projects for the individual repos. + // Instead, we only support listing the projects under the scope of an individual/organisation. + // However, this limitation does not affect filtering with a project ID. + { + projOpts := project_model.SearchOptions{ + ListOptions: db.ListOptionsAll, + OwnerID: ctxUser.ID, + IsClosed: optional.None[bool](), + Type: project_model.TypeIndividual, + } + if org != nil { + projOpts.OwnerID = org.ID + projOpts.Type = project_model.TypeOrganization + } + + projects, err := db.Find[project_model.Project](ctx, projOpts) + if err != nil { + ctx.ServerError("GetProjects", err) + return + } + + if projectID := ctx.FormInt64("project"); projectID != 0 { + opts.ProjectID = projectID + ctx.Data["ProjectID"] = projectID + } + + ctx.Data["Projects"] = projects + } + // Get IDs for labels (a filter option for issues/pulls). // Required for IssuesOptions. selectedLabels := ctx.FormString("labels") @@ -688,6 +720,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { pager.AddParam(ctx, "labels", "SelectLabels") pager.AddParam(ctx, "milestone", "MilestoneID") pager.AddParam(ctx, "assignee", "AssigneeID") + pager.AddParam(ctx, "project", "ProjectID") ctx.Data["Page"] = pager ctx.HTML(http.StatusOK, tplIssues) diff --git a/templates/user/dashboard/issues.tmpl b/templates/user/dashboard/issues.tmpl index 5ebeac9d14..8bffbcde1d 100644 --- a/templates/user/dashboard/issues.tmpl +++ b/templates/user/dashboard/issues.tmpl @@ -6,11 +6,11 @@
{{$keyword := StringUtils.RemoveAll $.Keyword "is:open" "-is:open" "is:closed" "-is:closed" "is:all"}} - + {{svg "octicon-issue-opened" 16}} {{ctx.Locale.PrettyNumber .IssueStats.OpenCount}} {{ctx.Locale.Tr "repo.issues.open_title"}} - + {{svg "octicon-issue-closed" 16}} {{ctx.Locale.PrettyNumber .IssueStats.ClosedCount}} {{ctx.Locale.Tr "repo.issues.closed_title"}} @@ -19,6 +19,7 @@