Skip to content

Commit

Permalink
demposedfs: Fix ReadNode call in NodeFromSpaceID()
Browse files Browse the repository at this point in the history
Pass the correct ID (the spaced id) to ReadNode(). Also fix the
signature of the NodeFromSpaceID method to make it more obvious that
just needs a Resource ID.
  • Loading branch information
rhafer committed Jun 19, 2023
1 parent b30fdde commit e800133
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
8 changes: 4 additions & 4 deletions pkg/storage/utils/decomposedfs/lookup/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (lu *Lookup) NodeFromID(ctx context.Context, id *provider.ResourceId) (n *n
}
if id.OpaqueId == "" {
// The Resource references the root of a space
return lu.NodeFromSpaceID(ctx, id)
return lu.NodeFromSpaceID(ctx, id.SpaceId)
}
return node.ReadNode(ctx, lu, id.SpaceId, id.OpaqueId, false, nil, false)
}
Expand All @@ -162,9 +162,9 @@ func Pathify(id string, depth, width int) string {
return b.String()
}

// NodeFromSpaceID converts a resource id without an opaque id into a Node
func (lu *Lookup) NodeFromSpaceID(ctx context.Context, id *provider.ResourceId) (n *node.Node, err error) {
node, err := node.ReadNode(ctx, lu, id.SpaceId, id.OpaqueId, false, nil, false)
// NodeFromSpaceID converts a resource id into a Node
func (lu *Lookup) NodeFromSpaceID(ctx context.Context, spaceID string) (n *node.Node, err error) {
node, err := node.ReadNode(ctx, lu, spaceID, spaceID, false, nil, false)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/storage/utils/decomposedfs/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,15 @@ var _ = Describe("Node", func() {
})
Describe("Permissions", func() {
It("Checks the owner permissions on a personal space", func() {
node1, err := env.Lookup.NodeFromSpaceID(env.Ctx, env.SpaceRootRes)
node1, err := env.Lookup.NodeFromSpaceID(env.Ctx, env.SpaceRootRes.SpaceId)
Expect(err).ToNot(HaveOccurred())
perms, _ := node1.PermissionSet(env.Ctx)
Expect(perms).To(Equal(node.OwnerPermissions()))
})
It("Checks the manager permissions on a project space", func() {
pSpace, err := env.CreateTestStorageSpace("project", &provider.Quota{QuotaMaxBytes: 2000})
Expect(err).ToNot(HaveOccurred())
nodePSpace, err := env.Lookup.NodeFromSpaceID(env.Ctx, pSpace)
nodePSpace, err := env.Lookup.NodeFromSpaceID(env.Ctx, pSpace.SpaceId)
Expect(err).ToNot(HaveOccurred())
u := ctxpkg.ContextMustGetUser(env.Ctx)
env.Permissions.On("AssemblePermissions", mock.Anything, mock.Anything, mock.Anything).Return(provider.ResourcePermissions{
Expand Down Expand Up @@ -288,7 +288,7 @@ var _ = Describe("Node", func() {
Permissions: ocsconv.NewEditorRole(false).CS3ResourcePermissions(),
})
Expect(err).ToNot(HaveOccurred())
spaceRoot, err := env.Lookup.NodeFromSpaceID(env.Ctx, storageSpace)
spaceRoot, err := env.Lookup.NodeFromSpaceID(env.Ctx, storageSpace.SpaceId)
Expect(err).ToNot(HaveOccurred())
permissionsActual, _ := spaceRoot.PermissionSet(env.Ctx)
permissionsExpected := ocsconv.NewEditorRole(false).CS3ResourcePermissions()
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/recycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (fs *Decomposedfs) ListRecycle(ctx context.Context, ref *provider.Reference
sublog := appctx.GetLogger(ctx).With().Str("space", spaceID).Str("key", key).Str("relative_path", relativePath).Logger()

// check permissions
trashnode, err := fs.lu.NodeFromSpaceID(ctx, ref.ResourceId)
trashnode, err := fs.lu.NodeFromSpaceID(ctx, spaceID)
if err != nil {
return nil, err
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/storage/utils/decomposedfs/upload/processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ func New(ctx context.Context, info tusd.FileInfo, lu *lookup.Lookup, tp Tree, p
return nil, errors.New("Decomposedfs: missing dir in metadata")
}

n, err := lu.NodeFromSpaceID(ctx, &provider.ResourceId{
SpaceId: info.Storage["SpaceRoot"],
OpaqueId: info.Storage["SpaceRoot"],
})
n, err := lu.NodeFromSpaceID(ctx, info.Storage["SpaceRoot"])
if err != nil {
return nil, errors.Wrap(err, "Decomposedfs: error getting space root node")
}
Expand Down

0 comments on commit e800133

Please sign in to comment.