From 86053b69f0c0be62ed6be5ebd1b5ab08e1d9b38f Mon Sep 17 00:00:00 2001 From: Bruno Michel Date: Tue, 10 Oct 2023 12:17:45 +0200 Subject: [PATCH] Fix updatedByApps when a file is updated by OO --- model/office/callback.go | 9 ++++++++- web/office/office_test.go | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/model/office/callback.go b/model/office/callback.go index f04bf22c795..6c951c9c3c4 100644 --- a/model/office/callback.go +++ b/model/office/callback.go @@ -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" ) @@ -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} diff --git a/web/office/office_test.go b/web/office/office_test.go index 19375b3ecfa..2424e2f905d 100644 --- a/web/office/office_test.go +++ b/web/office/office_test.go @@ -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()) }) }