diff --git a/extensions/graph/pkg/service/v0/drives.go b/extensions/graph/pkg/service/v0/drives.go index 17f04e2df7..821e664898 100644 --- a/extensions/graph/pkg/service/v0/drives.go +++ b/extensions/graph/pkg/service/v0/drives.go @@ -448,11 +448,25 @@ func (g Graph) ListStorageSpacesWithFilters(ctx context.Context, filters []*stor return res, err } +func generateSpaceId(id *storageprovider.ResourceId) (spaceID string) { + spaceID = id.GetStorageId() + // 2nd ID to compare is the opaque ID of the Space Root + spaceID2 := id.GetOpaqueId() + if strings.Contains(spaceID, "$") { + spaceID2, _ = resourceid.StorageIDUnwrap(spaceID) + } + // Append opaqueID only if it is different from the spaceID2 + if id.OpaqueId != spaceID2 { + spaceID += "!" + id.OpaqueId + } + return spaceID +} + func (g Graph) cs3StorageSpaceToDrive(ctx context.Context, baseURL *url.URL, space *storageprovider.StorageSpace) (*libregraph.Drive, error) { if space.Root == nil { return nil, fmt.Errorf("space has no root") } - rootID := resourceid.OwnCloudResourceIDWrap(space.Root) + spaceID := generateSpaceId(space.Root) var permissions []libregraph.Permission if space.Opaque != nil { @@ -510,19 +524,14 @@ func (g Graph) cs3StorageSpaceToDrive(ctx context.Context, baseURL *url.URL, spa } } - spaceID := space.Root.StorageId - sIDs := resourceid.OwnCloudResourceIDUnwrap(rootID) - if space.Root.OpaqueId != sIDs.OpaqueId { - spaceID = rootID - } drive := &libregraph.Drive{ - Id: &spaceID, + Id: libregraph.PtrString(spaceID), Name: &space.Name, //"createdDateTime": "string (timestamp)", // TODO read from StorageSpace ... needs Opaque for now //"description": "string", // TODO read from StorageSpace ... needs Opaque for now DriveType: &space.SpaceType, Root: &libregraph.DriveItem{ - Id: &rootID, + Id: libregraph.PtrString(resourceid.OwnCloudResourceIDWrap(space.Root)), Permissions: permissions, }, } diff --git a/extensions/graph/pkg/service/v0/graph_test.go b/extensions/graph/pkg/service/v0/graph_test.go index 0d52357cf8..8ad28656ee 100644 --- a/extensions/graph/pkg/service/v0/graph_test.go +++ b/extensions/graph/pkg/service/v0/graph_test.go @@ -201,7 +201,7 @@ var _ = Describe("Graph", func() { Id: &provider.StorageSpaceId{OpaqueId: "aID!differentID"}, SpaceType: "mountpoint", Root: &provider.ResourceId{ - StorageId: "aID", + StorageId: "prID$aID", OpaqueId: "differentID", }, Name: "New Folder", @@ -246,11 +246,11 @@ var _ = Describe("Graph", func() { value := response["value"][0] Expect(*value.DriveAlias).To(Equal("mountpoint/new-folder")) Expect(*value.DriveType).To(Equal("mountpoint")) - Expect(*value.Id).To(Equal("aID!differentID")) + Expect(*value.Id).To(Equal("prID$aID!differentID")) Expect(*value.Name).To(Equal("New Folder")) - Expect(*value.Root.WebDavUrl).To(Equal("https://localhost:9200/dav/spaces/aID!differentID")) + Expect(*value.Root.WebDavUrl).To(Equal("https://localhost:9200/dav/spaces/prID$aID!differentID")) Expect(*value.Root.ETag).To(Equal("101112131415")) - Expect(*value.Root.Id).To(Equal("aID!differentID")) + Expect(*value.Root.Id).To(Equal("prID$aID!differentID")) Expect(*value.Root.RemoteItem.ETag).To(Equal("123456789")) Expect(*value.Root.RemoteItem.Id).To(Equal("ownerStorageID!opaqueID")) Expect(value.Root.RemoteItem.LastModifiedDateTime.UTC()).To(Equal(time.Unix(1648327606, 0).UTC()))