From c822522b657459ba501ccad6c3dddf0973ea9941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Thu, 17 Oct 2024 11:45:19 +0200 Subject: [PATCH 1/4] feat: include a provider option to allow custom app names --- services/collaboration/pkg/config/app.go | 3 ++- services/collaboration/pkg/config/defaults/defaultconfig.go | 1 + services/collaboration/pkg/connector/fileconnector.go | 2 +- services/collaboration/pkg/service/grpc/v0/service.go | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/services/collaboration/pkg/config/app.go b/services/collaboration/pkg/config/app.go index a2b2f7bb11..2dd75011ef 100644 --- a/services/collaboration/pkg/config/app.go +++ b/services/collaboration/pkg/config/app.go @@ -2,7 +2,8 @@ package config // App defines the available app configuration. type App struct { - Name string `yaml:"name" env:"COLLABORATION_APP_NAME" desc:"The name of the app, either Collabora, OnlyOffice, Microsoft365 or MicrosoftOfficeOnline" introductionVersion:"6.0.0"` + Name string `yaml:"name" env:"COLLABORATION_APP_NAME" desc:"The name of the app" introductionVersion:"6.0.0"` + Provider string `yaml:"provider" env:"COLLABORATION_APP_PROVIDER" desc:"The provider of the app, either Collabora, OnlyOffice, Microsoft365 or MicrosoftOfficeOnline" introductionVersion:"%%NEXT%%"` Description string `yaml:"description" env:"COLLABORATION_APP_DESCRIPTION" desc:"App description" introductionVersion:"6.0.0"` Icon string `yaml:"icon" env:"COLLABORATION_APP_ICON" desc:"Icon for the app" introductionVersion:"6.0.0"` LockName string `yaml:"lockname" env:"COLLABORATION_APP_LOCKNAME" desc:"Name for the app lock" introductionVersion:"6.0.0"` diff --git a/services/collaboration/pkg/config/defaults/defaultconfig.go b/services/collaboration/pkg/config/defaults/defaultconfig.go index d8bc4aab3c..95ef6e7de3 100644 --- a/services/collaboration/pkg/config/defaults/defaultconfig.go +++ b/services/collaboration/pkg/config/defaults/defaultconfig.go @@ -24,6 +24,7 @@ func DefaultConfig() *config.Config { }, App: config.App{ Name: "Collabora", + Provider: "Collabora", Description: "Open office documents with Collabora", Icon: "image-edit", LockName: "com.github.owncloud.collaboration", diff --git a/services/collaboration/pkg/connector/fileconnector.go b/services/collaboration/pkg/connector/fileconnector.go index b8dc73382d..17629d77c7 100644 --- a/services/collaboration/pkg/connector/fileconnector.go +++ b/services/collaboration/pkg/connector/fileconnector.go @@ -1172,7 +1172,7 @@ func (f *FileConnector) CheckFileInfo(ctx context.Context) (*ConnectorResponse, // This will help with the CI because we're using a "FakeOffice" app // for the wopi validator, which requires a Microsoft fileinfo var info fileinfo.FileInfo - switch strings.ToLower(f.cfg.App.Name) { + switch strings.ToLower(f.cfg.App.Provider) { case "collabora": info = &fileinfo.Collabora{} case "onlyoffice": diff --git a/services/collaboration/pkg/service/grpc/v0/service.go b/services/collaboration/pkg/service/grpc/v0/service.go index 5fa63b9ab6..fc29cc2041 100644 --- a/services/collaboration/pkg/service/grpc/v0/service.go +++ b/services/collaboration/pkg/service/grpc/v0/service.go @@ -188,7 +188,7 @@ func (s *Service) getAppUrl(fileExt string, viewMode appproviderv1beta1.ViewMode // prioritize view action if possible appURL := s.getAppUrlFor("view", fileExt) - if strings.ToLower(s.config.App.Name) == "collabora" { + if strings.ToLower(s.config.App.Provider) == "collabora" { // collabora provides only one action per extension. usual options // are "view" (checked above), "edit" or "view_comment" (this last one // is exclusive of collabora) @@ -276,7 +276,7 @@ func (s *Service) addQueryToURL(baseURL string, req *appproviderv1beta1.OpenInAp } if lang != "" { - switch strings.ToLower(s.config.App.Name) { + switch strings.ToLower(s.config.App.Provider) { case "collabora": q.Add("lang", lang) case "onlyoffice": From 32607b24817bf244ce2d25d5d09f3beb1c34609b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Fri, 18 Oct 2024 08:59:55 +0200 Subject: [PATCH 2/4] refactor: change App.Provider to App.Product --- services/collaboration/pkg/config/app.go | 2 +- services/collaboration/pkg/config/defaults/defaultconfig.go | 2 +- services/collaboration/pkg/connector/fileconnector.go | 2 +- services/collaboration/pkg/service/grpc/v0/service.go | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/collaboration/pkg/config/app.go b/services/collaboration/pkg/config/app.go index 2dd75011ef..d22e0d43c5 100644 --- a/services/collaboration/pkg/config/app.go +++ b/services/collaboration/pkg/config/app.go @@ -3,7 +3,7 @@ package config // App defines the available app configuration. type App struct { Name string `yaml:"name" env:"COLLABORATION_APP_NAME" desc:"The name of the app" introductionVersion:"6.0.0"` - Provider string `yaml:"provider" env:"COLLABORATION_APP_PROVIDER" desc:"The provider of the app, either Collabora, OnlyOffice, Microsoft365 or MicrosoftOfficeOnline" introductionVersion:"%%NEXT%%"` + Product string `yaml:"product" env:"COLLABORATION_APP_PRODUCT" desc:"The WebOffice app, either Collabora, OnlyOffice, Microsoft365 or MicrosoftOfficeOnline" introductionVersion:"%%NEXT%%"` Description string `yaml:"description" env:"COLLABORATION_APP_DESCRIPTION" desc:"App description" introductionVersion:"6.0.0"` Icon string `yaml:"icon" env:"COLLABORATION_APP_ICON" desc:"Icon for the app" introductionVersion:"6.0.0"` LockName string `yaml:"lockname" env:"COLLABORATION_APP_LOCKNAME" desc:"Name for the app lock" introductionVersion:"6.0.0"` diff --git a/services/collaboration/pkg/config/defaults/defaultconfig.go b/services/collaboration/pkg/config/defaults/defaultconfig.go index 95ef6e7de3..8287fcd00f 100644 --- a/services/collaboration/pkg/config/defaults/defaultconfig.go +++ b/services/collaboration/pkg/config/defaults/defaultconfig.go @@ -24,7 +24,7 @@ func DefaultConfig() *config.Config { }, App: config.App{ Name: "Collabora", - Provider: "Collabora", + Product: "Collabora", Description: "Open office documents with Collabora", Icon: "image-edit", LockName: "com.github.owncloud.collaboration", diff --git a/services/collaboration/pkg/connector/fileconnector.go b/services/collaboration/pkg/connector/fileconnector.go index 17629d77c7..073a18daf1 100644 --- a/services/collaboration/pkg/connector/fileconnector.go +++ b/services/collaboration/pkg/connector/fileconnector.go @@ -1172,7 +1172,7 @@ func (f *FileConnector) CheckFileInfo(ctx context.Context) (*ConnectorResponse, // This will help with the CI because we're using a "FakeOffice" app // for the wopi validator, which requires a Microsoft fileinfo var info fileinfo.FileInfo - switch strings.ToLower(f.cfg.App.Provider) { + switch strings.ToLower(f.cfg.App.Product) { case "collabora": info = &fileinfo.Collabora{} case "onlyoffice": diff --git a/services/collaboration/pkg/service/grpc/v0/service.go b/services/collaboration/pkg/service/grpc/v0/service.go index fc29cc2041..74e12be130 100644 --- a/services/collaboration/pkg/service/grpc/v0/service.go +++ b/services/collaboration/pkg/service/grpc/v0/service.go @@ -188,7 +188,7 @@ func (s *Service) getAppUrl(fileExt string, viewMode appproviderv1beta1.ViewMode // prioritize view action if possible appURL := s.getAppUrlFor("view", fileExt) - if strings.ToLower(s.config.App.Provider) == "collabora" { + if strings.ToLower(s.config.App.Product) == "collabora" { // collabora provides only one action per extension. usual options // are "view" (checked above), "edit" or "view_comment" (this last one // is exclusive of collabora) @@ -276,7 +276,7 @@ func (s *Service) addQueryToURL(baseURL string, req *appproviderv1beta1.OpenInAp } if lang != "" { - switch strings.ToLower(s.config.App.Provider) { + switch strings.ToLower(s.config.App.Product) { case "collabora": q.Add("lang", lang) case "onlyoffice": From 1e8b5fae7084f38afa493520051a30ab09dc1d4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Tue, 5 Nov 2024 11:45:08 +0100 Subject: [PATCH 3/4] fix: add product name to the registration info --- services/collaboration/pkg/helpers/registration.go | 1 + 1 file changed, 1 insertion(+) diff --git a/services/collaboration/pkg/helpers/registration.go b/services/collaboration/pkg/helpers/registration.go index 0fa416bd4b..a6609fe20e 100644 --- a/services/collaboration/pkg/helpers/registration.go +++ b/services/collaboration/pkg/helpers/registration.go @@ -68,6 +68,7 @@ func RegisterAppProvider( Icon: cfg.App.Icon, Address: cfg.GRPC.Namespace + "." + cfg.Service.Name + "." + cfg.App.Name, MimeTypes: mimeTypes, + ProductName: cfg.App.Product, }, } gwc, err := gws.Next() From ff8d6746669f2d37fa2e29220b596b5587358737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Tue, 5 Nov 2024 13:20:28 +0100 Subject: [PATCH 4/4] fix: adjust tests for the new config option --- .drone.star | 3 +++ services/collaboration/pkg/connector/fileconnector_test.go | 4 ++++ services/collaboration/pkg/service/grpc/v0/service_test.go | 2 ++ 3 files changed, 9 insertions(+) diff --git a/.drone.star b/.drone.star index 2764e87072..458c2a245e 100644 --- a/.drone.star +++ b/.drone.star @@ -2935,14 +2935,17 @@ def wopiCollaborationService(name): if name == "collabora": environment["COLLABORATION_APP_NAME"] = "Collabora" + environment["COLLABORATION_APP_PRODUCT"] = "Collabora" environment["COLLABORATION_APP_ADDR"] = "https://collabora:9980" environment["COLLABORATION_APP_ICON"] = "https://collabora:9980/favicon.ico" elif name == "onlyoffice": environment["COLLABORATION_APP_NAME"] = "OnlyOffice" + environment["COLLABORATION_APP_PRODUCT"] = "OnlyOffice" environment["COLLABORATION_APP_ADDR"] = "https://onlyoffice" environment["COLLABORATION_APP_ICON"] = "https://onlyoffice/web-apps/apps/documenteditor/main/resources/img/favicon.ico" elif name == "fakeoffice": environment["COLLABORATION_APP_NAME"] = "FakeOffice" + environment["COLLABORATION_APP_PRODUCT"] = "Microsoft" environment["COLLABORATION_APP_ADDR"] = "http://fakeoffice:8080" environment["COLLABORATION_WOPI_SRC"] = "http://%s:9300" % service_name diff --git a/services/collaboration/pkg/connector/fileconnector_test.go b/services/collaboration/pkg/connector/fileconnector_test.go index f03ab5044b..b0f48586f5 100644 --- a/services/collaboration/pkg/connector/fileconnector_test.go +++ b/services/collaboration/pkg/connector/fileconnector_test.go @@ -48,6 +48,7 @@ var _ = Describe("FileConnector", func() { App: config.App{ LockName: "testName_for_unittests", // Only the LockName is used Name: "test", + Product: "Microsoft", }, Wopi: config.Wopi{ WopiSrc: "https://ocis.server.prv", @@ -1761,6 +1762,7 @@ var _ = Describe("FileConnector", func() { // change wopi app provider cfg.App.Name = "Collabora" + cfg.App.Product = "Collabora" expectedFileInfo := &fileinfo.Collabora{ OwnerID: "61616262636340637573746f6d496470", // hex of aabbcc@customIdp @@ -1834,6 +1836,7 @@ var _ = Describe("FileConnector", func() { // change wopi app provider cfg.App.Name = "Collabora" + cfg.App.Product = "Collabora" expectedFileInfo := &fileinfo.Collabora{ OwnerID: "61616262636340637573746f6d496470", // hex of aabbcc@customIdp @@ -1921,6 +1924,7 @@ var _ = Describe("FileConnector", func() { // change wopi app provider cfg.App.Name = "OnlyOffice" + cfg.App.Product = "OnlyOffice" response, err := fc.CheckFileInfo(ctx) Expect(err).ToNot(HaveOccurred()) diff --git a/services/collaboration/pkg/service/grpc/v0/service_test.go b/services/collaboration/pkg/service/grpc/v0/service_test.go index 636a9f4acf..1c2359ad85 100644 --- a/services/collaboration/pkg/service/grpc/v0/service_test.go +++ b/services/collaboration/pkg/service/grpc/v0/service_test.go @@ -147,6 +147,7 @@ var _ = Describe("Discovery", func() { cfg.Wopi.Secret = "my_supa_secret" cfg.Wopi.DisableChat = disableChat cfg.App.Name = appName + cfg.App.Product = appName myself := &userv1beta1.User{ Id: &userv1beta1.UserId{ @@ -333,6 +334,7 @@ var _ = Describe("Discovery", func() { cfg.Wopi.WopiSrc = "htttps://wopiserver.test.prv" cfg.Wopi.Secret = "my_supa_secret" cfg.App.Name = "OnlyOffice" + cfg.App.Product = "OnlyOffice" myself := &userv1beta1.User{ Id: &userv1beta1.UserId{