diff --git a/changelog/unreleased/remove-share-reference.md b/changelog/unreleased/remove-share-reference.md new file mode 100644 index 0000000000..fe9197f22f --- /dev/null +++ b/changelog/unreleased/remove-share-reference.md @@ -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 diff --git a/internal/grpc/services/gateway/storageprovider.go b/internal/grpc/services/gateway/storageprovider.go index 5dd46af077..d5410adf68 100644 --- a/internal/grpc/services/gateway/storageprovider.go +++ b/internal/grpc/services/gateway/storageprovider.go @@ -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) { diff --git a/internal/grpc/services/gateway/usershareprovider.go b/internal/grpc/services/gateway/usershareprovider.go index a1bc98ad0e..77f89bfc10 100644 --- a/internal/grpc/services/gateway/usershareprovider.go +++ b/internal/grpc/services/gateway/usershareprovider.go @@ -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" @@ -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 @@ -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 } } @@ -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, diff --git a/tests/acceptance/expected-failures-on-OCIS-storage.md b/tests/acceptance/expected-failures-on-OCIS-storage.md index 844697ad18..b17ce10a8a 100644 --- a/tests/acceptance/expected-failures-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-on-OCIS-storage.md @@ -327,7 +327,6 @@ 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: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) @@ -1356,10 +1355,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) diff --git a/tests/acceptance/expected-failures-on-S3NG-storage.md b/tests/acceptance/expected-failures-on-S3NG-storage.md index cbd5ac6dde..3ba507be06 100644 --- a/tests/acceptance/expected-failures-on-S3NG-storage.md +++ b/tests/acceptance/expected-failures-on-S3NG-storage.md @@ -330,7 +330,6 @@ 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: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) @@ -1355,10 +1354,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)