[MM-57517] Add exact user ID lookup to the search query for Users (#26661)

* [MM-57517] Add exact user ID lookup to the search query for Users

* Fix lint

* Add test for ID search
Этот коммит содержится в:
Devin Binnie
2024-04-10 07:54:02 -04:00
коммит произвёл GitHub
родитель 0ffbc75cfd
Коммит 39bb8a1121
2 изменённых файлов: 26 добавлений и 0 удалений

Просмотреть файл

@@ -1613,6 +1613,8 @@ func generateSearchQuery(query sq.SelectBuilder, terms []string, fields []string
}
termArgs = append(termArgs, fmt.Sprintf("%%%s%%", strings.TrimLeft(term, "@")))
}
searchFields = append(searchFields, "Id = ?")
termArgs = append(termArgs, strings.TrimLeft(term, "@"))
query = query.Where(fmt.Sprintf("(%s)", strings.Join(searchFields, " OR ")), termArgs...)
}

Просмотреть файл

@@ -2862,6 +2862,30 @@ func testUserStoreSearch(t *testing.T, rctx request.CTX, ss store.Store) {
},
[]*model.User{u3},
},
{
"search for Id of u1",
t1id,
u1.Id,
&model.UserSearchOptions{
AllowFullNames: true,
Limit: model.UserSearchDefaultLimit,
Roles: []string{},
TeamRoles: []string{},
},
[]*model.User{u1},
},
{
"search for partial Id of u1",
t1id,
u1.Id[:len(u1.Id)-1],
&model.UserSearchOptions{
AllowFullNames: true,
Limit: model.UserSearchDefaultLimit,
Roles: []string{},
TeamRoles: []string{},
},
[]*model.User{},
},
}
for _, testCase := range testCases {