diff --git a/api4/user.go b/api4/user.go index 18e549a649..1436808cd9 100644 --- a/api4/user.go +++ b/api4/user.go @@ -468,25 +468,23 @@ func autocompleteUsers(c *Context, w http.ResponseWriter, r *http.Request) { searchOptions[store.USER_SEARCH_OPTION_NAMES_ONLY] = true } - if len(teamId) > 0 { - if len(channelId) > 0 { - if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { - c.SetPermissionError(model.PERMISSION_READ_CHANNEL) - return - } - - result, _ := app.AutocompleteUsersInChannel(teamId, channelId, name, searchOptions, c.IsSystemAdmin()) - autocomplete.Users = result.InChannel - autocomplete.OutOfChannel = result.OutOfChannel - } else { - if !app.SessionHasPermissionToTeam(c.Session, teamId, model.PERMISSION_VIEW_TEAM) { - c.SetPermissionError(model.PERMISSION_VIEW_TEAM) - return - } - - result, _ := app.AutocompleteUsersInTeam(teamId, name, searchOptions, c.IsSystemAdmin()) - autocomplete.Users = result.InTeam + if len(channelId) > 0 { + if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { + c.SetPermissionError(model.PERMISSION_READ_CHANNEL) + return } + + result, _ := app.AutocompleteUsersInChannel(teamId, channelId, name, searchOptions, c.IsSystemAdmin()) + autocomplete.Users = result.InChannel + autocomplete.OutOfChannel = result.OutOfChannel + } else if len(teamId) > 0 { + if !app.SessionHasPermissionToTeam(c.Session, teamId, model.PERMISSION_VIEW_TEAM) { + c.SetPermissionError(model.PERMISSION_VIEW_TEAM) + return + } + + result, _ := app.AutocompleteUsersInTeam(teamId, name, searchOptions, c.IsSystemAdmin()) + autocomplete.Users = result.InTeam } else { // No permission check required result, _ := app.SearchUsersInTeam("", name, searchOptions, c.IsSystemAdmin()) diff --git a/api4/user_test.go b/api4/user_test.go index 82949f9133..d73aea2924 100644 --- a/api4/user_test.go +++ b/api4/user_test.go @@ -507,6 +507,12 @@ func TestAutocompleteUsers(t *testing.T) { t.Fatal("should have many users") } + rusers, resp = Client.AutocompleteUsersInChannel("", channelId, "", "") + CheckNoError(t, resp) + if len(rusers.Users) < 2 { + t.Fatal("should have many users") + } + rusers, resp = Client.AutocompleteUsersInTeam(teamId, username, "") CheckNoError(t, resp)