From 330a21a994b9ba73637048f2b1d676bd33636fdc Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Thu, 6 Jun 2019 13:44:06 +0100 Subject: [PATCH] [MM-16005] Check listOfAllowedChannels to be a not nil empty slice (#11050) * [MM-16005] Check listOfAllowedChannels to be a not nil empty slice The problem here had to do with the return type for a `nil` `[]string`. If `listOfAllowedChannels` is an empty list, that means that the user doesn't have permissions to view anything, hence we have to return an empty result. If it is `nil`, there are no restrictions and we can proceed. `[]string(nil)` behaves both as a `nil` value and as an "empty" slice, so this improves the check to be able to distinguish between both cases. * Add documentation to the GetViewUsersRestrictionsForTeam function --- app/user.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/user.go b/app/user.go index 918345f40e..117c683db0 100644 --- a/app/user.go +++ b/app/user.go @@ -1711,7 +1711,7 @@ func (a *App) SearchUsersInTeam(teamId string, term string, options *model.UserS if err != nil { return nil, err } - if len(listOfAllowedChannels) == 0 { + if listOfAllowedChannels != nil && len(listOfAllowedChannels) == 0 { return []*model.User{}, nil } @@ -2102,6 +2102,11 @@ func (a *App) GetViewUsersRestrictions(userId string) (*model.ViewUsersRestricti return &model.ViewUsersRestrictions{Teams: teamIdsWithPermission, Channels: channelIds}, nil } +/** + * Returns a list with the channel ids that the user has permissions to view on a + * team. If the result is an empty list, the user can't view any channel; if it's + * nil, there are no restrictions for the user in the specified team. + */ func (a *App) GetViewUsersRestrictionsForTeam(userId string, teamId string) ([]string, *model.AppError) { if a.HasPermissionTo(userId, model.PERMISSION_VIEW_MEMBERS) { return nil, nil