Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions server/app/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,9 @@ func (a *App) CopyCardFiles(sourceBoardID string, copiedBlocks []*model.Block, a
}

fileID, isOk := block.Fields["fileId"].(string)
if !isOk {
if !isOk || fileID == "" {
fileID, isOk = block.Fields["attachmentId"].(string)
if !isOk {
if !isOk || fileID == "" {
continue
}
}
Expand Down
10 changes: 3 additions & 7 deletions server/app/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,17 +672,13 @@ func TestCopyAndUpdateCardFiles(t *testing.T) {
})

t.Run("Empty file ID", func(t *testing.T) {
// blocks with an empty fileId/attachmentId should be treated
// as having no attached file
th.Store.EXPECT().GetBoard(validTestBoardID2).Return(&model.Board{ID: validTestBoardID2, TeamID: "validteam12345678901234567", IsTemplate: false}, nil)
mockedFileBackend := &mocks.FileBackend{}
th.App.filesBackend = mockedFileBackend
err := th.App.CopyAndUpdateCardFiles(validTestBoardID2, "userID", []*model.Block{emptyFileBlock}, false)
assert.Error(t, err)
if err != nil {
assert.True(t,
strings.Contains(err.Error(), "Block ID cannot be empty") ||
strings.Contains(err.Error(), "Could not validate file ID"),
"Expected error message to contain 'Block ID cannot be empty' or 'Could not validate file ID', got: %s", err.Error())
}
assert.NoError(t, err)
})
}

Expand Down
4 changes: 2 additions & 2 deletions server/model/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ func (b *Block) baseValidations() error {
return ErrBlockFieldsSizeLimitExceeded
}

if fileID, ok := b.Fields[BlockFieldFileId].(string); ok {
if fileID, ok := b.Fields[BlockFieldFileId].(string); ok && fileID != "" {
if err = ValidateFileId(fileID); err != nil {
return err
}
}

if attachmentId, ok := b.Fields[BlockFieldAttachmentId].(string); ok {
if attachmentId, ok := b.Fields[BlockFieldAttachmentId].(string); ok && attachmentId != "" {
if err = ValidateFileId(attachmentId); err != nil {
return err
}
Expand Down
32 changes: 32 additions & 0 deletions server/model/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,38 @@ func TestBlockIsValid(t *testing.T) {
require.ErrorIs(t, err, ErrBlockPropertiesInvalidType)
})

t.Run("Should accept block with empty fileId (no file attached)", func(t *testing.T) {
block := &Block{
ID: string(utils.IDTypeNone) + mmModel.NewId(),
BoardID: string(utils.IDTypeNone) + mmModel.NewId(),
CreatedBy: string(utils.IDTypeNone) + mmModel.NewId(),
ModifiedBy: string(utils.IDTypeNone) + mmModel.NewId(),
Schema: 1,
Type: TypeImage,
Title: "Image with empty fileId",
Fields: map[string]interface{}{BlockFieldFileId: ""},
CreateAt: 1234567890,
UpdateAt: 1234567890,
}
require.NoError(t, block.IsValid())
})

t.Run("Should accept block with empty attachmentId (no file attached)", func(t *testing.T) {
block := &Block{
ID: string(utils.IDTypeNone) + mmModel.NewId(),
BoardID: string(utils.IDTypeNone) + mmModel.NewId(),
CreatedBy: string(utils.IDTypeNone) + mmModel.NewId(),
ModifiedBy: string(utils.IDTypeNone) + mmModel.NewId(),
Schema: 1,
Type: TypeAttachment,
Title: "Attachment with empty attachmentId",
Fields: map[string]interface{}{BlockFieldAttachmentId: ""},
CreateAt: 1234567890,
UpdateAt: 1234567890,
}
require.NoError(t, block.IsValid())
})

t.Run("Should accept block with properties as map", func(t *testing.T) {
block := &Block{
ID: string(utils.IDTypeNone) + mmModel.NewId(),
Expand Down
Loading