From bd3e36553df0a665590a20107f5991a880680b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Vay=C3=A1?= Date: Wed, 2 Mar 2022 14:18:23 +0100 Subject: [PATCH] [MM-42022] Don't break importing process on missing display name of a channel (#19641) * Don't break importing process on missing display name of a channel * remove unused strings Co-authored-by: = <=> --- app/import_validators.go | 6 +++--- app/import_validators_test.go | 6 ++++-- i18n/en.json | 4 ---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/import_validators.go b/app/import_validators.go index 927776eac5..c22b782cdc 100644 --- a/app/import_validators.go +++ b/app/import_validators.go @@ -165,9 +165,9 @@ func validateChannelImportData(data *ChannelImportData) *model.AppError { return model.NewAppError("BulkImport", "app.import.validate_channel_import_data.name_characters.error", nil, "", http.StatusBadRequest) } - if data.DisplayName == nil { - return model.NewAppError("BulkImport", "app.import.validate_channel_import_data.display_name_missing.error", nil, "", http.StatusBadRequest) - } else if utf8.RuneCountInString(*data.DisplayName) == 0 || utf8.RuneCountInString(*data.DisplayName) > model.ChannelDisplayNameMaxRunes { + if data.DisplayName == nil || utf8.RuneCountInString(*data.DisplayName) == 0 { + data.DisplayName = data.Name // when displayName is missing we use name instead for displaying so we might as well convert it here. + } else if utf8.RuneCountInString(*data.DisplayName) > model.ChannelDisplayNameMaxRunes { return model.NewAppError("BulkImport", "app.import.validate_channel_import_data.display_name_length.error", nil, "", http.StatusBadRequest) } diff --git a/app/import_validators_test.go b/app/import_validators_test.go index 52f32d73e1..ff0b1c435d 100644 --- a/app/import_validators_test.go +++ b/app/import_validators_test.go @@ -404,11 +404,13 @@ func TestImportValidateChannelImportData(t *testing.T) { Type: &chanTypeOpen, } err = validateChannelImportData(&data) - require.NotNil(t, err, "Should have failed due to missing display_name.") + require.Nil(t, err, "Should have accepted having an empty display_name.") + require.Equal(t, data.Name, data.DisplayName, "Name and DisplayName should be the same if DisplayName is missing") data.DisplayName = ptrStr("") err = validateChannelImportData(&data) - require.NotNil(t, err, "Should have failed due to empty display_name.") + require.Nil(t, err, "Should have accepted having an empty display_name.") + require.Equal(t, data.Name, data.DisplayName, "Name and DisplayName should be the same if DisplayName is missing") data.DisplayName = ptrStr(strings.Repeat("abcdefghij", 7)) err = validateChannelImportData(&data) diff --git a/i18n/en.json b/i18n/en.json index c942c5594f..80d88dd093 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -5123,10 +5123,6 @@ "id": "app.import.validate_channel_import_data.display_name_length.error", "translation": "Channel display_name is not within permitted length constraints." }, - { - "id": "app.import.validate_channel_import_data.display_name_missing.error", - "translation": "Missing required channel property: display_name" - }, { "id": "app.import.validate_channel_import_data.header_length.error", "translation": "Channel header is too long."