diff options
author | George Goldberg <george@gberg.me> | 2017-02-16 14:49:01 +0000 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2017-02-16 09:49:01 -0500 |
commit | d60d05f2d86400faf3303e655c46c5b8d77879c4 (patch) | |
tree | 8907bdf20c38ab06c066c0946126157462b34981 /app/import.go | |
parent | 821939e5dab144ac14b4f288cb8d0c9e3bb570d0 (diff) | |
download | chat-d60d05f2d86400faf3303e655c46c5b8d77879c4.tar.gz chat-d60d05f2d86400faf3303e655c46c5b8d77879c4.tar.bz2 chat-d60d05f2d86400faf3303e655c46c5b8d77879c4.zip |
PLT-5521: Mandatory version in line 1 of bulk import. (#5400)
Diffstat (limited to 'app/import.go')
-rw-r--r-- | app/import.go | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/app/import.go b/app/import.go index 1241048d3..10a915b2a 100644 --- a/app/import.go +++ b/app/import.go @@ -25,6 +25,7 @@ type LineImportData struct { Team *TeamImportData `json:"team"` Channel *ChannelImportData `json:"channel"` User *UserImportData `json:"user"` + Version *int `json:"version"` } type TeamImportData struct { @@ -101,7 +102,16 @@ func BulkImport(fileReader io.Reader, dryRun bool) (*model.AppError, int) { if err := decoder.Decode(&line); err != nil { return model.NewLocAppError("BulkImport", "app.import.bulk_import.json_decode.error", nil, err.Error()), lineNumber } else { - if err := ImportLine(line, dryRun); err != nil { + if lineNumber == 1 { + importDataFileVersion, apperr := processImportDataFileVersionLine(line) + if apperr != nil { + return apperr, lineNumber + } + + if importDataFileVersion != 1 { + return model.NewAppError("BulkImport", "app.import.bulk_import.unsupported_version.error", nil, "", http.StatusBadRequest), lineNumber + } + } else if err := ImportLine(line, dryRun); err != nil { return err, lineNumber } } @@ -114,6 +124,14 @@ func BulkImport(fileReader io.Reader, dryRun bool) (*model.AppError, int) { return nil, 0 } +func processImportDataFileVersionLine(line LineImportData) (int, *model.AppError) { + if line.Type != "version" || line.Version == nil { + return -1, model.NewAppError("BulkImport", "app.import.process_import_data_file_version_line.invalid_version.error", nil, "", http.StatusBadRequest) + } + + return *line.Version, nil +} + func ImportLine(line LineImportData, dryRun bool) *model.AppError { switch { case line.Type == "team": |