diff --git a/server/channels/app/imports/import_validators.go b/server/channels/app/imports/import_validators.go index 8fa3f7ff1b..f9bbc6dd31 100644 --- a/server/channels/app/imports/import_validators.go +++ b/server/channels/app/imports/import_validators.go @@ -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) { diff --git a/server/channels/app/imports/import_validators_test.go b/server/channels/app/imports/import_validators_test.go index 17b6647c8c..4502d2772e 100644 --- a/server/channels/app/imports/import_validators_test.go +++ b/server/channels/app/imports/import_validators_test.go @@ -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 {