Skip to content

Commit

Permalink
Fix cozyMetadata.uploaded* fields on upload
Browse files Browse the repository at this point in the history
When the content of a file is modified by uploading a new version of it,
the cozyMetadata.uploaded* fields must be updated.
  • Loading branch information
nono committed Oct 9, 2023
1 parent 2368a15 commit 95519a2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions web/files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -2198,6 +2198,11 @@ func updateFileCozyMetadata(c echo.Context, file *vfs.FileDoc, setUploadFields b
if len(fcm.UpdatedByApps) > 0 {
file.CozyMetadata.UpdatedByApp(fcm.UpdatedByApps[0])
}
if setUploadFields {
file.CozyMetadata.UploadedAt = fcm.UploadedAt
file.CozyMetadata.UploadedBy = fcm.UploadedBy
file.CozyMetadata.UploadedOn = fcm.UploadedOn
}
}

if setUploadFields {
Expand Down
4 changes: 3 additions & 1 deletion web/files/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1392,8 +1392,9 @@ func TestFiles(t *testing.T) {
Object()

data1 := obj.Value("data").Object()
attrs1 := data1.Value("attributes").Object()
file1ID := data1.Value("id").String().NotEmpty().Raw()
attrs1 := data1.Value("attributes").Object()
uploadedAt1 := attrs1.Path("$.cozyMetadata.uploadedAt").String().NotEmpty().Raw()

buf, err := readFile(storage, "/willbemodified")
assert.NoError(t, err)
Expand Down Expand Up @@ -1435,6 +1436,7 @@ func TestFiles(t *testing.T) {
attrs.ValueEqual("class", "audio")
attrs.ValueEqual("mime", "audio/mp3")
attrs.ValueEqual("executable", false)
attrs.Path("$.cozyMetadata.uploadedAt").NotEqual(uploadedAt1)

buf, err = readFile(storage, "/willbemodified")
assert.NoError(t, err)
Expand Down

0 comments on commit 95519a2

Please sign in to comment.