From 5cfb0fca1a4e368f145468abefa713f043364b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Tue, 10 Nov 2026 15:56:52 +0100 Subject: [PATCH] fix(graph): list permissions when public shares are inaccessible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../service/v0/api_driveitem_permissions.go | 8 +++- .../v0/api_driveitem_permissions_test.go | 43 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/services/graph/pkg/service/v0/api_driveitem_permissions.go b/services/graph/pkg/service/v0/api_driveitem_permissions.go index 1bc0ac7e60..0a95df033c 100644 --- a/services/graph/pkg/service/v0/api_driveitem_permissions.go +++ b/services/graph/pkg/service/v0/api_driveitem_permissions.go @@ -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 } diff --git a/services/graph/pkg/service/v0/api_driveitem_permissions_test.go b/services/graph/pkg/service/v0/api_driveitem_permissions_test.go index c5bce19f34..c7743aef48 100644 --- a/services/graph/pkg/service/v0/api_driveitem_permissions_test.go +++ b/services/graph/pkg/service/v0/api_driveitem_permissions_test.go @@ -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