Skip to content

Commit

Permalink
appprovider: pass any other query parameters in /app/open as Opaque t…
Browse files Browse the repository at this point in the history
…o OpenInApp
  • Loading branch information
glpatcern authored and gmgigi96 committed Nov 30, 2022
1 parent 7c29bd4 commit d549d84
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 13 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/apps-opaque.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: appproviders: pass other query parameters as Opaque

This allows to send any other HTTP query parameter passed to /app/open
to the underlying appprovider drivers via GRPC

https://github.com/cs3org/reva/pull/3502
2 changes: 1 addition & 1 deletion internal/grpc/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func getProvider(c *config) (app.Provider, error) {
}

func (s *service) OpenInApp(ctx context.Context, req *providerpb.OpenInAppRequest) (*providerpb.OpenInAppResponse, error) {
appURL, err := s.provider.GetAppURL(ctx, req.ResourceInfo, req.ViewMode, req.AccessToken, s.conf.Language)
appURL, err := s.provider.GetAppURL(ctx, req.ResourceInfo, req.ViewMode, req.AccessToken, req.Opaque.Map, s.conf.Language)
if err != nil {
res := &providerpb.OpenInAppResponse{
Status: status.NewInternal(ctx, errors.New("appprovider: error calling GetAppURL"), err.Error()),
Expand Down
19 changes: 10 additions & 9 deletions internal/grpc/services/gateway/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (s *svc) OpenInApp(ctx context.Context, req *gateway.OpenInAppRequest) (*pr
}
if uri.Scheme == "webdav" {
insecure, skipVerify := getGRPCConfig(req.Opaque)
return s.openFederatedShares(ctx, fileInfo.Target, req.ViewMode, req.App, insecure, skipVerify, resChild)
return s.openFederatedShares(ctx, fileInfo.Target, req, insecure, skipVerify, resChild)
}

res, err := s.Stat(ctx, &storageprovider.StatRequest{
Expand All @@ -114,10 +114,10 @@ func (s *svc) OpenInApp(ctx context.Context, req *gateway.OpenInAppRequest) (*pr
}
fileInfo = res.Info
}
return s.openLocalResources(ctx, fileInfo, req.ViewMode, req.App)
return s.openLocalResources(ctx, fileInfo, req)
}

func (s *svc) openFederatedShares(ctx context.Context, targetURL string, vm gateway.OpenInAppRequest_ViewMode, app string,
func (s *svc) openFederatedShares(ctx context.Context, targetURL string, req *gateway.OpenInAppRequest,
insecure, skipVerify bool, nameQueries ...string) (*providerpb.OpenInAppResponse, error) {
log := appctx.GetLogger(ctx)
targetURL, err := appendNameQuery(targetURL, nameQueries...)
Expand All @@ -132,8 +132,9 @@ func (s *svc) openFederatedShares(ctx context.Context, targetURL string, vm gate
ref := &storageprovider.Reference{Path: ep.filePath}
appProviderReq := &gateway.OpenInAppRequest{
Ref: ref,
ViewMode: vm,
App: app,
ViewMode: req.ViewMode,
App: req.App,
Opaque: req.Opaque,
}

meshProvider, err := s.GetInfoByDomain(ctx, &ocmprovider.GetInfoByDomainRequest{
Expand Down Expand Up @@ -168,16 +169,15 @@ func (s *svc) openFederatedShares(ctx context.Context, targetURL string, vm gate
return res, nil
}

func (s *svc) openLocalResources(ctx context.Context, ri *storageprovider.ResourceInfo,
vm gateway.OpenInAppRequest_ViewMode, app string) (*providerpb.OpenInAppResponse, error) {
func (s *svc) openLocalResources(ctx context.Context, ri *storageprovider.ResourceInfo, req *gateway.OpenInAppRequest) (*providerpb.OpenInAppResponse, error) {
accessToken, ok := ctxpkg.ContextGetToken(ctx)
if !ok || accessToken == "" {
return &providerpb.OpenInAppResponse{
Status: status.NewUnauthenticated(ctx, errtypes.InvalidCredentials("Access token is invalid or empty"), ""),
}, nil
}

provider, err := s.findAppProvider(ctx, ri, app)
provider, err := s.findAppProvider(ctx, ri, req.App)
if err != nil {
err = errors.Wrap(err, "gateway: error calling findAppProvider")
if _, ok := err.(errtypes.IsNotFound); ok {
Expand All @@ -195,8 +195,9 @@ func (s *svc) openLocalResources(ctx context.Context, ri *storageprovider.Resour

appProviderReq := &providerpb.OpenInAppRequest{
ResourceInfo: ri,
ViewMode: providerpb.OpenInAppRequest_ViewMode(vm),
ViewMode: providerpb.OpenInAppRequest_ViewMode(req.ViewMode),
AccessToken: accessToken,
Opaque: req.Opaque,
}

res, err := appProviderClient.OpenInApp(ctx, appProviderReq)
Expand Down
11 changes: 11 additions & 0 deletions internal/http/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,21 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) {
return
}

opaqueMap := make(map[string]*typespb.OpaqueEntry)
for k, v := range r.Form {
if k != "file_id" && k != "view_mode" && k != "app_name" {
opaqueMap[k] = &typespb.OpaqueEntry{
Decoder: "plain",
Value: []byte(v[0]),
}
}
}

openReq := gateway.OpenInAppRequest{
Ref: fileRef,
ViewMode: viewMode,
App: r.Form.Get("app_name"),
Opaque: &typespb.Opaque{Map: opaqueMap},
}
openRes, err := client.OpenInApp(ctx, &openReq)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
appprovider "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1"
registry "github.com/cs3org/go-cs3apis/cs3/app/registry/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
)

// Registry is the interface that application registries implement
Expand All @@ -40,6 +41,6 @@ type Registry interface {
// Provider is the interface that application providers implement
// for interacting with external apps that serve the requested resource.
type Provider interface {
GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token, language string) (*appprovider.OpenInAppURL, error)
GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token string, opaqueMap map[string]*typespb.OpaqueEntry, language string) (*appprovider.OpenInAppURL, error)
GetAppProviderInfo(ctx context.Context) (*registry.ProviderInfo, error)
}
3 changes: 2 additions & 1 deletion pkg/app/provider/demo/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
appprovider "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1"
appregistry "github.com/cs3org/go-cs3apis/cs3/app/registry/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/pkg/app"
"github.com/cs3org/reva/pkg/app/provider/registry"
"github.com/mitchellh/mapstructure"
Expand All @@ -39,7 +40,7 @@ type demoProvider struct {
iframeUIProvider string
}

func (p *demoProvider) GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token, language string) (*appprovider.OpenInAppURL, error) {
func (p *demoProvider) GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token string, opaqueMap map[string]*typespb.OpaqueEntry, language string) (*appprovider.OpenInAppURL, error) {
url := fmt.Sprintf("<iframe src=%s/open/%s?view-mode=%s&access-token=%s&lang=%s />", p.iframeUIProvider, resource.Id.StorageId+":"+resource.Id.OpaqueId, viewMode.String(), token, language)
return &appprovider.OpenInAppURL{
AppUrl: url,
Expand Down
8 changes: 7 additions & 1 deletion pkg/app/provider/wopi/wopi.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
appregistry "github.com/cs3org/go-cs3apis/cs3/app/registry/v1beta1"
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/pkg/app"
"github.com/cs3org/reva/pkg/app/provider/registry"
"github.com/cs3org/reva/pkg/appctx"
Expand Down Expand Up @@ -118,7 +119,7 @@ func New(m map[string]interface{}) (app.Provider, error) {
}, nil
}

func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token, language string) (*appprovider.OpenInAppURL, error) {
func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token string, opaqueMap map[string]*typespb.OpaqueEntry, language string) (*appprovider.OpenInAppURL, error) {
log := appctx.GetLogger(ctx)

ext := path.Ext(resource.Path)
Expand Down Expand Up @@ -187,6 +188,11 @@ func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.Resourc
q.Add("appinturl", p.conf.AppIntURL)
}

if _, ok := opaqueMap["forcelock"]; ok {
// this is to work around an issue with Microsoft Office, cf. cs3org/wopiserver#106
q.Add("forcelock", "1")
}

httpReq.URL.RawQuery = q.Encode()

if p.conf.AppAPIKey != "" {
Expand Down

0 comments on commit d549d84

Please sign in to comment.