mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-02-22 19:35:47 -05:00
[v10.0/forgejo] fix: make author search case insenstive (#6783)
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/6782 - Make the author search in the issues and pull request list case insenstive. - Background: Forgejo mandates that all columns are case senstive and only SQLite ignores this for ASCII characters with the `LIKE` operator any other database will indeed do case senstive searching. Codeberg recently made all columns case senstive, hence why this issue now surfaces. - Added integration test. - Resolves forgejo/forgejo#6744 Co-authored-by: Gusted <postmaster@gusted.xyz> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6783 Reviewed-by: Beowulf <beowulf@beocode.eu> Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org> Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
This commit is contained in:
parent
b615d41457
commit
ac01c7a384
2 changed files with 45 additions and 2 deletions
|
@ -166,9 +166,9 @@ func GetReviewers(ctx context.Context, repo *Repository, doerID, posterID int64)
|
|||
// If isShowFullName is set to true, also include full name prefix search
|
||||
func GetIssuePostersWithSearch(ctx context.Context, repo *Repository, isPull bool, search string, isShowFullName bool) ([]*user_model.User, error) {
|
||||
users := make([]*user_model.User, 0, 30)
|
||||
var prefixCond builder.Cond = builder.Like{"name", search + "%"}
|
||||
prefixCond := db.BuildCaseInsensitiveLike("name", search+"%")
|
||||
if isShowFullName {
|
||||
prefixCond = prefixCond.Or(builder.Like{"full_name", "%" + search + "%"})
|
||||
prefixCond = db.BuildCaseInsensitiveLike("full_name", "%"+search+"%")
|
||||
}
|
||||
|
||||
cond := builder.In("`user`.id",
|
||||
|
|
|
@ -1336,3 +1336,46 @@ func TestIssueCount(t *testing.T) {
|
|||
allCount := htmlDoc.doc.Find("a[data-test-name='all-issue-count']").Text()
|
||||
assert.Contains(t, allCount, "2\u00a0All")
|
||||
}
|
||||
|
||||
func TestIssuePostersSearch(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
type userSearchInfo struct {
|
||||
UserID int64 `json:"user_id"`
|
||||
UserName string `json:"username"`
|
||||
}
|
||||
|
||||
type userSearchResponse struct {
|
||||
Results []*userSearchInfo `json:"results"`
|
||||
}
|
||||
|
||||
t.Run("Name search", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
defer test.MockVariableValue(&setting.UI.DefaultShowFullName, false)()
|
||||
|
||||
req := NewRequest(t, "GET", "/user2/repo1/issues/posters?q=USer2")
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
var data userSearchResponse
|
||||
DecodeJSON(t, resp, &data)
|
||||
|
||||
assert.Len(t, data.Results, 1)
|
||||
assert.EqualValues(t, "user2", data.Results[0].UserName)
|
||||
assert.EqualValues(t, 2, data.Results[0].UserID)
|
||||
})
|
||||
|
||||
t.Run("Full name search", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
defer test.MockVariableValue(&setting.UI.DefaultShowFullName, true)()
|
||||
|
||||
req := NewRequest(t, "GET", "/user2/repo1/issues/posters?q=OnE")
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
var data userSearchResponse
|
||||
DecodeJSON(t, resp, &data)
|
||||
|
||||
assert.Len(t, data.Results, 1)
|
||||
assert.EqualValues(t, "user1", data.Results[0].UserName)
|
||||
assert.EqualValues(t, 1, data.Results[0].UserID)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue