From bc20acb6d9f59f26223a595ec8c4422224529032 Mon Sep 17 00:00:00 2001 From: kobergj Date: Fri, 21 Jan 2022 14:48:12 +0100 Subject: [PATCH] Space grants (#2464) * send spacegrants and pass them to decomposedfs Signed-off-by: jkoberg * add changelog item Signed-off-by: jkoberg --- changelog/unreleased/extract-space-grants.md | 9 +++++++++ .../grpc/services/storageprovider/storageprovider.go | 9 +++++++++ .../ocs/handlers/apps/sharing/shares/spaces.go | 10 +++++++++- pkg/storage/utils/decomposedfs/grants.go | 6 ++---- pkg/storage/utils/decomposedfs/spaces.go | 2 +- pkg/utils/utils.go | 3 +++ 6 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 changelog/unreleased/extract-space-grants.md diff --git a/changelog/unreleased/extract-space-grants.md b/changelog/unreleased/extract-space-grants.md new file mode 100644 index 00000000000..2aa09f8114f --- /dev/null +++ b/changelog/unreleased/extract-space-grants.md @@ -0,0 +1,9 @@ +Bugfix: pass spacegrants when adding member to space + +When creating a space grant there should not be created a new space. +Unfortunately SpaceGrant didn't work when adding members to a space. +Now a value is placed in the ctx of the storageprovider on which decomposedfs reacts + + + +https://github.com/cs3org/reva/pull/2464 diff --git a/internal/grpc/services/storageprovider/storageprovider.go b/internal/grpc/services/storageprovider/storageprovider.go index 51a7739651d..e1f0505b8b3 100644 --- a/internal/grpc/services/storageprovider/storageprovider.go +++ b/internal/grpc/services/storageprovider/storageprovider.go @@ -1128,6 +1128,15 @@ func (s *service) DenyGrant(ctx context.Context, req *provider.DenyGrantRequest) } func (s *service) AddGrant(ctx context.Context, req *provider.AddGrantRequest) (*provider.AddGrantResponse, error) { + // TODO: update CS3 APIs + if req.Opaque != nil { + _, spacegrant := req.Opaque.Map["spacegrant"] + if spacegrant { + ctx = context.WithValue(ctx, utils.SpaceGrant, struct{}{}) + } + + } + // check grantee type is valid if req.Grant.Grantee.Type == provider.GranteeType_GRANTEE_TYPE_INVALID { return &provider.AddGrantResponse{ diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/spaces.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/spaces.go index 602b215bef6..0d7945dbc17 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/spaces.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/spaces.go @@ -102,8 +102,16 @@ func (h *Handler) addSpaceMember(w http.ResponseWriter, r *http.Request, info *p return } + // TODO: change CS3 APIs + opaque := &types.Opaque{ + Map: map[string]*types.OpaqueEntry{ + "spacegrant": {}, + }, + } + addGrantRes, err := providerClient.AddGrant(ctx, &provider.AddGrantRequest{ - Ref: ref, + Opaque: opaque, + Ref: ref, Grant: &provider.Grant{ Grantee: &grantee, Permissions: role.CS3ResourcePermissions(), diff --git a/pkg/storage/utils/decomposedfs/grants.go b/pkg/storage/utils/decomposedfs/grants.go index 918c1643730..fc22859460a 100644 --- a/pkg/storage/utils/decomposedfs/grants.go +++ b/pkg/storage/utils/decomposedfs/grants.go @@ -29,12 +29,10 @@ import ( "github.com/cs3org/reva/pkg/storage/utils/ace" "github.com/cs3org/reva/pkg/storage/utils/decomposedfs/node" "github.com/cs3org/reva/pkg/storage/utils/decomposedfs/xattrs" + "github.com/cs3org/reva/pkg/utils" "github.com/pkg/xattr" ) -// SpaceGrant is the key used to signal not to create a new space when a grant is assigned to a storage space. -var SpaceGrant struct{} - // DenyGrant denies access to a resource. func (fs *Decomposedfs) DenyGrant(ctx context.Context, ref *provider.Reference, g *provider.Grantee) error { return errtypes.NotSupported("decomposedfs: not supported") @@ -71,7 +69,7 @@ func (fs *Decomposedfs) AddGrant(ctx context.Context, ref *provider.Reference, g } // when a grant is added to a space, do not add a new space under "shares" - if spaceGrant := ctx.Value(SpaceGrant); spaceGrant == nil { + if spaceGrant := ctx.Value(utils.SpaceGrant); spaceGrant == nil { err := fs.createStorageSpace(ctx, "share", node.ID) if err != nil { return err diff --git a/pkg/storage/utils/decomposedfs/spaces.go b/pkg/storage/utils/decomposedfs/spaces.go index fe9db3e5544..fe5d2b6d456 100644 --- a/pkg/storage/utils/decomposedfs/spaces.go +++ b/pkg/storage/utils/decomposedfs/spaces.go @@ -143,7 +143,7 @@ func (fs *Decomposedfs) CreateStorageSpace(ctx context.Context, req *provider.Cr }, } - ctx = context.WithValue(ctx, SpaceGrant, struct{}{}) + ctx = context.WithValue(ctx, utils.SpaceGrant, struct{}{}) if err := fs.AddGrant(ctx, &provider.Reference{ ResourceId: resp.StorageSpace.Root, diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 9134f7eaa74..3a350fa3483 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -55,6 +55,9 @@ var ( // PublicStorageProviderID is the id used by the sharestorageprovider PublicStorageProviderID = "7993447f-687f-490d-875c-ac95e89a62a4" + + // SpaceGrant is used to signal the storageprovider that the grant is on a space + SpaceGrant struct{} ) // Skip evaluates whether a source endpoint contains any of the prefixes.