[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: = <=>
Этот коммит содержится в:
Guillermo Vayá
2022-03-02 14:18:23 +01:00
коммит произвёл GitHub
родитель 32e3c2f0b8
Коммит bd3e36553d
3 изменённых файлов: 7 добавлений и 9 удалений

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

@@ -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)
}

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

@@ -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)

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

@@ -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."