Skip to content

Commit

Permalink
Use space description on creation (#2533)
Browse files Browse the repository at this point in the history
* fix bug, coowners are now managers

* choose space description on creation

* add changelog

Signed-off-by: Michael Barz <[email protected]>

* fix unit tests
  • Loading branch information
micbar authored Feb 14, 2022
1 parent e55c115 commit 5832a9b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Change: Use description during space creation

We can now use a space description during space creation. We also fixed a bug in the spaces roles. Co-owners are now maintainers.

https://github.com/cs3org/reva/pull/2524
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestPermissions2Role(t *testing.T) {
table := map[Permissions]string{
PermissionRead: RoleViewer,
PermissionRead | PermissionWrite | PermissionCreate | PermissionDelete: RoleEditor,
PermissionAll: RoleCoowner,
PermissionAll: RoleManager,
PermissionWrite: RoleLegacy,
PermissionShare: RoleLegacy,
PermissionWrite | PermissionShare: RoleLegacy,
Expand Down
2 changes: 1 addition & 1 deletion internal/http/services/owncloud/ocs/conversions/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func RoleFromOCSPermissions(p Permissions) *Role {
if p.Contain(PermissionRead) {
if p.Contain(PermissionWrite) && p.Contain(PermissionCreate) && p.Contain(PermissionDelete) {
if p.Contain(PermissionShare) {
return NewCoownerRole()
return NewManagerRole()
}
return NewEditorRole()
}
Expand Down
53 changes: 29 additions & 24 deletions pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ func (fs *Decomposedfs) CreateStorageSpace(ctx context.Context, req *provider.Cr
spaceID = string(e.Value)
}
}
// allow sending a space description
var description string
if req.Opaque != nil && req.Opaque.Map != nil {
if e, ok := req.Opaque.Map["description"]; ok && e.Decoder == "plain" {
description = string(e.Value)
}
}
// TODO enforce a uuid?
// TODO clarify if we want to enforce a single personal storage space or if we want to allow sending the spaceid
if req.Type == "personal" {
Expand Down Expand Up @@ -111,40 +118,27 @@ func (fs *Decomposedfs) CreateStorageSpace(ctx context.Context, req *provider.Cr
return nil, err
}

metadata := make(map[string]string, 3)
if q := req.GetQuota(); q != nil {
// set default space quota
if err := n.SetMetadata(xattrs.QuotaAttr, strconv.FormatUint(q.QuotaMaxBytes, 10)); err != nil {
return nil, err
}
metadata[xattrs.QuotaAttr] = strconv.FormatUint(q.QuotaMaxBytes, 10)
}

if err := n.SetMetadata(xattrs.SpaceNameAttr, req.Name); err != nil {
return nil, err
metadata[xattrs.SpaceNameAttr] = req.Name
if description != "" {
metadata[xattrs.SpaceDescriptionAttr] = description
}

resp := &provider.CreateStorageSpaceResponse{
Status: &v1beta11.Status{
Code: v1beta11.Code_CODE_OK,
},
StorageSpace: &provider.StorageSpace{
Owner: u,
Id: &provider.StorageSpaceId{
OpaqueId: spaceID,
},
Root: &provider.ResourceId{
StorageId: spaceID,
OpaqueId: spaceID,
},
Name: req.GetName(),
Quota: req.GetQuota(),
SpaceType: req.GetType(),
},
if err := xattrs.SetMultiple(n.InternalPath(), metadata); err != nil {
return nil, err
}

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

if err := fs.AddGrant(ctx, &provider.Reference{
ResourceId: resp.StorageSpace.Root,
ResourceId: &provider.ResourceId{
StorageId: spaceID,
OpaqueId: spaceID,
},
}, &provider.Grant{
Grantee: &provider.Grantee{
Type: provider.GranteeType_GRANTEE_TYPE_USER,
Expand All @@ -157,6 +151,17 @@ func (fs *Decomposedfs) CreateStorageSpace(ctx context.Context, req *provider.Cr
return nil, err
}

space, err := fs.storageSpaceFromNode(ctx, n, "*", n.InternalPath(), false)
if err != nil {
return nil, err
}

resp := &provider.CreateStorageSpaceResponse{
Status: &v1beta11.Status{
Code: v1beta11.Code_CODE_OK,
},
StorageSpace: space,
}
return resp, nil
}

Expand Down

0 comments on commit 5832a9b

Please sign in to comment.