From 8e8d6284ea4b5ab732ecf8d3b517343f5bef9422 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Wed, 15 Sep 2021 17:20:50 +0200 Subject: [PATCH 1/4] fix opening a file with the wopi driver when the office suite only supports viewing the filetype --- pkg/app/provider/wopi/wopi.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/pkg/app/provider/wopi/wopi.go b/pkg/app/provider/wopi/wopi.go index 0cf3aa734e..350a9babd8 100644 --- a/pkg/app/provider/wopi/wopi.go +++ b/pkg/app/provider/wopi/wopi.go @@ -142,16 +142,29 @@ func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.Resourc } q.Add("appname", p.conf.AppName) - q.Add("appurl", p.appURLs["edit"][ext]) - if p.conf.AppIntURL != "" { - q.Add("appinturl", p.conf.AppIntURL) + var viewAppURL string + if viewAppURLs, ok := p.appURLs["view"]; ok { + if viewAppURL, ok = viewAppURLs[ext]; ok { + q.Add("appviewurl", viewAppURL) + } } - if viewExts, ok := p.appURLs["view"]; ok { - if url, ok := viewExts[ext]; ok { - q.Add("appviewurl", url) + if editAppURLs, ok := p.appURLs["edit"]; !ok { + if editAppURL, ok := editAppURLs[ext]; ok { + q.Add("appurl", editAppURL) } + } else { + // assuming that an view action is always available in the /hosting/discovery manifest + // eg. Collabora does support viewing jpgs but no editing + // eg. OnlyOffice does support viewing pdfs but no editing + // there is no known case of supporting edit only without view + q.Add("appurl", viewAppURL) + } + + if p.conf.AppIntURL != "" { + q.Add("appinturl", p.conf.AppIntURL) } + httpReq.URL.RawQuery = q.Encode() if p.conf.AppAPIKey != "" { From 17630f2ecddd2d57ff7c14612120eb83305fb7bc Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Wed, 15 Sep 2021 17:32:43 +0200 Subject: [PATCH 2/4] add changelog --- changelog/unreleased/fix-wopi-readonly-filetype.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 changelog/unreleased/fix-wopi-readonly-filetype.md diff --git a/changelog/unreleased/fix-wopi-readonly-filetype.md b/changelog/unreleased/fix-wopi-readonly-filetype.md new file mode 100644 index 0000000000..cfb46b6306 --- /dev/null +++ b/changelog/unreleased/fix-wopi-readonly-filetype.md @@ -0,0 +1,7 @@ +Bugfix: Fix opening a readonly filetype with WOPI + +This change fixes the opening of filetypes that +are only supported to be viewed and not to be edited +by some WOPI compliant office suites. + +https://github.com/cs3org/reva/pull/2073 From 997a059171173991002520675ff30f4a439bf908 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 27 Sep 2021 07:53:40 +0200 Subject: [PATCH 3/4] fix logic --- pkg/app/provider/wopi/wopi.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/app/provider/wopi/wopi.go b/pkg/app/provider/wopi/wopi.go index 350a9babd8..d084e39f4b 100644 --- a/pkg/app/provider/wopi/wopi.go +++ b/pkg/app/provider/wopi/wopi.go @@ -149,7 +149,7 @@ func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.Resourc q.Add("appviewurl", viewAppURL) } } - if editAppURLs, ok := p.appURLs["edit"]; !ok { + if editAppURLs, ok := p.appURLs["edit"]; ok { if editAppURL, ok := editAppURLs[ext]; ok { q.Add("appurl", editAppURL) } From a639a668777d3afac167947c7a993f3fdce06b25 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 27 Sep 2021 08:17:56 +0200 Subject: [PATCH 4/4] ensure that appurl is set --- pkg/app/provider/wopi/wopi.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/app/provider/wopi/wopi.go b/pkg/app/provider/wopi/wopi.go index d084e39f4b..f14cead986 100644 --- a/pkg/app/provider/wopi/wopi.go +++ b/pkg/app/provider/wopi/wopi.go @@ -153,13 +153,17 @@ func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.Resourc if editAppURL, ok := editAppURLs[ext]; ok { q.Add("appurl", editAppURL) } - } else { + } + if q.Get("appurl") == "" { // assuming that an view action is always available in the /hosting/discovery manifest // eg. Collabora does support viewing jpgs but no editing // eg. OnlyOffice does support viewing pdfs but no editing // there is no known case of supporting edit only without view q.Add("appurl", viewAppURL) } + if q.Get("appurl") == "" && q.Get("appviewurl") == "" { + return nil, errors.New("wopi: neither edit nor view app url found") + } if p.conf.AppIntURL != "" { q.Add("appinturl", p.conf.AppIntURL)