[MM-24453] Sanitize user term search (#14494)
* Sanitize user term search Remove the @ at the beginning of the search term in order to make it possible for ES to return results
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2135096d88
Коммит
f135e6c1bf
@@ -45,7 +45,9 @@ func (s *SearchUserStore) Search(teamId, term string, options *model.UserSearchO
|
|||||||
return []*model.User{}, nil
|
return []*model.User{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
usersIds, err := engine.SearchUsersInTeam(teamId, listOfAllowedChannels, term, options)
|
sanitizedTerm := sanitizeSearchTerm(term)
|
||||||
|
|
||||||
|
usersIds, err := engine.SearchUsersInTeam(teamId, listOfAllowedChannels, sanitizedTerm, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mlog.Error("Encountered error on Search", mlog.String("search_engine", engine.GetName()), mlog.Err(err))
|
mlog.Error("Encountered error on Search", mlog.String("search_engine", engine.GetName()), mlog.Err(err))
|
||||||
continue
|
continue
|
||||||
@@ -101,10 +103,11 @@ func (s *SearchUserStore) autocompleteUsersInChannelByEngine(engine searchengine
|
|||||||
var err *model.AppError
|
var err *model.AppError
|
||||||
uchanIds := []string{}
|
uchanIds := []string{}
|
||||||
nuchanIds := []string{}
|
nuchanIds := []string{}
|
||||||
|
sanitizedTerm := sanitizeSearchTerm(term)
|
||||||
if options.ListOfAllowedChannels != nil && !strings.Contains(strings.Join(options.ListOfAllowedChannels, "."), channelId) {
|
if options.ListOfAllowedChannels != nil && !strings.Contains(strings.Join(options.ListOfAllowedChannels, "."), channelId) {
|
||||||
nuchanIds, err = engine.SearchUsersInTeam(teamId, options.ListOfAllowedChannels, term, options)
|
nuchanIds, err = engine.SearchUsersInTeam(teamId, options.ListOfAllowedChannels, sanitizedTerm, options)
|
||||||
} else {
|
} else {
|
||||||
uchanIds, nuchanIds, err = engine.SearchUsersInChannel(teamId, channelId, options.ListOfAllowedChannels, term, options)
|
uchanIds, nuchanIds, err = engine.SearchUsersInChannel(teamId, channelId, options.ListOfAllowedChannels, sanitizedTerm, options)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
10
store/searchlayer/utils.go
Обычный файл
10
store/searchlayer/utils.go
Обычный файл
@@ -0,0 +1,10 @@
|
|||||||
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See LICENSE.txt for license information.
|
||||||
|
|
||||||
|
package searchlayer
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
func sanitizeSearchTerm(term string) string {
|
||||||
|
return strings.TrimLeft(term, "@")
|
||||||
|
}
|
||||||
@@ -104,7 +104,7 @@ var searchUserStoreTests = []searchTest{
|
|||||||
{
|
{
|
||||||
Name: "Should ignore leading @ when searching users",
|
Name: "Should ignore leading @ when searching users",
|
||||||
Fn: testShouldIgnoreLeadingAtSymbols,
|
Fn: testShouldIgnoreLeadingAtSymbols,
|
||||||
Tags: []string{ENGINE_MYSQL, ENGINE_POSTGRES},
|
Tags: []string{ENGINE_ALL},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "Should search users in a case insensitive manner",
|
Name: "Should search users in a case insensitive manner",
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user