mirror of
https://github.com/go-gitea/gitea
synced 2024-12-23 19:54:28 +01:00
beb71f5ef6
It will fix #28268 .
<img width="1313" alt="image"
src="https://github.com/go-gitea/gitea/assets/9418365/cb1e07d5-7a12-4691-a054-8278ba255bfc">
<img width="1318" alt="image"
src="https://github.com/go-gitea/gitea/assets/9418365/4fd60820-97f1-4c2c-a233-d3671a5039e9">
## ⚠️ BREAKING ⚠️
But need to give up some features:
<img width="1312" alt="image"
src="https://github.com/go-gitea/gitea/assets/9418365/281c0d51-0e7d-473f-bbed-216e2f645610">
However, such abandonment may fix #28055 .
## Backgroud
When the user switches the dashboard context to an org, it means they
want to search issues in the repos that belong to the org. However, when
they switch to themselves, it means all repos they can access because
they may have created an issue in a public repo that they don't own.
<img width="286" alt="image"
src="https://github.com/go-gitea/gitea/assets/9418365/182dcd5b-1c20-4725-93af-96e8dfae5b97">
It's a confusing design. Think about this: What does "In your
repositories" mean when the user switches to an org? Repos belong to the
user or the org?
Whatever, it has been broken by #26012 and its following PRs. After the
PR, it searches for issues in repos that the dashboard context user owns
or has been explicitly granted access to, so it causes #28268.
## How to fix it
It's not really difficult to fix it. Just extend the repo scope to
search issues when the dashboard context user is the doer. Since the
user may create issues or be mentioned in any public repo, we can just
set `AllPublic` to true, which is already supported by indexers. The DB
condition will also support it in this PR.
But the real difficulty is how to count the search results grouped by
repos. It's something like "search issues with this keyword and those
filters, and return the total number and the top results. **Then, group
all of them by repo and return the counts of each group.**"
<img width="314" alt="image"
src="https://github.com/go-gitea/gitea/assets/9418365/5206eb20-f8f5-49b9-b45a-1be2fcf679f4">
Before #26012, it was being done in the DB, but it caused the results to
be incomplete (see the description of #26012).
And to keep this, #26012 implement it in an inefficient way, just count
the issues by repo one by one, so it cannot work when `AllPublic` is
true because it's almost impossible to do this for all public repos.
1bfcdeef4c/modules/indexer/issues/indexer.go (L318-L338)
## Give up unnecessary features
We may can resovle `TODO: use "group by" of the indexer engines to
implement it`, I'm sure it can be done with Elasticsearch, but IIRC,
Bleve and Meilisearch don't support "group by".
And the real question is, does it worth it? Why should we need to know
the counts grouped by repos?
Let me show you my search dashboard on gitea.com.
<img width="1304" alt="image"
src="https://github.com/go-gitea/gitea/assets/9418365/2bca2d46-6c71-4de1-94cb-0c9af27c62ff">
I never think the long repo list helps anything.
And if we agree to abandon it, things will be much easier. That is this
PR.
## TODO
I know it's important to filter by repos when searching issues. However,
it shouldn't be the way we have it now. It could be implemented like
this.
<img width="1316" alt="image"
src="https://github.com/go-gitea/gitea/assets/9418365/99ee5f21-cbb5-4dfe-914d-cb796cb79fbe">
The indexers support it well now, but it requires some frontend work,
which I'm not good at. So, I think someone could help do that in another
PR and merge this one to fix the bug first.
Or please block this PR and help to complete it.
Finally, "Switch dashboard context" is also a design that needs
improvement. In my opinion, it can be accomplished by adding filtering
conditions instead of "switching".
115 lines
3.6 KiB
Go
115 lines
3.6 KiB
Go
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package user
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
|
"code.gitea.io/gitea/models/unittest"
|
|
"code.gitea.io/gitea/modules/contexttest"
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestArchivedIssues(t *testing.T) {
|
|
// Arrange
|
|
setting.UI.IssuePagingNum = 1
|
|
assert.NoError(t, unittest.LoadFixtures())
|
|
|
|
ctx, _ := contexttest.MockContext(t, "issues")
|
|
contexttest.LoadUser(t, ctx, 30)
|
|
ctx.Req.Form.Set("state", "open")
|
|
|
|
// Assume: User 30 has access to two Repos with Issues, one of the Repos being archived.
|
|
repos, _, _ := repo_model.GetUserRepositories(db.DefaultContext, &repo_model.SearchRepoOptions{Actor: ctx.Doer})
|
|
assert.Len(t, repos, 3)
|
|
IsArchived := make(map[int64]bool)
|
|
NumIssues := make(map[int64]int)
|
|
for _, repo := range repos {
|
|
IsArchived[repo.ID] = repo.IsArchived
|
|
NumIssues[repo.ID] = repo.NumIssues
|
|
}
|
|
assert.False(t, IsArchived[50])
|
|
assert.EqualValues(t, 1, NumIssues[50])
|
|
assert.True(t, IsArchived[51])
|
|
assert.EqualValues(t, 1, NumIssues[51])
|
|
|
|
// Act
|
|
Issues(ctx)
|
|
|
|
// Assert: One Issue (ID 30) from one Repo (ID 50) is retrieved, while nothing from archived Repo 51 is retrieved
|
|
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
|
|
|
assert.Len(t, ctx.Data["Issues"], 1)
|
|
}
|
|
|
|
func TestIssues(t *testing.T) {
|
|
setting.UI.IssuePagingNum = 1
|
|
assert.NoError(t, unittest.LoadFixtures())
|
|
|
|
ctx, _ := contexttest.MockContext(t, "issues")
|
|
contexttest.LoadUser(t, ctx, 2)
|
|
ctx.Req.Form.Set("state", "closed")
|
|
Issues(ctx)
|
|
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
|
|
|
assert.EqualValues(t, true, ctx.Data["IsShowClosed"])
|
|
assert.Len(t, ctx.Data["Issues"], 1)
|
|
}
|
|
|
|
func TestPulls(t *testing.T) {
|
|
setting.UI.IssuePagingNum = 20
|
|
assert.NoError(t, unittest.LoadFixtures())
|
|
|
|
ctx, _ := contexttest.MockContext(t, "pulls")
|
|
contexttest.LoadUser(t, ctx, 2)
|
|
ctx.Req.Form.Set("state", "open")
|
|
Pulls(ctx)
|
|
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
|
|
|
assert.Len(t, ctx.Data["Issues"], 5)
|
|
}
|
|
|
|
func TestMilestones(t *testing.T) {
|
|
setting.UI.IssuePagingNum = 1
|
|
assert.NoError(t, unittest.LoadFixtures())
|
|
|
|
ctx, _ := contexttest.MockContext(t, "milestones")
|
|
contexttest.LoadUser(t, ctx, 2)
|
|
ctx.SetParams("sort", "issues")
|
|
ctx.Req.Form.Set("state", "closed")
|
|
ctx.Req.Form.Set("sort", "furthestduedate")
|
|
Milestones(ctx)
|
|
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
|
assert.EqualValues(t, map[int64]int64{1: 1}, ctx.Data["Counts"])
|
|
assert.EqualValues(t, true, ctx.Data["IsShowClosed"])
|
|
assert.EqualValues(t, "furthestduedate", ctx.Data["SortType"])
|
|
assert.EqualValues(t, 1, ctx.Data["Total"])
|
|
assert.Len(t, ctx.Data["Milestones"], 1)
|
|
assert.Len(t, ctx.Data["Repos"], 2) // both repo 42 and 1 have milestones and both are owned by user 2
|
|
}
|
|
|
|
func TestMilestonesForSpecificRepo(t *testing.T) {
|
|
setting.UI.IssuePagingNum = 1
|
|
assert.NoError(t, unittest.LoadFixtures())
|
|
|
|
ctx, _ := contexttest.MockContext(t, "milestones")
|
|
contexttest.LoadUser(t, ctx, 2)
|
|
ctx.SetParams("sort", "issues")
|
|
ctx.SetParams("repo", "1")
|
|
ctx.Req.Form.Set("state", "closed")
|
|
ctx.Req.Form.Set("sort", "furthestduedate")
|
|
Milestones(ctx)
|
|
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
|
assert.EqualValues(t, map[int64]int64{1: 1}, ctx.Data["Counts"])
|
|
assert.EqualValues(t, true, ctx.Data["IsShowClosed"])
|
|
assert.EqualValues(t, "furthestduedate", ctx.Data["SortType"])
|
|
assert.EqualValues(t, 1, ctx.Data["Total"])
|
|
assert.Len(t, ctx.Data["Milestones"], 1)
|
|
assert.Len(t, ctx.Data["Repos"], 2) // both repo 42 and 1 have milestones and both are owned by user 2
|
|
}
|