Skip to content

Commit

Permalink
spaces: a space creator becomes an editor within the new resource
Browse files Browse the repository at this point in the history
  • Loading branch information
refs committed Sep 8, 2021
1 parent d63124e commit 78d5c2f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/storage/utils/decomposedfs/grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import (
"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")
Expand Down Expand Up @@ -68,8 +71,12 @@ func (fs *Decomposedfs) AddGrant(ctx context.Context, ref *provider.Reference, g
return err
}

if err := fs.createStorageSpace(ctx, "share", node.ID); err != nil {
return err
// when a grant is added to a space, do not add a new space under "shares"
if spaceGrant := ctx.Value(SpaceGrant); spaceGrant == nil {
err := fs.createStorageSpace(ctx, "share", node.ID)
if err != nil {
return err
}
}

return fs.tp.Propagate(ctx, node)
Expand Down
23 changes: 23 additions & 0 deletions pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ import (
v1beta11 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
ocsconv "github.com/cs3org/reva/internal/http/services/owncloud/ocs/conversions"
"github.com/cs3org/reva/pkg/appctx"
ctxpkg "github.com/cs3org/reva/pkg/ctx"
"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/google/uuid"
"github.com/pkg/errors"
"github.com/pkg/xattr"
)

Expand Down Expand Up @@ -111,6 +113,27 @@ func (fs *Decomposedfs) CreateStorageSpace(ctx context.Context, req *provider.Cr
},
}

nPath, err := fs.lu.Path(ctx, n)
if err != nil {
return nil, errors.Wrap(err, "decomposedfs: spaces: could not create space. invalid node path")
}

ctx = context.WithValue(ctx, SpaceGrant, struct{}{})

if err := fs.AddGrant(ctx, &provider.Reference{
Path: nPath,
}, &provider.Grant{
Grantee: &provider.Grantee{
Type: provider.GranteeType_GRANTEE_TYPE_USER,
Id: &provider.Grantee_UserId{
UserId: u.Id,
},
},
Permissions: ocsconv.NewEditorRole().CS3ResourcePermissions(),
}); err != nil {
return nil, err
}

return resp, nil
}

Expand Down

0 comments on commit 78d5c2f

Please sign in to comment.