Skip to content

Commit

Permalink
remove share reference when declining a share (#1991)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christofas authored Sep 8, 2021
1 parent bd4575a commit 571a960
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 15 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
5 changes: 0 additions & 5 deletions tests/acceptance/expected-failures-on-OCIS-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,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)
Expand Down Expand Up @@ -1344,10 +1343,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
5 changes: 0 additions & 5 deletions tests/acceptance/expected-failures-on-S3NG-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,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)
Expand Down Expand Up @@ -1343,10 +1342,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 571a960

Please sign in to comment.