From 36a15925dc4d10ac0c0a14ddbc60855aa5331519 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Fri, 28 Apr 2017 11:04:13 -0400 Subject: Fix user autocomplete for DMs and GMs (#6265) --- api4/user.go | 32 +++++++++++++++----------------- api4/user_test.go | 6 ++++++ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/api4/user.go b/api4/user.go index 18e549a64..1436808cd 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 - } + if len(channelId) > 0 { + if !app.SessionHasPermissionToChannel(c.Session, channelId, model.PERMISSION_READ_CHANNEL) { + c.SetPermissionError(model.PERMISSION_READ_CHANNEL) + return + } - result, _ := app.AutocompleteUsersInTeam(teamId, name, searchOptions, c.IsSystemAdmin()) - autocomplete.Users = result.InTeam + 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 82949f913..d73aea292 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) -- cgit v1.2.3-1-g7c22