Skip to content

Commit

Permalink
up and download of file shares (#1170)
Browse files Browse the repository at this point in the history
  • Loading branch information
butonic authored Sep 29, 2020
1 parent d4db27f commit fd6f0d3
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 39 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/file-share-up-download.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: up and download of file shares

The shared folder logic in the gateway storageprovider was not allowing file up and downloads for single file shares. We now check if the reference is actually a file to determine if up / download should be allowed.

https://github.com/cs3org/reva/pull/1170
173 changes: 165 additions & 8 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,93 @@ func (s *svc) InitiateFileDownload(ctx context.Context, req *provider.InitiateFi
return s.initiateFileDownload(ctx, req)
}

if s.isSharedFolder(ctx, p) || s.isShareName(ctx, p) {
log.Debug().Msgf("path:%s points to shared folder or share name", p)
err := errtypes.PermissionDenied("gateway: cannot download share folder or share name: path=" + p)
if s.isSharedFolder(ctx, p) {
log.Debug().Msgf("path:%s points to shared folder", p)
err := errtypes.PermissionDenied("gateway: cannot download share folder: path=" + p)
log.Err(err).Msg("gateway: error downloading")
return &gateway.InitiateFileDownloadResponse{
Status: status.NewInvalidArg(ctx, "path points to share folder or share name"),
Status: status.NewInvalidArg(ctx, "path points to share folder"),
}, nil

}

if s.isShareName(ctx, p) {
statReq := &provider.StatRequest{Ref: req.Ref}
statRes, err := s.stat(ctx, statReq)
if err != nil {
return &gateway.InitiateFileDownloadResponse{
Status: status.NewInternal(ctx, err, "gateway: error stating ref:"+statReq.Ref.String()),
}, nil
}
if statRes.Status.Code != rpc.Code_CODE_OK {
if statRes.Status.Code == rpc.Code_CODE_NOT_FOUND {
return &gateway.InitiateFileDownloadResponse{
Status: status.NewNotFound(ctx, "gateway: file not found:"+statReq.Ref.String()),
}, nil
}
err := status.NewErrorFromCode(statRes.Status.Code, "gateway")
return &gateway.InitiateFileDownloadResponse{
Status: status.NewInternal(ctx, err, "gateway: error stating ref:"+statReq.Ref.String()),
}, nil
}

if statRes.Info.Type != provider.ResourceType_RESOURCE_TYPE_REFERENCE {
err := errors.New(fmt.Sprintf("gateway: expected reference: got:%+v", statRes.Info))
log.Err(err).Msg("gateway: error stating share name")
return &gateway.InitiateFileDownloadResponse{
Status: status.NewInternal(ctx, err, "gateway: error initiating download"),
}, nil
}

ri, protocol, err := s.checkRef(ctx, statRes.Info)
if err != nil {
if _, ok := err.(errtypes.IsNotFound); ok {
return &gateway.InitiateFileDownloadResponse{
Status: status.NewNotFound(ctx, "gateway: reference not found:"+statRes.Info.Target),
}, nil
}
log.Err(err).Msg("gateway: error resolving reference")
return &gateway.InitiateFileDownloadResponse{
Status: status.NewInternal(ctx, err, "error initiating download"),
}, 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
}
return &gateway.InitiateFileDownloadResponse{
Opaque: opaque,
Status: status.NewOK(ctx),
DownloadEndpoint: ep,
}, nil
}

req.Ref = &provider.Reference{
Spec: &provider.Reference_Path{
Path: ri.Path,
},
}
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")
return &gateway.InitiateFileDownloadResponse{
Status: status.NewInvalidArg(ctx, "path points to share name"),
}, nil
}

if s.isShareChild(ctx, p) {
log.Debug().Msgf("shared child: %s", p)
shareName, shareChild := s.splitShare(ctx, p)
Expand Down Expand Up @@ -300,12 +377,92 @@ func (s *svc) InitiateFileUpload(ctx context.Context, req *provider.InitiateFile
return s.initiateFileUpload(ctx, req)
}

if s.isSharedFolder(ctx, p) || s.isShareName(ctx, p) {
log.Debug().Msgf("path:%s points to shared folder or share name", p)
err := errtypes.PermissionDenied("gateway: cannot upload to share folder or share name: path=" + p)
if s.isSharedFolder(ctx, p) {
log.Debug().Str("path", p).Msg("path points to shared folder")
err := errtypes.PermissionDenied("gateway: cannot upload to share folder: path=" + p)
log.Err(err).Msg("gateway: error downloading")
return &gateway.InitiateFileUploadResponse{
Status: status.NewInvalidArg(ctx, "path points to share folder or share name"),
Status: status.NewInvalidArg(ctx, "path points to share folder"),
}, nil

}

if s.isShareName(ctx, p) {
log.Debug().Str("path", p).Msg("path points to share name")
statReq := &provider.StatRequest{Ref: req.Ref}
statRes, err := s.stat(ctx, statReq)
if err != nil {
return &gateway.InitiateFileUploadResponse{
Status: status.NewInternal(ctx, err, "gateway: error stating ref:"+statReq.Ref.String()),
}, nil
}
if statRes.Status.Code != rpc.Code_CODE_OK {
if statRes.Status.Code == rpc.Code_CODE_NOT_FOUND {
err = errtypes.PermissionDenied("gateway: cannot upload to share name: path=" + p)
log.Err(err).Msg("gateway: error uploading")
return &gateway.InitiateFileUploadResponse{
Status: status.NewInvalidArg(ctx, "path points to non existing share name"),
}, nil
}
err := status.NewErrorFromCode(statRes.Status.Code, "gateway")
return &gateway.InitiateFileUploadResponse{
Status: status.NewInternal(ctx, err, "gateway: error stating ref:"+statReq.Ref.String()),
}, nil
}

if statRes.Info.Type != provider.ResourceType_RESOURCE_TYPE_REFERENCE {
err := errors.New(fmt.Sprintf("gateway: expected reference: got:%+v", statRes.Info))
log.Err(err).Msg("gateway: error stating share name")
return &gateway.InitiateFileUploadResponse{
Status: status.NewInternal(ctx, err, "gateway: error initiating upload"),
}, nil
}

ri, protocol, err := s.checkRef(ctx, statRes.Info)
if err != nil {
if _, ok := err.(errtypes.IsNotFound); ok {
return &gateway.InitiateFileUploadResponse{
Status: status.NewNotFound(ctx, "gateway: reference not found:"+statRes.Info.Target),
}, nil
}
log.Err(err).Msg("gateway: error resolving reference")
return &gateway.InitiateFileUploadResponse{
Status: status.NewInternal(ctx, err, "error initiating upload"),
}, 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
}
return &gateway.InitiateFileUploadResponse{
Opaque: opaque,
Status: status.NewOK(ctx),
UploadEndpoint: ep,
}, nil
}

req.Ref = &provider.Reference{
Spec: &provider.Reference_Path{
Path: ri.Path,
},
}
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{
Status: status.NewInvalidArg(ctx, "path points to share name"),
}, nil

}
Expand Down
39 changes: 26 additions & 13 deletions pkg/storage/fs/owncloud/owncloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ func (fs *ocfs) wrap(ctx context.Context, fn string) (internal string) {
// parts[0] contains the username or userid.
u, err := fs.getUser(ctx, parts[0])
if err != nil {
logger.New().Error().Err(err).
Msg("could not get user")
// TODO return invalid internal path?
return
}
Expand Down Expand Up @@ -284,8 +282,6 @@ func (fs *ocfs) wrapShadow(ctx context.Context, fn string) (internal string) {
// parts[0] contains the username or userid.
u, err := fs.getUser(ctx, parts[0])
if err != nil {
logger.New().Error().Err(err).
Msg("could not get user")
// TODO return invalid internal path?
return
}
Expand Down Expand Up @@ -319,8 +315,6 @@ func (fs *ocfs) getVersionsPath(ctx context.Context, np string) string {
// parts[1] contains the username or userid.
u, err := fs.getUser(ctx, parts[1])
if err != nil {
logger.New().Error().Err(err).
Msg("could not get user")
// TODO return invalid internal path?
return ""
}
Expand Down Expand Up @@ -392,8 +386,7 @@ func (fs *ocfs) unwrap(ctx context.Context, internal string) (external string) {
external = path.Join("/", parts[1], parts[3])
}
}
log := appctx.GetLogger(ctx)
log.Debug().Msgf("ocfs: unwrap: internal=%s external=%s", internal, external)
appctx.GetLogger(ctx).Debug().Str("internal", internal).Str("external", external).Msg("ocfs: unwrap")
return
}

Expand Down Expand Up @@ -425,8 +418,7 @@ func (fs *ocfs) unwrapShadow(ctx context.Context, internal string) (external str
external = path.Join("/", parts[1], parts[3])
}
}
log := appctx.GetLogger(ctx)
log.Debug().Msgf("ocfs: unwrapShadow: internal=%s external=%s", internal, external)
appctx.GetLogger(ctx).Debug().Str("internal", internal).Str("external", external).Msg("ocfs: unwrapShadow")
return
}

Expand All @@ -440,6 +432,7 @@ func (fs *ocfs) getOwner(internal string) string {
return ""
}

// TODO cache user lookup
func (fs *ocfs) getUser(ctx context.Context, usernameOrID string) (id *userpb.User, err error) {
u := user.ContextMustGetUser(ctx)
// check if username matches and id is set
Expand All @@ -455,22 +448,42 @@ func (fs *ocfs) getUser(ctx context.Context, usernameOrID string) (id *userpb.Us
// parts[0] contains the username or userid. use user service to look up id
c, err := pool.GetUserProviderServiceClient(fs.c.UserProviderEndpoint)
if err != nil {
appctx.GetLogger(ctx).
Error().Err(err).
Str("userprovidersvc", fs.c.UserProviderEndpoint).
Str("usernameOrID", usernameOrID).
Msg("could not get user provider client")
return nil, err
}
res, err := c.GetUser(ctx, &userpb.GetUserRequest{
UserId: &userpb.UserId{OpaqueId: usernameOrID},
})
if err != nil {
appctx.GetLogger(ctx).
Error().Err(err).
Str("userprovidersvc", fs.c.UserProviderEndpoint).
Str("usernameOrID", usernameOrID).
Msg("could not get user")
return nil, err
}

if res.Status.Code == rpc.Code_CODE_NOT_FOUND {
logger.New().Error().Str("code", string(res.Status.Code)).Msg("user not found")
appctx.GetLogger(ctx).
Error().
Str("userprovidersvc", fs.c.UserProviderEndpoint).
Str("usernameOrID", usernameOrID).
Interface("status", res.Status).
Msg("user not found")
return nil, fmt.Errorf("user not found")
}

if res.Status.Code != rpc.Code_CODE_OK {
logger.New().Error().Str("code", string(res.Status.Code)).Msg("user lookup failed")
appctx.GetLogger(ctx).
Error().
Str("userprovidersvc", fs.c.UserProviderEndpoint).
Str("usernameOrID", usernameOrID).
Interface("status", res.Status).
Msg("user lookup failed")
return nil, fmt.Errorf("user lookup failed")
}
return res.User, nil
Expand Down Expand Up @@ -541,7 +554,7 @@ func (fs *ocfs) convertToResourceInfo(ctx context.Context, fi os.FileInfo, np st
} else {
appctx.GetLogger(ctx).Error().Err(err).
Str("entry", entry).
Msgf("error retrieving xattr metadata")
Msg("error retrieving xattr metadata")
}
}
} else {
Expand Down
16 changes: 0 additions & 16 deletions tests/acceptance/expected-failures-on-OC-storage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,6 @@ apiShareManagement/acceptShares.feature:582
apiShareManagement/acceptShares.feature:652
apiShareManagement/acceptShares.feature:696
#
# https://github.com/owncloud/product/issues/208 After accepting a share data in the received file cannot be downloaded
apiShareManagement/acceptSharesToSharesFolder.feature:15
apiShareManagement/acceptSharesToSharesFolder.feature:22
#
# https://github.com/owncloud/product/issues/207 Response is empty when accepting a share
apiShareManagement/acceptSharesToSharesFolder.feature:30
apiShareManagement/acceptSharesToSharesFolder.feature:52
Expand Down Expand Up @@ -266,12 +262,6 @@ apiShareToSharesManagementBasic/excludeGroupFromReceivingSharesToSharesFolder.fe
apiShareToSharesManagementBasic/excludeGroupFromReceivingSharesToSharesFolder.feature:135
apiShareToSharesManagementBasic/excludeGroupFromReceivingSharesToSharesFolder.feature:136
#
# These currently pass in owncloud/ocis-reva and fail in cs3org/reva
apiShareToSharesManagementBasic/excludeGroupFromReceivingSharesToSharesFolder.feature:115
apiShareToSharesManagementBasic/excludeGroupFromReceivingSharesToSharesFolder.feature:116
apiShareToSharesManagementBasic/excludeGroupFromReceivingSharesToSharesFolder.feature:153
apiShareToSharesManagementBasic/excludeGroupFromReceivingSharesToSharesFolder.feature:154
#
# https://github.com/owncloud/ocis-reva/issues/260 Sharee retrieves the information about a share -but gets response containing all the shares
apiShareOperations/accessToShare.feature:48
apiShareOperations/accessToShare.feature:49
Expand Down Expand Up @@ -670,14 +660,8 @@ apiShareReshareToShares2/reShareWhenShareWithOnlyMembershipGroups.feature:41
apiShareReshareToShares2/reShareWhenShareWithOnlyMembershipGroups.feature:42
apiShareReshareToShares3/reShareUpdate.feature:25
apiShareReshareToShares3/reShareUpdate.feature:26
apiShareReshareToShares3/reShareUpdate.feature:42
apiShareReshareToShares3/reShareUpdate.feature:43
apiShareReshareToShares3/reShareUpdate.feature:59
apiShareReshareToShares3/reShareUpdate.feature:60
apiShareReshareToShares3/reShareUpdate.feature:76
apiShareReshareToShares3/reShareUpdate.feature:77
apiShareReshareToShares3/reShareUpdate.feature:93
apiShareReshareToShares3/reShareUpdate.feature:94
apiShareReshareToShares3/reShareUpdate.feature:112
apiShareReshareToShares3/reShareUpdate.feature:113
apiShareReshareToShares3/reShareUpdate.feature:131
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ Feature: previews of files downloaded through the webdav API
Then the HTTP status code should be "200"
And the downloaded image should be "1240" pixels wide and "648" pixels high

@issue-ocis-thumbnails-191 @skipOnOcis-EOS-Storage @issue-ocis-reva-308 @skipOnOcis-OCIS-Storage
@issue-ocis-191 @skipOnOcis-EOS-Storage @issue-ocis-reva-308 @skipOnOcis-OCIS-Storage
# after fixing all issues delete this Scenario and use the one from oC10 core
Scenario: download previews of other users files
Given user "Brian" has been created with default attributes and without skeleton files
And user "Alice" has uploaded file "filesForUpload/lorem.txt" to "/parent.txt"
When user "Brian" downloads the preview of "/parent.txt" of "Alice" with width "32" and height "32" using the WebDAV API
Then the HTTP status code should be "500"
Then the HTTP status code should be "200"

@issue-ocis-190
# after fixing all issues delete this Scenario and use the one from oC10 core
Expand Down
2 changes: 2 additions & 0 deletions tests/oc-integration-tests/drone/gateway.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ ocminvitemanagersvc = "localhost:13000"
ocmproviderauthorizersvc = "localhost:13000"
# other
commit_share_to_storage_grant = true
commit_share_to_storage_ref = true
share_folder = "Shares"
datagateway = "http://localhost:19001/data"
transfer_shared_secret = "replace-me-with-a-transfer-secret" # for direct uploads
transfer_expires = 6 # give it a moment
Expand Down
2 changes: 2 additions & 0 deletions tests/oc-integration-tests/drone/storage-home-owncloud.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ enable_home_creation = true
datadirectory = "/drone/src/tmp/reva/data"
enable_home = true
redis = "redis:6379"
userprovidersvc = "localhost:18000"


[http]
Expand All @@ -46,3 +47,4 @@ temp_folder = "/drone/src/tmp/reva/tmp"
datadirectory = "/drone/src/tmp/reva/data"
enable_home = true
redis = "redis:6379"
userprovidersvc = "localhost:18000"
1 change: 1 addition & 0 deletions tests/oc-integration-tests/drone/storage-oc-owncloud.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ temp_folder = "/drone/src/tmp/reva/tmp"
[http.services.dataprovider.drivers.owncloud]
datadirectory = "/drone/src/tmp/reva/data"
redis = "redis:6379"
userprovidersvc = "localhost:18000"
Loading

0 comments on commit fd6f0d3

Please sign in to comment.