fix(graph): list permissions when public shares are inaccessible

When the public share manager cannot access its metadata space, e.g.
after an upgrade, listing public shares fails with an already exists
error and the whole permissions request ended in a 500. The space
members dialog in web then just keeps spinning.

We now log a warning, skip the link permissions and still return the
user and space permissions.

Our reva currently replaces the original error with a generic "error
listing public shares", so this only takes effect together with the
port of `owncloud/reva#264`, which passes the error message through.

ported from `owncloud/ocis#11245`

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
Jörn Friedrich Dreyer committed 2026-11-13 18:18:31 +01:00
1 parent 4bb1feef67
commit 5cfb0fca1a
2 files changed
+50 -1

No files matched your search

@@ -23,6 +23,7 @@ import (
"github.com/go-chi/render"
libregraph "github.com/opencloud-eu/libre-graph-api-go"
revactx "github.com/opencloud-eu/reva/v2/pkg/ctx"
"github.com/opencloud-eu/reva/v2/pkg/errtypes"
"github.com/opencloud-eu/reva/v2/pkg/publicshare"
"github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool"
"github.com/opencloud-eu/reva/v2/pkg/share"
@@ -633,7 +634,12 @@ func (s DriveItemPermissionsService) ListPermissions(ctx context.Context, itemID
driveItems, err = s.listPublicShares(ctx, []*link.ListPublicSharesRequest_Filter{
publicshare.ResourceIDFilter(itemID),
}, driveItems)
if err != nil {
switch {
case err != nil && strings.Contains(err.Error(), errtypes.AlreadyExists("").Error()):
// the public share manager reports an already exists error when its metadata space is
// not accessible, e.g. after an upgrade. Still list the user and space permissions.
logger.Warn().Err(err).Str(_logKeyItemID, storagespace.FormatResourceID(itemID)).Msg("could not list public shares, skipping link permissions")
case err != nil:
errorEvent(&logger, err).Str(_logKeyItemID, storagespace.FormatResourceID(itemID)).Msg("could not list public shares")
return collectionOfPermissions, err
}
@@ -42,6 +42,7 @@ import (
roleconversions "github.com/opencloud-eu/reva/v2/pkg/conversions"
revactx "github.com/opencloud-eu/reva/v2/pkg/ctx"
"github.com/opencloud-eu/reva/v2/pkg/errtypes"
"github.com/opencloud-eu/reva/v2/pkg/rgrpc/status"
"github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool"
"github.com/opencloud-eu/reva/v2/pkg/storagespace"
@@ -1771,6 +1772,48 @@ var _ = Describe("DriveItemPermissionsService", func() {
Expect(len(permissions.LibreGraphPermissionsRolesAllowedValues)).ToNot(BeZero())
Expect(len(permissions.Value)).To(Equal(2))
})
It("still returns the user shares when listing public shares reports an already exists error", func() {
statResponse.Info.PermissionSet = roleconversions.NewEditorRole().CS3ResourcePermissions()
listSharesResponse.Shares = []*collaboration.Share{
{
Id: &collaboration.ShareId{OpaqueId: "1"},
Permissions: &collaboration.SharePermissions{
Permissions: roleconversions.NewViewerRole().CS3ResourcePermissions(),
},
ResourceId: &provider.ResourceId{
StorageId: "1",
SpaceId: "2",
OpaqueId: "3",
},
Grantee: &provider.Grantee{
Type: provider.GranteeType_GRANTEE_TYPE_USER,
Id: &provider.Grantee_UserId{
UserId: &userpb.UserId{
OpaqueId: "user-id",
},
},
},
},
}
listPublicSharesResponse.Status = status.NewInternal(ctx, errtypes.AlreadyExists("user service-user does not have access to metadata space jsoncs3-public-share-manager-metadata, but it exists").Error())
gatewayClient.On("Stat", mock.Anything, mock.Anything).Return(statResponse, nil)
gatewayClient.On("ListShares", mock.Anything, mock.Anything).Return(listSharesResponse, nil)
gatewayClient.On("GetUser", mock.Anything, mock.Anything).Return(getUserResponse, nil)
gatewayClient.On("ListPublicShares", mock.Anything, mock.Anything).Return(listPublicSharesResponse, nil)
permissions, err := driveItemPermissionsService.ListPermissions(context.Background(), itemID, svc.ListPermissionsQueryOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(len(permissions.Value)).To(Equal(1))
})
It("fails when listing public shares fails for other reasons", func() {
listPublicSharesResponse.Status = status.NewInternal(ctx, "error listing public shares")
gatewayClient.On("Stat", mock.Anything, mock.Anything).Return(statResponse, nil)
gatewayClient.On("ListShares", mock.Anything, mock.Anything).Return(listSharesResponse, nil)
gatewayClient.On("ListPublicShares", mock.Anything, mock.Anything).Return(listPublicSharesResponse, nil)
_, err := driveItemPermissionsService.ListPermissions(context.Background(), itemID, svc.ListPermissionsQueryOptions{})
Expect(err).To(HaveOccurred())
})
It("returns role denied", func() {
statResponse.Info.PermissionSet = roleconversions.NewManagerRole().CS3ResourcePermissions()
statResponse.Info.Type = provider.ResourceType_RESOURCE_TYPE_CONTAINER