Skip to content

Commit

Permalink
Fix updatedByApps when a file is updated by OO (#4156)
Browse files Browse the repository at this point in the history
  • Loading branch information
nono authored Oct 10, 2023
2 parents fdb9bcd + 86053b6 commit 1753348
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion model/office/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/cozy/cozy-stack/model/vfs"
"github.com/cozy/cozy-stack/pkg/config/config"
"github.com/cozy/cozy-stack/pkg/crypto"
"github.com/cozy/cozy-stack/pkg/metadata"

jwt "github.com/golang-jwt/jwt/v4"
)
Expand Down Expand Up @@ -146,13 +147,19 @@ func saveFile(inst *instance.Instance, detector conflictDetector, downloadURL st
_ = res.Body.Close()
}()

instanceURL := inst.PageURL("/", nil)
newfile := file.Clone().(*vfs.FileDoc)
newfile.MD5Sum = nil // Let the VFS compute the new md5sum
newfile.ByteSize = res.ContentLength
if newfile.CozyMetadata == nil {
newfile.CozyMetadata = vfs.NewCozyMetadata(inst.PageURL("/", nil))
newfile.CozyMetadata = vfs.NewCozyMetadata(instanceURL)
}
newfile.UpdatedAt = time.Now()
newfile.CozyMetadata.UpdatedByApp(&metadata.UpdatedByAppEntry{
Slug: OOSlug,
Date: newfile.UpdatedAt,
Instance: instanceURL,
})
newfile.CozyMetadata.UpdatedAt = newfile.UpdatedAt
newfile.CozyMetadata.UploadedAt = &newfile.UpdatedAt
newfile.CozyMetadata.UploadedBy = &vfs.UploadedByEntry{Slug: OOSlug}
Expand Down
1 change: 1 addition & 0 deletions web/office/office_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ func TestOffice(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, "letter (2).docx", conflict.DocName)
assert.Equal(t, "onlyoffice-server", conflict.CozyMetadata.UploadedBy.Slug)
assert.Equal(t, "onlyoffice-server", conflict.CozyMetadata.UpdatedByApps[0].Slug)
assert.NotEqual(t, conflictRev, conflict.Rev())
})
}
Expand Down

0 comments on commit 1753348

Please sign in to comment.