MM-64632: Fix a panic in bulk import (#33360)

We were incorrect de-referencing the channels slice
without checking for nil pointer first.

https://mattermost.atlassian.net/browse/MM-64632
```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2025-07-09 09:37:36 +05:30
коммит произвёл GitHub
родитель 30ba6f573d
Коммит c4dde3d0ab
2 изменённых файлов: 22 добавлений и 8 удалений

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

@@ -791,16 +791,17 @@ func isValidGuestRoles(data UserImportData) bool {
gtc++
}
if *team.Channels != nil {
for _, channel := range *team.Channels {
if channel.Roles != nil && model.IsInRole(*channel.Roles, model.ChannelGuestRoleId) {
ctc++
}
if team.Channels == nil {
continue
}
for _, channel := range *team.Channels {
if channel.Roles != nil && model.IsInRole(*channel.Roles, model.ChannelGuestRoleId) {
ctc++
}
}
if ctc == len(*team.Channels) {
isChannelGuest = true
}
if ctc == len(*team.Channels) {
isChannelGuest = true
}
}
if gtc == len(*data.Teams) {

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

@@ -1704,6 +1704,19 @@ func TestIsValidGuestRoles(t *testing.T) {
},
expected: true,
},
{
name: "Valid case: User with team but nil channels array",
input: UserImportData{
Roles: model.NewPointer(model.SystemUserRoleId),
Teams: &[]UserTeamImportData{
{
Roles: model.NewPointer(model.TeamUserRoleId),
Channels: nil,
},
},
},
expected: true,
},
}
for _, tc := range testCases {