fix: make author search case insenstive (#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 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6782 Reviewed-by: Beowulf <beowulf@beocode.eu> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
parent
5b26596c5c
commit
499497c959
|
@ -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
|
// 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) {
|
func GetIssuePostersWithSearch(ctx context.Context, repo *Repository, isPull bool, search string, isShowFullName bool) ([]*user_model.User, error) {
|
||||||
users := make([]*user_model.User, 0, 30)
|
users := make([]*user_model.User, 0, 30)
|
||||||
var prefixCond builder.Cond = builder.Like{"name", search + "%"}
|
prefixCond := db.BuildCaseInsensitiveLike("name", search+"%")
|
||||||
if isShowFullName {
|
if isShowFullName {
|
||||||
prefixCond = prefixCond.Or(builder.Like{"full_name", "%" + search + "%"})
|
prefixCond = db.BuildCaseInsensitiveLike("full_name", "%"+search+"%")
|
||||||
}
|
}
|
||||||
|
|
||||||
cond := builder.In("`user`.id",
|
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()
|
allCount := htmlDoc.doc.Find("a[data-test-name='all-issue-count']").Text()
|
||||||
assert.Contains(t, allCount, "2\u00a0All")
|
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…
Reference in New Issue