diff --git a/services/collaboration/pkg/service/grpc/v0/service.go b/services/collaboration/pkg/service/grpc/v0/service.go index 34e1683f65..f6ea4d2efa 100644 --- a/services/collaboration/pkg/service/grpc/v0/service.go +++ b/services/collaboration/pkg/service/grpc/v0/service.go @@ -179,32 +179,27 @@ func (s *Service) OpenInApp( // getAppUrl will get the appURL that should be used based on the extension // and the provided view mode. -// "view" urls will be chosen first, then if the view mode is "read/write", -// "edit" urls will be prioritized. Note that "view" url might be returned for -// "read/write" view mode if no "edit" url is found. +// If the view mode is "read/write", the "edit" url is used. Otherwise, and if +// there is no "edit" url, the "view" url is used. func (s *Service) getAppUrl(fileExt string, viewMode appproviderv1beta1.ViewMode) string { - // prioritize view action if possible + // If read/write mode has been requested, prioritize edit action. + if viewMode == appproviderv1beta1.ViewMode_VIEW_MODE_READ_WRITE { + if editAppURL := s.appURLs.GetAppURLFor("edit", fileExt); editAppURL != "" { + return editAppURL + } + } + appURL := s.appURLs.GetAppURLFor("view", fileExt) - 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 + if appURL == "" && strings.ToLower(s.config.App.Product) == "collabora" { + // collabora might provide only one action per extension, which is + // "view" (checked above), "edit" or "view_comment" (this last one // is exclusive of collabora) - if appURL == "" { - if editURL := s.appURLs.GetAppURLFor("edit", fileExt); editURL != "" { - return editURL - } - if commentURL := s.appURLs.GetAppURLFor("view_comment", fileExt); commentURL != "" { - return commentURL - } + if editURL := s.appURLs.GetAppURLFor("edit", fileExt); editURL != "" { + return editURL } - } else { - // If not collabora, there might be an edit action for the extension. - // If read/write mode has been requested, prioritize edit action. - if viewMode == appproviderv1beta1.ViewMode_VIEW_MODE_READ_WRITE { - if editAppURL := s.appURLs.GetAppURLFor("edit", fileExt); editAppURL != "" { - appURL = editAppURL - } + if commentURL := s.appURLs.GetAppURLFor("view_comment", fileExt); commentURL != "" { + return commentURL } } diff --git a/services/collaboration/pkg/service/grpc/v0/service_test.go b/services/collaboration/pkg/service/grpc/v0/service_test.go index 105841db74..c0e36f7e3c 100644 --- a/services/collaboration/pkg/service/grpc/v0/service_test.go +++ b/services/collaboration/pkg/service/grpc/v0/service_test.go @@ -197,16 +197,16 @@ var _ = Describe("Discovery", func() { Expect(resp.GetAppUrl().GetFormParameters()["access_token_ttl"]).To(Equal(strconv.FormatInt(nowTime.Add(5*time.Hour).Unix()*1000, 10))) }, Entry("Microsoft chat no lang", "Microsoft", "", false, "https://cloud.opencloud.test/hosting/wopi/word/edit?WOPISrc=https%3A%2F%2Fwopi.opencloud.test%2Fwopi%2Ffiles%2F2f6ec18696dd1008106749bd94106e5cfad5c09e15de7b77088d03843e71b43e"), - Entry("Collabora chat no lang", "Collabora", "", false, "https://cloud.opencloud.test/hosting/wopi/word/view?WOPISrc=https%3A%2F%2Fwopi.opencloud.test%2Fwopi%2Ffiles%2F2f6ec18696dd1008106749bd94106e5cfad5c09e15de7b77088d03843e71b43e&closebutton=false"), + Entry("Collabora chat no lang", "Collabora", "", false, "https://cloud.opencloud.test/hosting/wopi/word/edit?WOPISrc=https%3A%2F%2Fwopi.opencloud.test%2Fwopi%2Ffiles%2F2f6ec18696dd1008106749bd94106e5cfad5c09e15de7b77088d03843e71b43e&closebutton=false"), Entry("OnlyOffice chat no lang", "OnlyOffice", "", false, "https://cloud.opencloud.test/hosting/wopi/word/edit?WOPISrc=https%3A%2F%2Fwopi.opencloud.test%2Fwopi%2Ffiles%2F2f6ec18696dd1008106749bd94106e5cfad5c09e15de7b77088d03843e71b43e"), Entry("Microsoft chat lang", "Microsoft", "de", false, "https://cloud.opencloud.test/hosting/wopi/word/edit?UI_LLCC=de-DE&WOPISrc=https%3A%2F%2Fwopi.opencloud.test%2Fwopi%2Ffiles%2F2f6ec18696dd1008106749bd94106e5cfad5c09e15de7b77088d03843e71b43e"), - Entry("Collabora chat lang", "Collabora", "de", false, "https://cloud.opencloud.test/hosting/wopi/word/view?WOPISrc=https%3A%2F%2Fwopi.opencloud.test%2Fwopi%2Ffiles%2F2f6ec18696dd1008106749bd94106e5cfad5c09e15de7b77088d03843e71b43e&closebutton=false&lang=de-DE"), + Entry("Collabora chat lang", "Collabora", "de", false, "https://cloud.opencloud.test/hosting/wopi/word/edit?WOPISrc=https%3A%2F%2Fwopi.opencloud.test%2Fwopi%2Ffiles%2F2f6ec18696dd1008106749bd94106e5cfad5c09e15de7b77088d03843e71b43e&closebutton=false&lang=de-DE"), Entry("OnlyOffice chat lang", "OnlyOffice", "de", false, "https://cloud.opencloud.test/hosting/wopi/word/edit?WOPISrc=https%3A%2F%2Fwopi.opencloud.test%2Fwopi%2Ffiles%2F2f6ec18696dd1008106749bd94106e5cfad5c09e15de7b77088d03843e71b43e&ui=de-DE"), Entry("Microsoft no chat no lang", "Microsoft", "", true, "https://cloud.opencloud.test/hosting/wopi/word/edit?WOPISrc=https%3A%2F%2Fwopi.opencloud.test%2Fwopi%2Ffiles%2F2f6ec18696dd1008106749bd94106e5cfad5c09e15de7b77088d03843e71b43e&dchat=1"), - Entry("Collabora no chat no lang", "Collabora", "", true, "https://cloud.opencloud.test/hosting/wopi/word/view?WOPISrc=https%3A%2F%2Fwopi.opencloud.test%2Fwopi%2Ffiles%2F2f6ec18696dd1008106749bd94106e5cfad5c09e15de7b77088d03843e71b43e&closebutton=false&dchat=1"), + Entry("Collabora no chat no lang", "Collabora", "", true, "https://cloud.opencloud.test/hosting/wopi/word/edit?WOPISrc=https%3A%2F%2Fwopi.opencloud.test%2Fwopi%2Ffiles%2F2f6ec18696dd1008106749bd94106e5cfad5c09e15de7b77088d03843e71b43e&closebutton=false&dchat=1"), Entry("OnlyOffice no chat no lang", "OnlyOffice", "", true, "https://cloud.opencloud.test/hosting/wopi/word/edit?WOPISrc=https%3A%2F%2Fwopi.opencloud.test%2Fwopi%2Ffiles%2F2f6ec18696dd1008106749bd94106e5cfad5c09e15de7b77088d03843e71b43e&dchat=1"), Entry("Microsoft no chat lang", "Microsoft", "de", true, "https://cloud.opencloud.test/hosting/wopi/word/edit?UI_LLCC=de-DE&WOPISrc=https%3A%2F%2Fwopi.opencloud.test%2Fwopi%2Ffiles%2F2f6ec18696dd1008106749bd94106e5cfad5c09e15de7b77088d03843e71b43e&dchat=1"), - Entry("Collabora no chat lang", "Collabora", "de", true, "https://cloud.opencloud.test/hosting/wopi/word/view?WOPISrc=https%3A%2F%2Fwopi.opencloud.test%2Fwopi%2Ffiles%2F2f6ec18696dd1008106749bd94106e5cfad5c09e15de7b77088d03843e71b43e&closebutton=false&dchat=1&lang=de-DE"), + Entry("Collabora no chat lang", "Collabora", "de", true, "https://cloud.opencloud.test/hosting/wopi/word/edit?WOPISrc=https%3A%2F%2Fwopi.opencloud.test%2Fwopi%2Ffiles%2F2f6ec18696dd1008106749bd94106e5cfad5c09e15de7b77088d03843e71b43e&closebutton=false&dchat=1&lang=de-DE"), Entry("OnlyOffice no chat lang", "OnlyOffice", "de", true, "https://cloud.opencloud.test/hosting/wopi/word/edit?WOPISrc=https%3A%2F%2Fwopi.opencloud.test%2Fwopi%2Ffiles%2F2f6ec18696dd1008106749bd94106e5cfad5c09e15de7b77088d03843e71b43e&dchat=1&ui=de-DE"), ) DescribeTable( @@ -270,6 +270,57 @@ var _ = Describe("Discovery", func() { Entry("without a mobile request nothing is added", "OnlyOffice", "ee", true, appproviderv1beta1.ViewMode_VIEW_MODE_READ_WRITE, "", ""), Entry("collabora does not get it", "Collabora", "ee", true, appproviderv1beta1.ViewMode_VIEW_MODE_READ_ONLY, "true", ""), ) + DescribeTable( + "Collabora action", + func(viewMode appproviderv1beta1.ViewMode, filePath, expectedPath string) { + ctx := context.Background() + nowTime := time.Now() + + cfg.Wopi.WopiSrc = "https://wopi.opencloud.test" + cfg.Wopi.Secret = "my_supa_secret" + cfg.App.Name = "Collabora" + cfg.App.Product = "Collabora" + + myself := &userv1beta1.User{ + Id: &userv1beta1.UserId{ + Idp: "myIdp", + OpaqueId: "opaque001", + Type: userv1beta1.UserType_USER_TYPE_PRIMARY, + }, + Username: "username", + } + + req := &appproviderv1beta1.OpenInAppRequest{ + ResourceInfo: &providerv1beta1.ResourceInfo{ + Id: &providerv1beta1.ResourceId{ + StorageId: "myStorage", + OpaqueId: "storageOpaque001", + SpaceId: "SpaceA", + }, + Path: filePath, + }, + ViewMode: viewMode, + AccessToken: MintToken(myself, cfg.TokenManager.JWTSecret, nowTime), + } + + gatewayClient.On("WhoAmI", mock.Anything, mock.Anything).Times(1).Return(&gatewayv1beta1.WhoAmIResponse{ + Status: status.NewOK(ctx), + User: myself, + }, nil) + + resp, err := srv.OpenInApp(ctx, req) + Expect(err).To(Succeed()) + Expect(resp.GetStatus().GetCode()).To(Equal(rpcv1beta1.Code_CODE_OK)) + + appURL, err := url.Parse(resp.GetAppUrl().GetAppUrl()) + Expect(err).To(Succeed()) + Expect(appURL.Path).To(Equal(expectedPath)) + }, + Entry("read/write uses the edit action", appproviderv1beta1.ViewMode_VIEW_MODE_READ_WRITE, "/path/to/file.docx", "/hosting/wopi/word/edit"), + Entry("read only uses the view action", appproviderv1beta1.ViewMode_VIEW_MODE_READ_ONLY, "/path/to/file.docx", "/hosting/wopi/word/view"), + Entry("view only uses the view action", appproviderv1beta1.ViewMode_VIEW_MODE_VIEW_ONLY, "/path/to/file.docx", "/hosting/wopi/word/view"), + Entry("read/write uses the view action when there is no edit action", appproviderv1beta1.ViewMode_VIEW_MODE_READ_WRITE, "/path/to/file.pdf", "/hosting/wopi/word/view"), + ) It("Success with Wopi Proxy", func() { ctx := context.Background()