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

add remote item metadata #6300

Merged
merged 1 commit into from
Jun 14, 2023
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
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
23 changes: 17 additions & 6 deletions services/graph/pkg/service/v0/driveitems.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,17 @@ 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))
item.WebDavUrl = libregraph.PtrString(webDavURL.String())
item.Name = libregraph.PtrString(res.GetInfo().GetName())
if res.GetInfo().GetSpace().GetRoot() != nil {
webDavURL := *baseURL
relativePath := res.GetInfo().GetPath()
webDavURL.Path = path.Join(webDavURL.Path, storagespace.FormatResourceID(*res.GetInfo().GetSpace().GetRoot()), relativePath)
item.WebDavUrl = libregraph.PtrString(webDavURL.String())
}
}
return item, nil
}
Expand Down Expand Up @@ -192,8 +196,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 +215,13 @@ func cs3ResourceToRemoteItem(res *storageprovider.ResourceInfo) (*libregraph.Rem
if res.Type == storageprovider.ResourceType_RESOURCE_TYPE_CONTAINER {
remoteItem.Folder = &libregraph.Folder{}
}
if res.GetSpace() != nil && res.GetSpace().GetRoot() != nil {
remoteItem.RootId = libregraph.PtrString(storagespace.FormatResourceID(*res.GetSpace().GetRoot()))
micbar marked this conversation as resolved.
Show resolved Hide resolved
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