From 21222ff97f485acde8de3ab2d4098b5030a21c0c Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Wed, 13 Mar 2024 19:03:27 +0100 Subject: [PATCH] enhancement(sharing): Return space permissions when looking up space root Partial-Fix: #8352 --- services/graph/pkg/service/v0/driveitems.go | 65 +++++++++++++++------ 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/services/graph/pkg/service/v0/driveitems.go b/services/graph/pkg/service/v0/driveitems.go index f6dd52b0a5b..90aee9b30e0 100644 --- a/services/graph/pkg/service/v0/driveitems.go +++ b/services/graph/pkg/service/v0/driveitems.go @@ -407,25 +407,56 @@ func (g Graph) ListPermissions(w http.ResponseWriter, r *http.Request) { collectionOfPermissions.LibreGraphPermissionsRolesAllowedValues[i] = definition } - driveItems := make(driveItemsByResourceID) - driveItems, err = g.listUserShares(ctx, []*collaboration.Filter{ - share.ResourceIDFilter(conversions.ToPointer(itemID)), - }, driveItems) - if err != nil { - errorcode.RenderError(w, r, err) - return - } + if IsSpaceRoot(statResponse.GetInfo().GetId()) { + // this is a space root, get permissions via storage space API + filters := []*storageprovider.ListStorageSpacesRequest_Filter{ + listStorageSpacesIDFilter(statResponse.GetInfo().GetSpace().GetId().GetOpaqueId()), + } + res, err := g.ListStorageSpacesWithFilters(ctx, filters, true) + switch { + case err != nil: + g.logger.Error().Err(err).Msg("could not get drive: transport error") + errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error()) + return + case res.Status.Code != cs3rpc.Code_CODE_OK: + if res.Status.Code == cs3rpc.Code_CODE_NOT_FOUND { + // the client is doing a lookup for a specific space, therefore we need to return + // not found to the caller + g.logger.Debug().Msg("could not get drive: not found") + errorcode.ItemNotFound.Render(w, r, http.StatusNotFound, "drive not found") + return + } + g.logger.Debug(). + Str("grpcmessage", res.GetStatus().GetMessage()). + Msg("could not get drive: grpc error") + errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, res.Status.Message) + return + } + permissions := g.cs3PermissionsToLibreGraph(ctx, res.GetStorageSpaces()[0], APIVersion_1_Beta_1) + collectionOfPermissions.Value = permissions + } else { + // "normal" driveItem, populate permissions via share providers - driveItems, err = g.listPublicShares(ctx, []*link.ListPublicSharesRequest_Filter{ - publicshare.ResourceIDFilter(conversions.ToPointer(itemID)), - }, driveItems) - if err != nil { - errorcode.RenderError(w, r, err) - return - } + driveItems := make(driveItemsByResourceID) + driveItems, err = g.listUserShares(ctx, []*collaboration.Filter{ + share.ResourceIDFilter(conversions.ToPointer(itemID)), + }, driveItems) + if err != nil { + errorcode.RenderError(w, r, err) + return + } - for _, driveItem := range driveItems { - collectionOfPermissions.Value = append(collectionOfPermissions.Value, driveItem.Permissions...) + driveItems, err = g.listPublicShares(ctx, []*link.ListPublicSharesRequest_Filter{ + publicshare.ResourceIDFilter(conversions.ToPointer(itemID)), + }, driveItems) + if err != nil { + errorcode.RenderError(w, r, err) + return + } + + for _, driveItem := range driveItems { + collectionOfPermissions.Value = append(collectionOfPermissions.Value, driveItem.Permissions...) + } } render.Status(r, http.StatusOK)