From c9e0547dce89f0a779b67d0417a34aecba614906 Mon Sep 17 00:00:00 2001 From: Roman Perekhod Date: Wed, 26 Mar 2025 12:29:54 +0100 Subject: [PATCH] Fix pdf form creation for Onlyoffice --- changelog/unreleased/fix-pdf-form.md | 7 ++++++ .../ocis_full/config/ocis/app-registry.yaml | 16 +++++++------- .../ocis_full/config/onlyoffice/local.json | 1 - .../pkg/config/defaults/defaultconfig.go | 22 +++++++++---------- .../pkg/connector/fileconnector.go | 13 ++++++++++- .../pkg/connector/fileconnector_test.go | 2 ++ .../pkg/connector/fileinfo/onlyoffice.go | 10 +++++++++ 7 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 changelog/unreleased/fix-pdf-form.md diff --git a/changelog/unreleased/fix-pdf-form.md b/changelog/unreleased/fix-pdf-form.md new file mode 100644 index 00000000000..61ab7453c32 --- /dev/null +++ b/changelog/unreleased/fix-pdf-form.md @@ -0,0 +1,7 @@ +Bugfix: Fix pdf form creation + +Fix pdf form creation for Onlyoffice. +Adjust the file extension for Form to be PDF instead of DOCXF + +https://github.com/owncloud/ocis/pull/11163 +https://github.com/owncloud/ocis/issues/11164 diff --git a/deployments/examples/ocis_full/config/ocis/app-registry.yaml b/deployments/examples/ocis_full/config/ocis/app-registry.yaml index b7cf0decf9a..bdda5382b77 100644 --- a/deployments/examples/ocis_full/config/ocis/app-registry.yaml +++ b/deployments/examples/ocis_full/config/ocis/app-registry.yaml @@ -1,12 +1,5 @@ app_registry: mimetypes: - - mime_type: application/pdf - extension: pdf - name: PDF - description: PDF document - icon: '' - default_app: '' - allow_creation: false - mime_type: application/vnd.oasis.opendocument.text extension: odt name: OpenDocument @@ -41,7 +34,7 @@ app_registry: description: Form Document icon: '' default_app: OnlyOffice - allow_creation: true + allow_creation: false - mime_type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet extension: xlsx name: Microsoft Excel @@ -56,6 +49,13 @@ app_registry: icon: '' default_app: OnlyOffice allow_creation: true + - mime_type: application/pdf + extension: pdf + name: PDF form + description: PDF form document + icon: '' + default_app: OnlyOffice + allow_creation: true - mime_type: application/vnd.jupyter extension: ipynb name: Jupyter Notebook diff --git a/deployments/examples/ocis_full/config/onlyoffice/local.json b/deployments/examples/ocis_full/config/onlyoffice/local.json index 0db571fad42..21ded73c0cd 100755 --- a/deployments/examples/ocis_full/config/onlyoffice/local.json +++ b/deployments/examples/ocis_full/config/onlyoffice/local.json @@ -67,5 +67,4 @@ ] } } - } diff --git a/services/app-registry/pkg/config/defaults/defaultconfig.go b/services/app-registry/pkg/config/defaults/defaultconfig.go index 1c51f77c7fe..db87e974e1c 100644 --- a/services/app-registry/pkg/config/defaults/defaultconfig.go +++ b/services/app-registry/pkg/config/defaults/defaultconfig.go @@ -37,12 +37,6 @@ func DefaultConfig() *config.Config { func defaultMimeTypeConfig() []config.MimeTypeConfig { return []config.MimeTypeConfig{ - { - MimeType: "application/pdf", - Extension: "pdf", - Name: "PDF", - Description: "PDF document", - }, { MimeType: "application/vnd.oasis.opendocument.text", Extension: "odt", @@ -72,11 +66,10 @@ func defaultMimeTypeConfig() []config.MimeTypeConfig { AllowCreation: true, }, { - MimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.form", - Extension: "docxf", - Name: "Form Document", - Description: "Form Document", - AllowCreation: true, + MimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.form", + Extension: "docxf", + Name: "Form Document", + Description: "Form Document", }, { MimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", @@ -92,6 +85,13 @@ func defaultMimeTypeConfig() []config.MimeTypeConfig { Description: "Microsoft PowerPoint document", AllowCreation: true, }, + { + MimeType: "application/pdf", + Extension: "pdf", + Name: "PDF form", + Description: "PDF form document", + AllowCreation: true, + }, { MimeType: "application/vnd.jupyter", Extension: "ipynb", diff --git a/services/collaboration/pkg/connector/fileconnector.go b/services/collaboration/pkg/connector/fileconnector.go index a64bae5622d..ef27188e886 100644 --- a/services/collaboration/pkg/connector/fileconnector.go +++ b/services/collaboration/pkg/connector/fileconnector.go @@ -1243,9 +1243,20 @@ func (f *FileConnector) CheckFileInfo(ctx context.Context) (*ConnectorResponse, } } // fileinfo map + var size interface{} + size = int64(statRes.GetInfo().GetSize()) + // OnlyOffice requires a 0 size of files for "pdf" files, for extensions "docx", "xlsx", "pptx" it is optional + // For other extensions like "ods", "odt", "odp" the 0 size should be omitted + if strings.ToLower(f.cfg.App.Product) == "onlyoffice" && statRes.GetInfo().GetSize() == 0 { + ext := strings.ToLower(path.Ext(statRes.GetInfo().GetPath())) + if ext != ".pdf" { + size = nil + } + } + infoMap := map[string]interface{}{ fileinfo.KeyOwnerID: hexEncodedOwnerId, - fileinfo.KeySize: int64(statRes.GetInfo().GetSize()), + fileinfo.KeySize: size, fileinfo.KeyVersion: getVersion(statRes.GetInfo().GetMtime()), fileinfo.KeyBaseFileName: path.Base(statRes.GetInfo().GetPath()), fileinfo.KeyBreadcrumbDocName: path.Base(statRes.GetInfo().GetPath()), diff --git a/services/collaboration/pkg/connector/fileconnector_test.go b/services/collaboration/pkg/connector/fileconnector_test.go index 3412de77d75..3aa169df670 100644 --- a/services/collaboration/pkg/connector/fileconnector_test.go +++ b/services/collaboration/pkg/connector/fileconnector_test.go @@ -18,6 +18,7 @@ import ( typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/owncloud/ocis/v2/ocis-pkg/conversions" "github.com/owncloud/ocis/v2/ocis-pkg/shared" collabmocks "github.com/owncloud/ocis/v2/services/collaboration/mocks" "github.com/owncloud/ocis/v2/services/collaboration/pkg/config" @@ -1876,6 +1877,7 @@ var _ = Describe("FileConnector", func() { expectedFileInfo := &fileinfo.OnlyOffice{ Version: "v162738490", + Size: conversions.ToPointer(int64(998877)), BaseFileName: "test.txt", BreadcrumbDocName: "test.txt", BreadcrumbFolderName: "/path/to", diff --git a/services/collaboration/pkg/connector/fileinfo/onlyoffice.go b/services/collaboration/pkg/connector/fileinfo/onlyoffice.go index 4a6535a46dd..02a071ca49c 100644 --- a/services/collaboration/pkg/connector/fileinfo/onlyoffice.go +++ b/services/collaboration/pkg/connector/fileinfo/onlyoffice.go @@ -1,5 +1,9 @@ package fileinfo +import ( + "github.com/owncloud/ocis/v2/ocis-pkg/conversions" +) + // OnlyOffice fileInfo properties // // OnlyOffice WOPI check file info specification: @@ -13,6 +17,8 @@ type OnlyOffice struct { BaseFileName string `json:"BaseFileName,omitempty"` // copied from MS WOPI Version string `json:"Version,omitempty"` + // The size of the file in bytes, expressed as a long, a 64-bit signed integer. + Size *int64 `json:"Size,omitempty"` // // Breadcrumb properties @@ -137,6 +143,10 @@ func (oinfo *OnlyOffice) SetProperties(props map[string]interface{}) { oinfo.BaseFileName = value.(string) case KeyVersion: oinfo.Version = value.(string) + case KeySize: + if value != nil { + oinfo.Size = conversions.ToPointer(value.(int64)) + } case KeyBreadcrumbBrandName: oinfo.BreadcrumbBrandName = value.(string)