diff --git a/changelog/unreleased/ocm-file-downloads.md b/changelog/unreleased/ocm-file-downloads.md new file mode 100644 index 00000000000..fdacfdf3c28 --- /dev/null +++ b/changelog/unreleased/ocm-file-downloads.md @@ -0,0 +1,3 @@ +Bugfix: Skip file check for OCM data transfers + +https://github.com/cs3org/reva/pull/1636 diff --git a/internal/grpc/services/gateway/ocmshareprovider.go b/internal/grpc/services/gateway/ocmshareprovider.go index 5b91eb9f07a..1a8cb6f8c37 100644 --- a/internal/grpc/services/gateway/ocmshareprovider.go +++ b/internal/grpc/services/gateway/ocmshareprovider.go @@ -76,6 +76,27 @@ func (s *svc) RemoveOCMShare(ctx context.Context, req *ocm.RemoveOCMShareRequest }, nil } + // if we need to commit the share, we need the resource it points to. + var share *ocm.Share + if s.c.CommitShareToStorageGrant { + getShareReq := &ocm.GetOCMShareRequest{ + Ref: req.Ref, + } + getShareRes, err := c.GetOCMShare(ctx, getShareReq) + if err != nil { + return nil, errors.Wrap(err, "gateway: error calling GetShare") + } + + if getShareRes.Status.Code != rpc.Code_CODE_OK { + res := &ocm.RemoveOCMShareResponse{ + Status: status.NewInternal(ctx, status.NewErrorFromCode(getShareRes.Status.Code, "gateway"), + "error getting share when committing to the storage"), + } + return res, nil + } + share = getShareRes.Share + } + res, err := c.RemoveOCMShare(ctx, req) if err != nil { return nil, errors.Wrap(err, "gateway: error calling RemoveShare") @@ -86,24 +107,6 @@ func (s *svc) RemoveOCMShare(ctx context.Context, req *ocm.RemoveOCMShareRequest return res, nil } - // if we need to commit the share, we need the resource it points to. - getShareReq := &ocm.GetOCMShareRequest{ - Ref: req.Ref, - } - getShareRes, err := c.GetOCMShare(ctx, getShareReq) - if err != nil { - return nil, errors.Wrap(err, "gateway: error calling GetShare") - } - - if getShareRes.Status.Code != rpc.Code_CODE_OK { - res := &ocm.RemoveOCMShareResponse{ - Status: status.NewInternal(ctx, status.NewErrorFromCode(getShareRes.Status.Code, "gateway"), - "error getting share when committing to the storage"), - } - return res, nil - } - share := getShareRes.Share - // TODO(labkode): if both commits are enabled they could be done concurrently. if s.c.CommitShareToStorageGrant { removeGrantStatus, err := s.removeGrant(ctx, share.ResourceId, share.Grantee, share.Permissions.Permissions) diff --git a/internal/grpc/services/gateway/storageprovider.go b/internal/grpc/services/gateway/storageprovider.go index eba1cd14642..77b4a5adbb9 100644 --- a/internal/grpc/services/gateway/storageprovider.go +++ b/internal/grpc/services/gateway/storageprovider.go @@ -258,31 +258,30 @@ func (s *svc) InitiateFileDownload(ctx context.Context, req *provider.InitiateFi }, nil } - // if it is a file allow download - if ri.Type == provider.ResourceType_RESOURCE_TYPE_FILE { - log.Debug().Str("path", p).Interface("ri", ri).Msg("path points to share name file") - - if protocol == "webdav" { - // TODO(ishank011): pass this through the datagateway service - // for now, we just expose the file server to the user - ep, opaque, err := s.webdavRefTransferEndpoint(ctx, statRes.Info.Target) - if err != nil { - return &gateway.InitiateFileDownloadResponse{ - Status: status.NewInternal(ctx, err, "gateway: error downloading from webdav host: "+p), - }, nil - } + if protocol == "webdav" { + // TODO(ishank011): pass this through the datagateway service + // for now, we just expose the file server to the user + ep, opaque, err := s.webdavRefTransferEndpoint(ctx, statRes.Info.Target) + if err != nil { return &gateway.InitiateFileDownloadResponse{ - Status: status.NewOK(ctx), - Protocols: []*gateway.FileDownloadProtocol{ - { - Opaque: opaque, - Protocol: "simple", - DownloadEndpoint: ep, - }, - }, + Status: status.NewInternal(ctx, err, "gateway: error downloading from webdav host: "+p), }, nil } + return &gateway.InitiateFileDownloadResponse{ + Status: status.NewOK(ctx), + Protocols: []*gateway.FileDownloadProtocol{ + { + Opaque: opaque, + Protocol: "simple", + DownloadEndpoint: ep, + }, + }, + }, nil + } + // if it is a file allow download + if ri.Type == provider.ResourceType_RESOURCE_TYPE_FILE { + log.Debug().Str("path", p).Interface("ri", ri).Msg("path points to share name file") req.Ref = &provider.Reference{ Spec: &provider.Reference_Path{ Path: ri.Path, @@ -290,8 +289,8 @@ func (s *svc) InitiateFileDownload(ctx context.Context, req *provider.InitiateFi } log.Debug().Msg("download path: " + ri.Path) return s.initiateFileDownload(ctx, req) - } + log.Debug().Str("path", p).Interface("statRes", statRes).Msg("path:%s points to share name") err = errtypes.PermissionDenied("gateway: cannot download share name: path=" + p) log.Err(err).Str("path", p).Msg("gateway: error downloading") @@ -471,31 +470,30 @@ func (s *svc) InitiateFileUpload(ctx context.Context, req *provider.InitiateFile }, nil } - // if it is a file allow upload - if ri.Type == provider.ResourceType_RESOURCE_TYPE_FILE { - log.Debug().Str("path", p).Interface("ri", ri).Msg("path points to share name file") - - if protocol == "webdav" { - // TODO(ishank011): pass this through the datagateway service - // for now, we just expose the file server to the user - ep, opaque, err := s.webdavRefTransferEndpoint(ctx, statRes.Info.Target) - if err != nil { - return &gateway.InitiateFileUploadResponse{ - Status: status.NewInternal(ctx, err, "gateway: error downloading from webdav host: "+p), - }, nil - } + if protocol == "webdav" { + // TODO(ishank011): pass this through the datagateway service + // for now, we just expose the file server to the user + ep, opaque, err := s.webdavRefTransferEndpoint(ctx, statRes.Info.Target) + if err != nil { return &gateway.InitiateFileUploadResponse{ - Status: status.NewOK(ctx), - Protocols: []*gateway.FileUploadProtocol{ - { - Opaque: opaque, - Protocol: "simple", - UploadEndpoint: ep, - }, - }, + Status: status.NewInternal(ctx, err, "gateway: error downloading from webdav host: "+p), }, nil } + return &gateway.InitiateFileUploadResponse{ + Status: status.NewOK(ctx), + Protocols: []*gateway.FileUploadProtocol{ + { + Opaque: opaque, + Protocol: "simple", + UploadEndpoint: ep, + }, + }, + }, nil + } + // if it is a file allow upload + if ri.Type == provider.ResourceType_RESOURCE_TYPE_FILE { + log.Debug().Str("path", p).Interface("ri", ri).Msg("path points to share name file") req.Ref = &provider.Reference{ Spec: &provider.Reference_Path{ Path: ri.Path, @@ -503,8 +501,8 @@ func (s *svc) InitiateFileUpload(ctx context.Context, req *provider.InitiateFile } log.Debug().Msg("upload path: " + ri.Path) return s.initiateFileUpload(ctx, req) - } + err = errtypes.PermissionDenied("gateway: cannot upload to share name: path=" + p) log.Err(err).Msg("gateway: error uploading") return &gateway.InitiateFileUploadResponse{