[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
Этот коммит содержится в:
Mario de Frutos Dieguez
2020-06-26 20:37:35 +02:00
коммит произвёл GitHub
родитель dd40d59c84
Коммит 4c33b7a35d
6 изменённых файлов: 234 добавлений и 168 удалений

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

@@ -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)