Skip to content

Commit

Permalink
remove share reference when declining a share
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christofas committed Sep 7, 2021
1 parent f004c26 commit 98875bc
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 14 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/remove-share-reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: remove share references when declining shares

Implemented the removal of share references when a share gets declined.
Now when a user declines a share it will no longer be listed in their `Shares` directory.

https://github.com/cs3org/reva/pull/1991
11 changes: 7 additions & 4 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -924,13 +924,16 @@ func (s *svc) Delete(ctx context.Context, req *provider.DeleteRequest) (*provide
if err != nil {
return nil, err
}

return &provider.DeleteResponse{
Status: status.NewOK(ctx),
}, nil
}
}

ref := &provider.Reference{Path: p}

req.Ref = ref
return s.delete(ctx, req)
return &provider.DeleteResponse{
Status: status.NewNotFound(ctx, "could not find share"),
}, nil
}

if s.isShareChild(ctx, p) {
Expand Down
69 changes: 68 additions & 1 deletion internal/grpc/services/gateway/usershareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/rgrpc/status"
Expand Down Expand Up @@ -127,6 +128,8 @@ func (s *svc) RemoveShare(ctx context.Context, req *collaboration.RemoveShareReq
return nil, errors.Wrap(err, "gateway: error calling RemoveShare")
}

s.removeReference(ctx, share.ResourceId)

// if we don't need to commit we return earlier
if !s.c.CommitShareToStorageGrant && !s.c.CommitShareToStorageRef {
return res, nil
Expand Down Expand Up @@ -324,7 +327,7 @@ func (s *svc) UpdateReceivedShare(ctx context.Context, req *collaboration.Update
}
return rsp, nil
} else if req.Field.GetState() == collaboration.ShareState_SHARE_STATE_REJECTED {
// Nothing more to do, return the original result
s.removeReference(ctx, res.Share.Share.ResourceId)
return res, nil
}
}
Expand All @@ -336,6 +339,70 @@ func (s *svc) UpdateReceivedShare(ctx context.Context, req *collaboration.Update
}, nil
}

func (s *svc) removeReference(ctx context.Context, resourceID *provider.ResourceId) *rpc.Status {
log := appctx.GetLogger(ctx)

idReference := &provider.Reference{ResourceId: resourceID}
storageProvider, err := s.find(ctx, idReference)
if err != nil {
if _, ok := err.(errtypes.IsNotFound); ok {
return status.NewNotFound(ctx, "storage provider not found")
}
return status.NewInternal(ctx, err, "error finding storage provider")
}

statRes, err := storageProvider.Stat(ctx, &provider.StatRequest{Ref: idReference})
if err != nil {
return status.NewInternal(ctx, err, "gateway: error calling Stat for the share resource id: "+resourceID.String())
}

if statRes.Status.Code != rpc.Code_CODE_OK {
err := status.NewErrorFromCode(statRes.Status.GetCode(), "gateway")
return status.NewInternal(ctx, err, "could not delete share reference")
}

homeRes, err := s.GetHome(ctx, &provider.GetHomeRequest{})
if err != nil {
err := errors.Wrap(err, "gateway: error calling GetHome")
return status.NewInternal(ctx, err, "could not delete share reference")
}

sharePath := path.Join(homeRes.Path, s.c.ShareFolder, path.Base(statRes.Info.Path))
log.Debug().Str("share_path", sharePath).Msg("remove reference of share")

homeProvider, err := s.find(ctx, &provider.Reference{Path: sharePath})
if err != nil {
if _, ok := err.(errtypes.IsNotFound); ok {
return status.NewNotFound(ctx, "storage provider not found")
}
return status.NewInternal(ctx, err, "error finding storage provider")
}

deleteReq := &provider.DeleteRequest{
Opaque: &typesv1beta1.Opaque{
Map: map[string]*typesv1beta1.OpaqueEntry{
// This signals the storageprovider that we want to delete the share reference and not the underlying file.
"deleting_shared_resource": {},
},
},
Ref: &provider.Reference{Path: sharePath},
}

deleteResp, err := homeProvider.Delete(ctx, deleteReq)
if err != nil {
return status.NewInternal(ctx, err, "could not delete share reference")
}

if deleteResp.Status.Code != rpc.Code_CODE_OK {
err := status.NewErrorFromCode(deleteResp.Status.GetCode(), "gateway")
return status.NewInternal(ctx, err, "could not delete share reference")
}

log.Debug().Str("share_path", sharePath).Msg("share reference successfully removed")

return status.NewOK(ctx)
}

