feat(graph): [OCISDEV-602] add space ID to incoming shares

Added the `spaceId` to the incoming shares. This is aligning the graph
API with the WebDAV API where the clients can use `spaceid` property.
This change allows clients to get the space ID directly instead of
having to parse the resource ID.
This commit is contained in:
Lukas Hirt authored and Roman Perekhod committed 2026-02-16 14:21:38 +01:00
1 parent abba43dbd1
commit db06952566
8 files changed
+159 -5

No files matched your search

@@ -0,0 +1,6 @@
Enhancement: Add space ID to incoming shares
Added the `spaceId` to the incoming shares. This is aligning the graph API with the WebDAV API where the clients can use `spaceid` property.
This change allows clients to get the space ID directly instead of having to parse the resource ID.
https://github.com/owncloud/ocis/pull/12024
+1 -1
View File
@@ -63,7 +63,7 @@ require (
github.com/onsi/gomega v1.39.0
github.com/open-policy-agent/opa v1.12.3
github.com/orcaman/concurrent-map v1.0.0
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260116104114-10074a92be64
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245
github.com/owncloud/reva/v2 v2.0.0-20260213104810-a8d45f58b2d5
github.com/pkg/errors v0.9.1
github.com/pkg/xattr v0.4.12
+2 -2
View File
@@ -740,8 +740,8 @@ github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/orcaman/concurrent-map v1.0.0 h1:I/2A2XPCb4IuQWcQhBhSwGfiuybl/J0ev9HDbW65HOY=
github.com/orcaman/concurrent-map v1.0.0/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI=
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260116104114-10074a92be64 h1:z9djjzd+leAy6QZpi8dLy3OVjc/um+1XAGk1SJEvwE8=
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260116104114-10074a92be64/go.mod h1:z61VMGAJRtR1nbgXWiNoCkxUXP1B3Je9rMuJbnGd+Og=
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245 h1:JRidLTAKhnvyLMRtVtSF4lhBa0NSAOs6fof+d6JnKII=
github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245/go.mod h1:z61VMGAJRtR1nbgXWiNoCkxUXP1B3Je9rMuJbnGd+Og=
github.com/owncloud/reva/v2 v2.0.0-20260213104810-a8d45f58b2d5 h1:JyDXgzdkdfAPt9uRMQu49AreYpaUl+RinrNVITyfHu4=
github.com/owncloud/reva/v2 v2.0.0-20260213104810-a8d45f58b2d5/go.mod h1:ahCZbT/ltp5J8aURUpTOfpA/dLBeTvHaMm772cvj7+U=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
@@ -2,4 +2,5 @@ package svc
var (
CS3ReceivedShareToLibreGraphPermissions = cs3ReceivedShareToLibreGraphPermissions
Cs3ReceivedSharesToDriveItems = cs3ReceivedSharesToDriveItems
)
+1 -1
View File
@@ -235,6 +235,7 @@ func cs3ReceivedSharesToDriveItems(ctx context.Context,
{
if id := shareStat.GetInfo().GetId(); id != nil {
remoteItem.SetId(storagespace.FormatResourceID(id))
remoteItem.SpaceId = libregraph.PtrString(storagespace.FormatStorageID(id.StorageId, id.SpaceId))
}
if name := shareStat.GetInfo().GetName(); name != "" {
@@ -264,7 +265,6 @@ func cs3ReceivedSharesToDriveItems(ctx context.Context,
if !reflect.ValueOf(*parentReference).IsZero() {
remoteItem.ParentReference = parentReference
}
}
// the parentReference of the outer driveItem should be the drive
+110
View File
@@ -5,13 +5,22 @@ import (
"net/http"
"net/http/httptest"
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/go-chi/chi/v5"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
libregraph "github.com/owncloud/libre-graph-api-go"
rConversions "github.com/owncloud/reva/v2/pkg/conversions"
"github.com/owncloud/reva/v2/pkg/rgrpc/todo/pool"
"github.com/owncloud/reva/v2/pkg/utils"
cs3mocks "github.com/owncloud/reva/v2/tests/cs3mocks/mocks"
"github.com/stretchr/testify/mock"
"google.golang.org/grpc"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/owncloud/reva/v2/pkg/storagespace"
@@ -150,4 +159,105 @@ var _ = Describe("Utils", func() {
},
),
)
Describe("cs3ReceivedSharesToDriveItems", func() {
It("sets spaceId in remoteItem", func() {
pool.RemoveSelector("GatewaySelector" + "com.owncloud.api.gateway")
gatewayClient := &cs3mocks.GatewayAPIClient{}
gatewaySelector := pool.GetSelector[gateway.GatewayAPIClient](
"GatewaySelector",
"com.owncloud.api.gateway",
func(cc grpc.ClientConnInterface) gateway.GatewayAPIClient {
return gatewayClient
},
)
statResponse := &storageprovider.StatResponse{
Status: &rpc.Status{Code: rpc.Code_CODE_OK},
Info: &storageprovider.ResourceInfo{
Id: &storageprovider.ResourceId{
StorageId: "storage-id-123",
SpaceId: "space-id-456",
OpaqueId: "opaque-id-789",
},
Name: "shared-file.txt",
Type: storageprovider.ResourceType_RESOURCE_TYPE_FILE,
Etag: "etag-abc",
Size: 1024,
Mtime: &typesv1beta1.Timestamp{Seconds: 1234567890},
Space: &storageprovider.StorageSpace{
SpaceType: "project",
Root: &storageprovider.ResourceId{
StorageId: "storage-id-123",
SpaceId: "space-id-456",
OpaqueId: "space-id-456",
},
},
},
}
gatewayClient.On("Stat", mock.Anything, mock.Anything).Return(statResponse, nil)
getUserResponse := &userpb.GetUserResponse{
Status: &rpc.Status{Code: rpc.Code_CODE_OK},
User: &userpb.User{
Id: &userpb.UserId{
OpaqueId: "user-123",
},
DisplayName: "Test User",
Mail: "test@example.com",
},
}
gatewayClient.On("GetUser", mock.Anything, mock.Anything).Return(getUserResponse, nil)
identityCache := identity.NewIdentityCache(
identity.IdentityCacheWithGatewaySelector(gatewaySelector),
)
receivedShares := []*collaboration.ReceivedShare{
{
Share: &collaboration.Share{
Id: &collaboration.ShareId{
OpaqueId: "share-123",
},
ResourceId: &storageprovider.ResourceId{
StorageId: "storage-id-123",
SpaceId: "space-id-456",
OpaqueId: "opaque-id-789",
},
Permissions: &collaboration.SharePermissions{
Permissions: rConversions.NewViewerRole().CS3ResourcePermissions(),
},
Creator: &userpb.UserId{
OpaqueId: "user-123",
},
Ctime: &typesv1beta1.Timestamp{Seconds: 1234567890},
},
State: collaboration.ShareState_SHARE_STATE_ACCEPTED,
MountPoint: &storageprovider.Reference{
Path: "shared-file.txt",
},
},
}
driveItems, err := service.Cs3ReceivedSharesToDriveItems(
context.Background(),
conversions.ToPointer(log.NopLogger()),
gatewayClient,
identityCache,
receivedShares,
unifiedrole.GetRoles(unifiedrole.RoleFilterAll()),
)
Expect(err).ToNot(HaveOccurred())
Expect(driveItems).To(HaveLen(1))
driveItem := driveItems[0]
Expect(driveItem.RemoteItem).ToNot(BeNil())
Expect(driveItem.RemoteItem.HasSpaceId()).To(BeTrue())
expectedSpaceId := storagespace.FormatStorageID("storage-id-123", "space-id-456")
Expect(driveItem.RemoteItem.GetSpaceId()).To(Equal(expectedSpaceId))
})
})
})
+37
View File
@@ -54,6 +54,8 @@ type RemoteItem struct {
WebDavUrl *string `json:"webDavUrl,omitempty"`
// URL that displays the resource in the browser. Read-only.
WebUrl *string `json:"webUrl,omitempty"`
// The UUID of the space that contains the item.
SpaceId *string `json:"spaceId,omitempty"`
}
// NewRemoteItem instantiates a new RemoteItem object
@@ -745,6 +747,38 @@ func (o *RemoteItem) SetWebUrl(v string) {
o.WebUrl = &v
}
// GetSpaceId returns the SpaceId field value if set, zero value otherwise.
func (o *RemoteItem) GetSpaceId() string {
if o == nil || IsNil(o.SpaceId) {
var ret string
return ret
}
return *o.SpaceId
}
// GetSpaceIdOk returns a tuple with the SpaceId field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *RemoteItem) GetSpaceIdOk() (*string, bool) {
if o == nil || IsNil(o.SpaceId) {
return nil, false
}
return o.SpaceId, true
}
// HasSpaceId returns a boolean if a field has been set.
func (o *RemoteItem) HasSpaceId() bool {
if o != nil && !IsNil(o.SpaceId) {
return true
}
return false
}
// SetSpaceId gets a reference to the given string and assigns it to the SpaceId field.
func (o *RemoteItem) SetSpaceId(v string) {
o.SpaceId = &v
}
func (o RemoteItem) MarshalJSON() ([]byte, error) {
toSerialize, err := o.ToMap()
if err != nil {
@@ -818,6 +852,9 @@ func (o RemoteItem) ToMap() (map[string]interface{}, error) {
if !IsNil(o.WebUrl) {
toSerialize["webUrl"] = o.WebUrl
}
if !IsNil(o.SpaceId) {
toSerialize["spaceId"] = o.SpaceId
}
return toSerialize, nil
}
+1 -1
View File
@@ -1310,7 +1310,7 @@ github.com/opentracing/opentracing-go/log
# github.com/orcaman/concurrent-map v1.0.0
## explicit
github.com/orcaman/concurrent-map
# github.com/owncloud/libre-graph-api-go v1.0.5-0.20260116104114-10074a92be64
# github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245
## explicit; go 1.18
github.com/owncloud/libre-graph-api-go
# github.com/owncloud/reva/v2 v2.0.0-20260213104810-a8d45f58b2d5