Skip to content

Commit

Permalink
add remote item metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Barz <[email protected]>
  • Loading branch information
micbar committed Jun 13, 2023
1 parent 85dcb57 commit 421bb4f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/add-remote-item-metadata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Add more metadata to the remote item

We added the drive alias, the space name and the relative path to the remote item. This is needed to resolve shared files directly on the source space.

https://github.com/owncloud/ocis/pull/6300
17 changes: 13 additions & 4 deletions services/graph/pkg/service/v0/driveitems.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,15 @@ func (g Graph) getRemoteItem(ctx context.Context, root *storageprovider.Resource
return nil, err
}

if baseURL != nil {
if baseURL != nil && res.GetInfo() != nil && res.GetInfo().GetSpace() != nil {
// TODO read from StorageSpace ... needs Opaque for now
// TODO how do we build the url?
// for now: read from request
webDavURL := *baseURL
webDavURL.Path = path.Join(webDavURL.Path, storagespace.FormatResourceID(*root))
relativePath := res.GetInfo().GetPath()
webDavURL.Path = path.Join(webDavURL.Path, storagespace.FormatResourceID(*res.GetInfo().GetSpace().GetRoot()), relativePath)
item.WebDavUrl = libregraph.PtrString(webDavURL.String())
item.Name = libregraph.PtrString(res.GetInfo().GetName())
}
return item, nil
}
Expand Down Expand Up @@ -192,8 +194,8 @@ func cs3ResourceToRemoteItem(res *storageprovider.ResourceInfo) (*libregraph.Rem
Size: size,
}

if name := path.Base(res.Path); name != "" {
remoteItem.Name = &name
if res.GetPath() != "" {
remoteItem.Path = libregraph.PtrString(path.Clean(res.GetPath()))
}
if res.Etag != "" {
remoteItem.ETag = &res.Etag
Expand All @@ -211,6 +213,13 @@ func cs3ResourceToRemoteItem(res *storageprovider.ResourceInfo) (*libregraph.Rem
if res.Type == storageprovider.ResourceType_RESOURCE_TYPE_CONTAINER {
remoteItem.Folder = &libregraph.Folder{}
}
if res.GetSpace() != nil {
remoteItem.RootId = libregraph.PtrString(storagespace.FormatResourceID(*res.GetSpace().GetRoot()))
grantSpaceAlias := utils.ReadPlainFromOpaque(res.GetSpace().GetOpaque(), "spaceAlias")
if grantSpaceAlias != "" {
remoteItem.DriveAlias = libregraph.PtrString(grantSpaceAlias)
}
}
return remoteItem, nil
}

Expand Down
15 changes: 13 additions & 2 deletions services/graph/pkg/service/v0/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,18 +278,28 @@ var _ = Describe("Graph", func() {
"grantOpaqueID": {Decoder: "plain", Value: []byte("opaqueID")},
},
},
RootInfo: &provider.ResourceInfo{Path: "New Folder", Name: "Project Mars"},
},
},
}, nil)
var opaque *typesv1beta1.Opaque
opaque = utils.AppendPlainToOpaque(opaque, "spaceAlias", "project/project-mars")
gatewayClient.On("Stat", mock.Anything, mock.Anything).Return(&provider.StatResponse{
Status: status.NewOK(ctx),
Info: &provider.ResourceInfo{
Etag: "123456789",
Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER,
Id: &provider.ResourceId{StorageId: "ownerStorageID", SpaceId: "spaceID", OpaqueId: "opaqueID"},
Path: "New Folder",
Path: "Folder/New Folder",
Mtime: &typesv1beta1.Timestamp{Seconds: 1648327606, Nanos: 0},
Size: uint64(1234),
Name: "New Folder",
Space: &provider.StorageSpace{
Name: "Project Mars",
SpaceType: "project",
Opaque: opaque,
Root: &provider.ResourceId{StorageId: "ownerStorageID", SpaceId: "spaceID", OpaqueId: "opaqueID"},
},
},
}, nil)
gatewayClient.On("GetQuota", mock.Anything, mock.Anything).Return(&provider.GetQuotaResponse{
Expand Down Expand Up @@ -322,8 +332,9 @@ var _ = Describe("Graph", func() {
Expect(value.Root.RemoteItem.LastModifiedDateTime.UTC()).To(Equal(time.Unix(1648327606, 0).UTC()))
Expect(*value.Root.RemoteItem.Folder).To(Equal(libregraph.Folder{}))
Expect(*value.Root.RemoteItem.Name).To(Equal("New Folder"))
Expect(*value.Root.RemoteItem.Path).To(Equal("Folder/New Folder"))
Expect(*value.Root.RemoteItem.Size).To(Equal(int64(1234)))
Expect(*value.Root.RemoteItem.WebDavUrl).To(Equal("https://localhost:9200/dav/spaces/ownerStorageID$spaceID%21opaqueID"))
Expect(*value.Root.RemoteItem.WebDavUrl).To(Equal("https://localhost:9200/dav/spaces/ownerStorageID$spaceID%21opaqueID/Folder/New%20Folder"))
})
It("can not list spaces with wrong sort parameter", func() {
gatewayClient.On("ListStorageSpaces", mock.Anything, mock.Anything).Return(&provider.ListStorageSpacesResponse{
Expand Down

0 comments on commit 421bb4f

Please sign in to comment.