Skip to content

Commit

Permalink
Further fixes following tests
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Aug 3, 2020
1 parent 38161bb commit f2cd667
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
8 changes: 4 additions & 4 deletions cmd/reva/open-file-in-app-provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ func openFileInAppProviderCommand() *command {
cmd := newCommand("open-file-in-app-provider")
cmd.Description = func() string { return "Open a file in an external app provider" }
cmd.Usage = func() string {
return "Usage: open-file-in-app-provider [-flags] <path> <viewMode (view, read, write)>"
return "Usage: open-file-in-app-provider [-flags] [-viewmode view|read|write] <path>"
}
viewMode := cmd.String("viewMode", "view", "the view permissions, defaults to view")
viewMode := cmd.String("viewmode", "view", "the view permissions, defaults to view")

cmd.Action = func() error {
ctx := getAuthContext()
Expand All @@ -43,7 +43,7 @@ func openFileInAppProviderCommand() *command {
}
path := cmd.Args()[0]

viewMode := getViewMode(*viewMode)
vm := getViewMode(*viewMode)

client, err := getClient()
if err != nil {
Expand All @@ -54,7 +54,7 @@ func openFileInAppProviderCommand() *command {
Spec: &provider.Reference_Path{Path: path},
}

openRequest := &gateway.OpenFileInAppProviderRequest{Ref: ref, ViewMode: viewMode}
openRequest := &gateway.OpenFileInAppProviderRequest{Ref: ref, ViewMode: vm}

openRes, err := client.OpenFileInAppProvider(ctx, openRequest)
if err != nil {
Expand Down
20 changes: 8 additions & 12 deletions internal/grpc/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,13 @@ func (s *service) OpenFileInAppProvider(ctx context.Context, req *providerpb.Ope
}
appsRes, err := httpClient.Do(appsReq)
if err != nil {
log.Error().Err(err).Msg("error performing http request")
res := &providerpb.OpenFileInAppProviderResponse{
Status: status.NewInternal(ctx, err, "error performing http request"),
}
return res, nil
}
defer appsRes.Body.Close()
if appsRes.StatusCode != http.StatusOK {
log.Error().Err(err).Msg("error performing http request")
res := &providerpb.OpenFileInAppProviderResponse{
Status: status.NewInternal(ctx, err, "error performing http request, status code: "+strconv.Itoa(appsRes.StatusCode)),
}
Expand Down Expand Up @@ -195,6 +193,7 @@ func (s *service) OpenFileInAppProvider(ctx context.Context, req *providerpb.Ope

openResBody := buf.String()

// TODO this could be done once every ~week, no need to do it at every request
appsBodyMap := make(map[string]interface{})
err2 := json.Unmarshal(appsBody, &appsBodyMap)
if err2 != nil {
Expand All @@ -207,30 +206,27 @@ func (s *service) OpenFileInAppProvider(ctx context.Context, req *providerpb.Ope

viewOptionsMap, ok := viewOptions.(map[string]interface{})
if !ok {
log.Error().Msg("error typecasting to map")
res := &providerpb.OpenFileInAppProviderResponse{
Status: status.NewInternal(ctx, nil, "error typecasting to map"),
Status: status.NewInvalid(ctx, "Incorrect parsing of the App URLs map from the WOPI server"),
}
return res, nil
}

var viewmode string

if req.ViewMode == providerpb.OpenFileInAppProviderRequest_VIEW_MODE_READ_WRITE {
viewmode = "edit"
} else {
viewmode = "view"
}

providerURL := fmt.Sprintf("%v", viewOptionsMap[viewmode])

if strings.Contains(providerURL, "?") {
providerURL += "&"
appProviderURL := fmt.Sprintf("%v", viewOptionsMap[viewmode])
if strings.Contains(appProviderURL, "?") {
appProviderURL += "&"
} else {
providerURL += "?"
appProviderURL += "?"
}

appProviderURL := fmt.Sprintf("%sWOPISrc=%s\n", providerURL, openResBody)
appProviderURL = fmt.Sprintf("%sWOPISrc=%s", appProviderURL, openResBody)
log.Info().Msg(fmt.Sprintf("Returning app provider URL %s", appProviderURL))

return &providerpb.OpenFileInAppProviderResponse{
Status: status.NewOK(ctx),
Expand Down
6 changes: 6 additions & 0 deletions internal/grpc/services/gateway/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ package gateway

import (
"context"
"fmt"

providerpb "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1"
registry "github.com/cs3org/go-cs3apis/cs3/app/registry/v1beta1"
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/rgrpc/status"
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
Expand Down Expand Up @@ -96,6 +98,10 @@ func (s *svc) OpenFileInAppProvider(ctx context.Context, req *gateway.OpenFileIn
}

// build the appProvider specific request with the required extra info that has been obtained

log := appctx.GetLogger(ctx)
log.Debug().Msg(fmt.Sprintf("request: %s", req))

appProviderReq := &providerpb.OpenFileInAppProviderRequest{
ResourceInfo: fileInfo,
ViewMode: providerpb.OpenFileInAppProviderRequest_ViewMode(req.ViewMode),
Expand Down

0 comments on commit f2cd667

Please sign in to comment.