[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
This commit is contained in:
Devin Binnie 2024-04-10 07:54:02 -04:00 committed by GitHub
parent 0ffbc75cfd
commit 39bb8a1121
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 0 deletions

View File

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

View File

@ -2862,6 +2862,30 @@ func testUserStoreSearch(t *testing.T, rctx request.CTX, ss store.Store) {
}, },
[]*model.User{u3}, []*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 { for _, testCase := range testCases {