func (s *svc) createReference(ctx context.Context, resourceID *provider.ResourceId) *rpc.Status {
ref := &provider.Reference{
ResourceId: resourceID,
Expand Down
6 changes: 1 addition & 5 deletions tests/acceptance/expected-failures-on-OCIS-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ File and sync features in a shared scenario

#### [Response is empty when accepting a share](https://github.com/owncloud/product/issues/207)

- [apiShareManagementToShares/acceptShares.feature:207](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareManagementToShares/acceptShares.feature#L207)
- [apiShareManagementToShares/acceptShares.feature:82](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareManagementToShares/acceptShares.feature#L82)
- [apiShareManagementToShares/acceptShares.feature:261](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareManagementToShares/acceptShares.feature#L261)

#### [cannot accept identical pending shares from different user serially](https://github.com/owncloud/ocis/issues/2131)
Expand Down Expand Up @@ -1356,10 +1356,6 @@ _ocs: api compatibility, return correct status code_
- [apiShareOperationsToShares2/shareAccessByID.feature:155](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareOperationsToShares2/shareAccessByID.feature#L155)
- [apiShareOperationsToShares2/shareAccessByID.feature:156](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareOperationsToShares2/shareAccessByID.feature#L156)

#### [File is still present in the file list after declining a share](https://github.com/owncloud/ocis/issues/2112)
- [apiShareOperationsToShares2/shareAccessByID.feature:123](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareOperationsToShares2/shareAccessByID.feature#L123)
- [apiShareOperationsToShares2/shareAccessByID.feature:124](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareOperationsToShares2/shareAccessByID.feature#L124)

#### [[OC-storage] share-types field empty for shared file folder in webdav response](https://github.com/owncloud/ocis/issues/2144)
- [apiWebdavProperties2/getFileProperties.feature:156](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavProperties2/getFileProperties.feature#L156)
- [apiWebdavProperties2/getFileProperties.feature:157](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavProperties2/getFileProperties.feature#L157)
Expand Down
8 changes: 4 additions & 4 deletions tests/acceptance/expected-failures-on-S3NG-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,11 @@ File and sync features in a shared scenario

#### [Response is empty when accepting a share](https://github.com/owncloud/product/issues/207)

<<<<<<< HEAD
- [apiShareManagementToShares/acceptShares.feature:207](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareManagementToShares/acceptShares.feature#L207)
=======
- [apiShareManagementToShares/acceptShares.feature:82](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareManagementToShares/acceptShares.feature#L82)
>>>>>>> 8358b4e7 (remove share reference when declining a share)
- [apiShareManagementToShares/acceptShares.feature:261](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareManagementToShares/acceptShares.feature#L261)

#### [cannot accept identical pending shares from different user serially](https://github.com/owncloud/ocis/issues/2131)
Expand Down Expand Up @@ -1355,10 +1359,6 @@ _ocs: api compatibility, return correct status code_
- [apiShareOperationsToShares2/shareAccessByID.feature:155](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareOperationsToShares2/shareAccessByID.feature#L155)
- [apiShareOperationsToShares2/shareAccessByID.feature:156](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareOperationsToShares2/shareAccessByID.feature#L156)

#### [File is still present in the file list after declining a share](https://github.com/owncloud/ocis/issues/2112)
- [apiShareOperationsToShares2/shareAccessByID.feature:123](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareOperationsToShares2/shareAccessByID.feature#L123)
- [apiShareOperationsToShares2/shareAccessByID.feature:124](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiShareOperationsToShares2/shareAccessByID.feature#L124)

#### [[OC-storage] share-types field empty for shared file folder in webdav response](https://github.com/owncloud/ocis/issues/2144)
- [apiWebdavProperties2/getFileProperties.feature:156](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavProperties2/getFileProperties.feature#L156)
- [apiWebdavProperties2/getFileProperties.feature:157](https://github.com/owncloud/core/blob/master/tests/acceptance/features/apiWebdavProperties2/getFileProperties.feature#L157)
Expand Down

0 comments on commit 98875bc

Please sign in to comment.