Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use space description on creation #2533

Merged
merged 4 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
micbar marked this conversation as resolved.
Show resolved Hide resolved
}

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,
}
micbar marked this conversation as resolved.
Show resolved Hide resolved
return resp, nil
}

Expand Down