[MM-25767] Quick switch users search is always falling back to the database (#14762)
* Refactor of getListOfAllowedChannelsForTeam
Also, I've fixed some problematic scenarios:
- The quick search doesn't provide team id so it was always failing
- When the teamId was empty and view restrictions too we always
return all the channels because if we do "strings.Contains("foo", "")
it always returns true
- There was a case, in quick search with a guest account, where you
get an empty result because teamId is not provided
* Error if team id is not passed when searching for the channel
If we search users passing the channel id, we must pass the team id
too so we avoid returning all the channels if we remove the empty
team id restriction we have in the getListOfAllowedChannelsForTeam
There is no known reason to search for a channel but not filtering
using the team id. Even guest accounts belong to a team
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
dd40d59c84
Коммит
4c33b7a35d
15
api4/user.go
15
api4/user.go
@@ -885,9 +885,18 @@ func autocompleteUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if len(channelId) > 0 {
|
||||
// Applying the provided teamId here is useful for DMs and GMs which don't belong
|
||||
// to a team. Applying it when the channel does belong to a team makes less sense,
|
||||
// but the permissions are checked above regardless.
|
||||
// We're using the channelId to search for users inside that channel and the team
|
||||
// to get the not in channel list. Also we want to include the DM and GM users for
|
||||
// that team which could only be obtained having the team id.
|
||||
if len(teamId) == 0 {
|
||||
c.Err = model.NewAppError("autocompleteUser",
|
||||
"api.user.autocomplete_users.missing_team_id.app_error",
|
||||
nil,
|
||||
"channelId="+channelId,
|
||||
http.StatusInternalServerError,
|
||||
)
|
||||
return
|
||||
}
|
||||
result, err := c.App.AutocompleteUsersInChannel(teamId, channelId, name, options)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
|
||||
@@ -1148,6 +1148,7 @@ func TestAutocompleteUsersInChannel(t *testing.T) {
|
||||
Username string
|
||||
ExpectedResults int
|
||||
MoreThan bool
|
||||
ShouldFail bool
|
||||
}{
|
||||
{
|
||||
"Autocomplete in channel for specific username",
|
||||
@@ -1156,6 +1157,7 @@ func TestAutocompleteUsersInChannel(t *testing.T) {
|
||||
username,
|
||||
1,
|
||||
false,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"Search for not valid username",
|
||||
@@ -1164,6 +1166,7 @@ func TestAutocompleteUsersInChannel(t *testing.T) {
|
||||
"amazonses",
|
||||
0,
|
||||
false,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"Search for all users",
|
||||
@@ -1172,14 +1175,16 @@ func TestAutocompleteUsersInChannel(t *testing.T) {
|
||||
"",
|
||||
2,
|
||||
true,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"Search all in specific channel",
|
||||
"Fail when the teamId is not provided",
|
||||
"",
|
||||
channelId,
|
||||
"",
|
||||
2,
|
||||
true,
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1187,12 +1192,17 @@ func TestAutocompleteUsersInChannel(t *testing.T) {
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
th.LoginBasic()
|
||||
rusers, resp := th.Client.AutocompleteUsersInChannel(tc.TeamId, tc.ChannelId, tc.Username, model.USER_SEARCH_DEFAULT_LIMIT, "")
|
||||
CheckNoError(t, resp)
|
||||
if tc.MoreThan {
|
||||
assert.True(t, len(rusers.Users) >= tc.ExpectedResults)
|
||||
if tc.ShouldFail {
|
||||
CheckErrorMessage(t, resp, "api.user.autocomplete_users.missing_team_id.app_error")
|
||||
} else {
|
||||
assert.Len(t, rusers.Users, tc.ExpectedResults)
|
||||
CheckNoError(t, resp)
|
||||
if tc.MoreThan {
|
||||
assert.True(t, len(rusers.Users) >= tc.ExpectedResults)
|
||||
} else {
|
||||
assert.Len(t, rusers.Users, tc.ExpectedResults)
|
||||
}
|
||||
}
|
||||
|
||||
th.Client.Logout()
|
||||
_, resp = th.Client.AutocompleteUsersInChannel(tc.TeamId, tc.ChannelId, tc.Username, model.USER_SEARCH_DEFAULT_LIMIT, "")
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
Ссылка в новой задаче
Block a user