cs3org / reva

WebDAV/gRPC/HTTP high performance server to link high level clients to storage backends
https://reva.link
Apache License 2.0
167 stars 113 forks source link

Make relative reference parameters in appprovider consistent with other services #2347

Open ishank011 opened 2 years ago

ishank011 commented 2 years ago

https://github.com/cs3org/reva/pull/2210#discussion_r765556535

wkloucek commented 2 years ago

The below diff would change the behavior with the restriction of not using relative CS3api references. I would opt for waiting until all storage provider support relative references, then this will be cleaner and easier, since we can just pass both parameters into the relative CS3api reference.

diff --git a/internal/http/services/appprovider/appprovider.go b/internal/http/services/appprovider/appprovider.go
index ed101a0f..57c2e387 100644
--- a/internal/http/services/appprovider/appprovider.go
+++ b/internal/http/services/appprovider/appprovider.go
@@ -154,11 +154,7 @@ func (s *svc) handleNew(w http.ResponseWriter, r *http.Request) {
                return
        }

-       dirPart, filePart := path.Split(filename)
-       if dirPart != "" || filePart != filename {
-               writeError(w, r, appErrorInvalidParameter, "the filename must not contain a path segment", nil)
-               return
-       }
+       relativePath, filename := path.Split(filename)

        statParentContainerReq := &provider.StatRequest{
                Ref: &provider.Reference{
@@ -176,13 +172,29 @@ func (s *svc) handleNew(w http.ResponseWriter, r *http.Request) {
                return
        }

-       if parentContainer.Info.Type != provider.ResourceType_RESOURCE_TYPE_CONTAINER {
-               writeError(w, r, appErrorInvalidParameter, "the parent container id does not point to a container", nil)
+       statRelativeParentContainerReq := &provider.StatRequest{
+               Ref: &provider.Reference{
+                       Path: path.Join(parentContainer.Info.Path, utils.MakeRelativePath(relativePath)),
+               },
+       }
+       relativeParentContainer, err := client.Stat(ctx, statRelativeParentContainerReq)
+       if err != nil {
+               writeError(w, r, appErrorServerError, "error sending a grpc stat request", err)
+               return
+       }
+
+       if relativeParentContainer.Status.Code != rpc.Code_CODE_OK {
+               writeError(w, r, appErrorNotFound, "the path relative to the parent container is not accessible or does not exist", err)
+               return
+       }
+
+       if relativeParentContainer.Info.Type != provider.ResourceType_RESOURCE_TYPE_CONTAINER {
+               writeError(w, r, appErrorInvalidParameter, "the path relative to the parent container id does not point to a container", nil)
                return
        }

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

        statFileReq := &provider.StatRequest{