Skip to content

Handle target in OpenInApp response #4077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 3, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description: >
# _struct: Config_

{{% dir name="insecure" type="bool" default=false %}}
Whether to skip certificate checks when sending requests. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/http/services/appprovider/appprovider.go#L55)
Whether to skip certificate checks when sending requests. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/http/services/appprovider/appprovider.go#L56)
{{< highlight toml >}}
[http.services.appprovider]
insecure = false
Expand Down
49 changes: 35 additions & 14 deletions internal/http/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import (
"net/http"
"path"

apppb "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1"
appregistry "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"
storagepb "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/internal/http/services/datagateway"
"github.com/cs3org/reva/pkg/appctx"
Expand Down Expand Up @@ -158,8 +159,8 @@ func (s *svc) handleNew(w http.ResponseWriter, r *http.Request) {
return
}

statParentContainerReq := &provider.StatRequest{
Ref: &provider.Reference{
statParentContainerReq := &storagepb.StatRequest{
Ref: &storagepb.Reference{
ResourceId: parentContainerRef,
},
}
Expand All @@ -174,16 +175,16 @@ func (s *svc) handleNew(w http.ResponseWriter, r *http.Request) {
return
}

if parentContainer.Info.Type != provider.ResourceType_RESOURCE_TYPE_CONTAINER {
if parentContainer.Info.Type != storagepb.ResourceType_RESOURCE_TYPE_CONTAINER {
writeError(w, r, appErrorInvalidParameter, "the parent container id does not point to a container", nil)
return
}

fileRef := &provider.Reference{
fileRef := &storagepb.Reference{
Path: path.Join(parentContainer.Info.Path, utils.MakeRelativePath(filename)),
}

statFileReq := &provider.StatRequest{
statFileReq := &storagepb.StatRequest{
Ref: fileRef,
}
statFileRes, err := client.Stat(ctx, statFileReq)
Expand All @@ -202,7 +203,7 @@ func (s *svc) handleNew(w http.ResponseWriter, r *http.Request) {
}

// Create empty file via storageprovider
createReq := &provider.InitiateFileUploadRequest{
createReq := &storagepb.InitiateFileUploadRequest{
Ref: fileRef,
Opaque: &typespb.Opaque{
Map: map[string]*typespb.OpaqueEntry{
Expand Down Expand Up @@ -269,7 +270,7 @@ func (s *svc) handleNew(w http.ResponseWriter, r *http.Request) {
return
}

if statRes.Info.Type != provider.ResourceType_RESOURCE_TYPE_FILE {
if statRes.Info.Type != storagepb.ResourceType_RESOURCE_TYPE_FILE {
writeError(w, r, appErrorInvalidParameter, "the given file id does not point to a file", nil)
return
}
Expand Down Expand Up @@ -339,7 +340,7 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) {

fileID := r.Form.Get("file_id")

var fileRef provider.Reference
var fileRef storagepb.Reference
if fileID == "" {
path := r.Form.Get("path")
if path == "" {
Expand All @@ -356,7 +357,7 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) {
fileRef.ResourceId = resourceID
}

statRes, err := client.Stat(ctx, &provider.StatRequest{Ref: &fileRef})
statRes, err := client.Stat(ctx, &storagepb.StatRequest{Ref: &fileRef})
if err != nil {
writeError(w, r, appErrorServerError, "Internal error accessing the file, please try again later", err)
return
Expand All @@ -370,7 +371,7 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) {
return
}

if statRes.Info.Type != provider.ResourceType_RESOURCE_TYPE_FILE {
if statRes.Info.Type != storagepb.ResourceType_RESOURCE_TYPE_FILE {
writeError(w, r, appErrorInvalidParameter, "the given file id does not point to a file", nil)
return
}
Expand Down Expand Up @@ -417,7 +418,16 @@ func (s *svc) handleOpen(w http.ResponseWriter, r *http.Request) {
return
}

js, err := json.Marshal(openRes.AppUrl)
// recreate the structure to be able to marshal the AppUrl.Target as a string
js, err := json.Marshal(
map[string]interface{}{
"app_url": openRes.AppUrl.AppUrl,
"method": openRes.AppUrl.Method,
"form_parameters": openRes.AppUrl.FormParameters,
"headers": openRes.AppUrl.Headers,
"target": appTargetToString(openRes.AppUrl.Target),
},
)
if err != nil {
writeError(w, r, appErrorServerError, "Internal error with JSON payload",
errors.Wrap(err, "error marshalling JSON response"))
Expand All @@ -442,7 +452,7 @@ func (s *svc) handleNotify(w http.ResponseWriter, r *http.Request) {
}

fileID := r.Form.Get("file_id")
var fileRef provider.Reference
var fileRef storagepb.Reference
if fileID == "" {
path := r.Form.Get("path")
if path == "" {
Expand Down Expand Up @@ -488,7 +498,7 @@ func filterAppsByUserAgent(mimeTypes []*appregistry.MimeTypeInfo, userAgent stri
return res
}

func resolveViewMode(res *provider.ResourceInfo, vm string) gateway.OpenInAppRequest_ViewMode {
func resolveViewMode(res *storagepb.ResourceInfo, vm string) gateway.OpenInAppRequest_ViewMode {
var viewMode gateway.OpenInAppRequest_ViewMode
if vm != "" {
viewMode = utils.GetViewMode(vm)
Expand All @@ -512,3 +522,14 @@ func resolveViewMode(res *provider.ResourceInfo, vm string) gateway.OpenInAppReq
}
return viewMode
}

func appTargetToString(t apppb.Target) string {
switch t {
case apppb.Target_TARGET_IFRAME:
return "iframe"
case apppb.Target_TARGET_BLANK:
return "blank"
default:
return "iframe"
}
}