From 5853b9b5980d7300f11d1c6c39fbb40b11a50a9e Mon Sep 17 00:00:00 2001
From: Pascal Bleser
Date: Mon, 16 Nov 2026 09:33:47 +0100
Subject: [PATCH] fix(graph): return the drive id in
remoteItem.parentReference.driveId
For received shares, remoteItem.parentReference.driveId held the id of
the root item of the drive ($!) instead of the id
of the drive ($), unlike all other drive items. Clients
had to cut off the root part themselves to request /drives/{drive-id}.
Use the drive id for user and OCM shares, and expect it in the
acceptance tests of the shared with me listing.
Fixes #3997
Assisted-by: Claude Code:claude-opus-5-5
---
.../graph/pkg/service/v0/sharedwithme_test.go | 18 ++++++++++++
services/graph/pkg/service/v0/utils.go | 4 +--
.../apiSharingNg1/sharedWithMe.feature | 28 +++++++++----------
.../sharedWithMeSyncDisabled.feature | 22 +++++++--------
.../editorListGrantsWithVersions.feature | 8 +++---
5 files changed, 49 insertions(+), 31 deletions(-)
diff --git a/services/graph/pkg/service/v0/sharedwithme_test.go b/services/graph/pkg/service/v0/sharedwithme_test.go
index adb83e2475..c7cf5dc658 100644
--- a/services/graph/pkg/service/v0/sharedwithme_test.go
+++ b/services/graph/pkg/service/v0/sharedwithme_test.go
@@ -289,6 +289,24 @@ var _ = Describe("SharedWithMe", func() {
Expect(jsonData.Get("driveId").String()).To(Equal(storagespace.FormatStorageID(utils.ShareStorageProviderID, utils.ShareStorageSpaceID)))
})
+ It("populates the driveItem.remoteItem.parentReference properties with the drive of the shared resource", func() {
+ statResponse.Info.Space = &providerv1beta1.StorageSpace{
+ SpaceType: "project",
+ Root: toResourceID("1$2!2"),
+ }
+
+ svc.ListSharedWithMe(
+ tape,
+ httptest.NewRequest(http.MethodGet, "/graph/v1beta1/me/drive/sharedWithMe", nil),
+ )
+
+ jsonData := gjson.Get(tape.Body.String(), "value.0.remoteItem.parentReference")
+
+ // the id of the drive, not the id of its root item
+ Expect(jsonData.Get("driveId").String()).To(Equal("1$2"))
+ Expect(jsonData.Get("driveType").String()).To(Equal("project"))
+ })
+
It("populates the driveItem remoteItem properties", func() {
share := listReceivedSharesResponse.Shares[0].Share
share.Id = &collaborationv1beta1.ShareId{OpaqueId: "1:2:3"}
diff --git a/services/graph/pkg/service/v0/utils.go b/services/graph/pkg/service/v0/utils.go
index 422f0f1872..064fa68b30 100644
--- a/services/graph/pkg/service/v0/utils.go
+++ b/services/graph/pkg/service/v0/utils.go
@@ -264,7 +264,7 @@ func cs3ReceivedSharesToDriveItems(ctx context.Context,
}
if root := shareStat.GetInfo().GetSpace().GetRoot(); root != nil {
- parentReference.SetDriveId(storagespace.FormatResourceID(root))
+ parentReference.SetDriveId(storagespace.FormatStorageID(root.GetStorageId(), root.GetSpaceId()))
}
if !reflect.ValueOf(*parentReference).IsZero() {
remoteItem.ParentReference = parentReference
@@ -619,7 +619,7 @@ func cs3ReceivedOCMSharesToDriveItems(ctx context.Context,
}
if root := shareStat.GetInfo().GetSpace().GetRoot(); root != nil {
- parentReference.SetDriveId(storagespace.FormatResourceID(root))
+ parentReference.SetDriveId(storagespace.FormatStorageID(root.GetStorageId(), root.GetSpaceId()))
}
if !reflect.ValueOf(*parentReference).IsZero() {
remoteItem.ParentReference = parentReference
diff --git a/tests/acceptance/features/apiSharingNg1/sharedWithMe.feature b/tests/acceptance/features/apiSharingNg1/sharedWithMe.feature
index 3577764252..d30c5ff630 100755
--- a/tests/acceptance/features/apiSharingNg1/sharedWithMe.feature
+++ b/tests/acceptance/features/apiSharingNg1/sharedWithMe.feature
@@ -202,7 +202,7 @@ Feature: an user gets the resources shared to them
"properties": {
"driveId": {
"type": "string",
- "pattern": "^%file_id_pattern%$"
+ "pattern": "^%space_id_pattern%$"
},
"driveType": {
"type": "string",
@@ -571,7 +571,7 @@ Feature: an user gets the resources shared to them
"properties": {
"driveId": {
"type": "string",
- "pattern": "^%file_id_pattern%$"
+ "pattern": "^%space_id_pattern%$"
},
"driveType": {
"type": "string",
@@ -870,7 +870,7 @@ Feature: an user gets the resources shared to them
"properties": {
"driveId": {
"type": "string",
- "pattern": "%space_id_pattern%"
+ "pattern": "^%space_id_pattern%$"
},
"driveType" : {
"type": "string",
@@ -1121,7 +1121,7 @@ Feature: an user gets the resources shared to them
"properties": {
"driveId": {
"type": "string",
- "pattern": "%space_id_pattern%"
+ "pattern": "^%space_id_pattern%$"
},
"driveType" : {
"const": "personal"
@@ -1399,7 +1399,7 @@ Feature: an user gets the resources shared to them
"properties": {
"driveId": {
"type": "string",
- "pattern": "%space_id_pattern%"
+ "pattern": "^%space_id_pattern%$"
},
"driveType" : {
"type": "string",
@@ -1748,7 +1748,7 @@ Feature: an user gets the resources shared to them
"properties": {
"driveId": {
"type": "string",
- "pattern": "%space_id_pattern%"
+ "pattern": "^%space_id_pattern%$"
},
"driveType" : {
"const": "personal"
@@ -2708,7 +2708,7 @@ Feature: an user gets the resources shared to them
"properties": {
"driveId": {
"type": "string",
- "pattern": "^%file_id_pattern%$"
+ "pattern": "^%space_id_pattern%$"
},
"driveType" : {
"const": "project"
@@ -2921,7 +2921,7 @@ Feature: an user gets the resources shared to them
"properties": {
"driveId": {
"type": "string",
- "pattern": "^%file_id_pattern%$"
+ "pattern": "^%space_id_pattern%$"
},
"driveType" : {
"const": "project"
@@ -3146,7 +3146,7 @@ Feature: an user gets the resources shared to them
"properties": {
"driveId": {
"type": "string",
- "pattern": "%space_id_pattern%"
+ "pattern": "^%space_id_pattern%$"
},
"driveType" : {
"const": "project"
@@ -3345,7 +3345,7 @@ Feature: an user gets the resources shared to them
"properties": {
"driveId": {
"type": "string",
- "pattern": "%space_id_pattern%"
+ "pattern": "^%space_id_pattern%$"
},
"driveType" : {
"const": "project"
@@ -3564,7 +3564,7 @@ Feature: an user gets the resources shared to them
"properties": {
"driveId": {
"type": "string",
- "pattern": "%space_id_pattern%"
+ "pattern": "^%space_id_pattern%$"
},
"driveType" : {
"const": "project"
@@ -3842,7 +3842,7 @@ Feature: an user gets the resources shared to them
"properties": {
"driveId": {
"type": "string",
- "pattern": "%space_id_pattern%"
+ "pattern": "^%space_id_pattern%$"
},
"driveType" : {
"const": "project"
@@ -4433,7 +4433,7 @@ Feature: an user gets the resources shared to them
"properties": {
"driveId": {
"type": "string",
- "pattern": "^%file_id_pattern%$"
+ "pattern": "^%space_id_pattern%$"
},
"driveType" : {
"const": "project"
@@ -4660,7 +4660,7 @@ Feature: an user gets the resources shared to them
"properties": {
"driveId": {
"type": "string",
- "pattern": "^%file_id_pattern%$"
+ "pattern": "^%space_id_pattern%$"
},
"driveType" : {
"const": "project"
diff --git a/tests/acceptance/features/apiSharingNg1/sharedWithMeSyncDisabled.feature b/tests/acceptance/features/apiSharingNg1/sharedWithMeSyncDisabled.feature
index fbff6a1091..bdeca5af17 100644
--- a/tests/acceptance/features/apiSharingNg1/sharedWithMeSyncDisabled.feature
+++ b/tests/acceptance/features/apiSharingNg1/sharedWithMeSyncDisabled.feature
@@ -181,7 +181,7 @@ Feature: listing sharedWithMe when auto-sync is disabled
"properties": {
"driveId": {
"type": "string",
- "pattern": "^%file_id_pattern%$"
+ "pattern": "^%space_id_pattern%$"
},
"driveType": {
"type": "string",
@@ -428,7 +428,7 @@ Feature: listing sharedWithMe when auto-sync is disabled
"properties": {
"driveId": {
"type": "string",
- "pattern": "^%file_id_pattern%$"
+ "pattern": "^%space_id_pattern%$"
},
"driveType": {
"type": "string",
@@ -693,7 +693,7 @@ Feature: listing sharedWithMe when auto-sync is disabled
"properties": {
"driveId": {
"type": "string",
- "pattern": "^%file_id_pattern%$"
+ "pattern": "^%space_id_pattern%$"
},
"driveType": {
"type": "string",
@@ -944,7 +944,7 @@ Feature: listing sharedWithMe when auto-sync is disabled
"properties": {
"driveId": {
"type": "string",
- "pattern": "^%file_id_pattern%$"
+ "pattern": "^%space_id_pattern%$"
},
"driveType": {
"type": "string",
@@ -1173,7 +1173,7 @@ Feature: listing sharedWithMe when auto-sync is disabled
"properties": {
"driveId": {
"type": "string",
- "pattern": "^%file_id_pattern%$"
+ "pattern": "^%space_id_pattern%$"
},
"driveType": {
"type": "string",
@@ -1395,7 +1395,7 @@ Feature: listing sharedWithMe when auto-sync is disabled
"properties": {
"driveId": {
"type": "string",
- "pattern": "^%file_id_pattern%$"
+ "pattern": "^%space_id_pattern%$"
},
"driveType": {
"type": "string",
@@ -1631,7 +1631,7 @@ Feature: listing sharedWithMe when auto-sync is disabled
"properties": {
"driveId": {
"type": "string",
- "pattern": "^%file_id_pattern%$"
+ "pattern": "^%space_id_pattern%$"
},
"driveType": {
"type": "string",
@@ -1843,7 +1843,7 @@ Feature: listing sharedWithMe when auto-sync is disabled
"properties": {
"driveId": {
"type": "string",
- "pattern": "^%file_id_pattern%$"
+ "pattern": "^%space_id_pattern%$"
},
"driveType": {
"type": "string",
@@ -3264,7 +3264,7 @@ Feature: listing sharedWithMe when auto-sync is disabled
"properties": {
"driveId": {
"type": "string",
- "pattern": "^%file_id_pattern%$"
+ "pattern": "^%space_id_pattern%$"
},
"driveType": {
"const": "project"
@@ -3401,7 +3401,7 @@ Feature: listing sharedWithMe when auto-sync is disabled
"properties": {
"driveId": {
"type": "string",
- "pattern": "^%file_id_pattern%$"
+ "pattern": "^%space_id_pattern%$"
},
"driveType": {
"const": "project"
@@ -3582,7 +3582,7 @@ Feature: listing sharedWithMe when auto-sync is disabled
"properties": {
"driveId": {
"type": "string",
- "pattern": "^%file_id_pattern%$"
+ "pattern": "^%space_id_pattern%$"
},
"driveType": {
"const": "project"
diff --git a/tests/acceptance/features/apiSharingNgAdditionalShareRole/editorListGrantsWithVersions.feature b/tests/acceptance/features/apiSharingNgAdditionalShareRole/editorListGrantsWithVersions.feature
index 47ba000c71..2fef683d5c 100644
--- a/tests/acceptance/features/apiSharingNgAdditionalShareRole/editorListGrantsWithVersions.feature
+++ b/tests/acceptance/features/apiSharingNgAdditionalShareRole/editorListGrantsWithVersions.feature
@@ -529,7 +529,7 @@ Feature: an user shares resources
"type": "object",
"required": ["driveId", "driveType"],
"properties": {
- "driveId": { "pattern": "^%file_id_pattern%$" },
+ "driveId": { "pattern": "^%space_id_pattern%$" },
"driveType": { "const": "personal" }
}
},
@@ -636,7 +636,7 @@ Feature: an user shares resources
"type": "object",
"required": ["driveId", "driveType"],
"properties": {
- "driveId": { "pattern": "^%file_id_pattern%$" },
+ "driveId": { "pattern": "^%space_id_pattern%$" },
"driveType": { "const": "personal" }
}
},
@@ -750,7 +750,7 @@ Feature: an user shares resources
"type": "object",
"required": ["driveId", "driveType"],
"properties": {
- "driveId": { "pattern": "^%file_id_pattern%$" },
+ "driveId": { "pattern": "^%space_id_pattern%$" },
"driveType": { "const": "project" }
}
},
@@ -843,7 +843,7 @@ Feature: an user shares resources
"type": "object",
"required": ["driveId", "driveType"],
"properties": {
- "driveId": { "pattern": "^%file_id_pattern%$" },
+ "driveId": { "pattern": "^%space_id_pattern%$" },
"driveType": { "const": "project" }
}
},