Skip to content

Commit

Permalink
fix(sharing-ng): align sharedWithMe driveItem IDs
Browse files Browse the repository at this point in the history
The IDs of the driveItems returned by the 'sharedWithMe' endpoint
should match the ids returned by the webdav PROPFIND response on
the share jail.

Fixes: owncloud#8420
  • Loading branch information
rhafer committed Feb 21, 2024
1 parent f1638d6 commit 49362dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
26 changes: 17 additions & 9 deletions services/graph/pkg/service/v0/sharedwithme.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,24 @@ func (g Graph) cs3ReceivedSharesToDriveItems(ctx context.Context, receivedShares

group.Go(func() error {
var err error // redeclare
resourceID := receivedShares[0].GetShare().GetResourceId()
shareStat, err := doStat(receivedShares[0].GetShare().GetResourceId())
if shareStat == nil || err != nil {
return err
}

driveItem := libregraph.NewDriveItem()

// The id of the driveItem will be the composed of the StorageID and the SpaceID of the sharestorage
// appended with the ResourceID of the shared resource
// '<sharestorageid>$<sharespaceid>!<resource's storageid>:<resource's spaceid>:<resource's opaque id>'
driveItem.SetId(storagespace.FormatResourceID(storageprovider.ResourceId{
StorageId: utils.ShareStorageProviderID,
OpaqueId: resourceID.GetStorageId() + ":" + resourceID.GetSpaceId() + ":" + resourceID.GetOpaqueId(),
SpaceId: utils.ShareStorageSpaceID,
}))
permissions := make([]libregraph.Permission, 0, len(receivedShares))

var oldestReceivedShare *collaboration.ReceivedShare
for _, receivedShare := range receivedShares {
switch {
case oldestReceivedShare == nil:
fallthrough
case utils.TSToTime(receivedShare.GetShare().GetCtime()).Before(utils.TSToTime(oldestReceivedShare.GetShare().GetCtime())):
oldestReceivedShare = receivedShare
}

permission, err := g.cs3ReceivedShareToLibreGraphPermissions(ctx, receivedShare)
if err != nil {
return err
Expand Down Expand Up @@ -150,6 +149,15 @@ func (g Graph) cs3ReceivedSharesToDriveItems(ctx context.Context, receivedShares

}

// The id of the driveItem will be the composed of the StorageID and the SpaceID of the sharestorage
// appended with the ShareID of the oldest shared that exists for this resource
// '<sharestorageid>$<sharespaceid>!<resource's storageid>:<resource's spaceid>:<resource's opaque id>'
driveItem.SetId(storagespace.FormatResourceID(storageprovider.ResourceId{
StorageId: utils.ShareStorageProviderID,
OpaqueId: oldestReceivedShare.GetShare().GetId().GetOpaqueId(),
SpaceId: utils.ShareStorageSpaceID,
}))

if !driveItem.HasUIHidden() {
driveItem.SetUIHidden(false)
}
Expand Down
3 changes: 3 additions & 0 deletions services/graph/pkg/service/v0/sharedwithme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ var _ = Describe("SharedWithMe", func() {
Permissions: roleconversions.NewViewerRole(true).CS3ResourcePermissions(),
},
Creator: getUserResponseShareCreator.User.Id,
Ctime: utils.TSNow(),
},
MountPoint: &providerv1beta1.Reference{
ResourceId: &providerv1beta1.ResourceId{
Expand Down Expand Up @@ -213,6 +214,7 @@ var _ = Describe("SharedWithMe", func() {
Hidden: true,
Share: &collaborationv1beta1.Share{
ResourceId: toResourceID("7$8!9"),
Ctime: utils.TSNow(),
},
})

Expand Down Expand Up @@ -405,6 +407,7 @@ var _ = Describe("SharedWithMe", func() {
Permissions: roleconversions.NewViewerRole(true).CS3ResourcePermissions(),
},
Creator: getUserResponseShareCreator.User.Id,
Ctime: utils.TSNow(),
Grantee: &providerv1beta1.Grantee{
Type: providerv1beta1.GranteeType_GRANTEE_TYPE_GROUP,
Id: &providerv1beta1.Grantee_GroupId{
Expand Down

0 comments on commit 49362dc

Please sign in to comment.