@@ -51,8 +51,8 @@ const (
5151type DriveItemPermissionsProvider interface {
5252 Invite (ctx context.Context , resourceId * storageprovider.ResourceId , invite libregraph.DriveItemInvite ) (libregraph.Permission , error )
5353 SpaceRootInvite (ctx context.Context , driveID * storageprovider.ResourceId , invite libregraph.DriveItemInvite ) (libregraph.Permission , error )
54- ListPermissions (ctx context.Context , itemID * storageprovider.ResourceId , listFederatedRoles , selectRoles bool ) (libregraph.CollectionOfPermissionsWithAllowedValues , error )
55- ListSpaceRootPermissions (ctx context.Context , driveID * storageprovider.ResourceId , selectRoles bool ) (libregraph.CollectionOfPermissionsWithAllowedValues , error )
54+ ListPermissions (ctx context.Context , itemID * storageprovider.ResourceId , listFederatedRoles bool , selectedAttrs map [ string ] struct {} ) (libregraph.CollectionOfPermissionsWithAllowedValues , error )
55+ ListSpaceRootPermissions (ctx context.Context , driveID * storageprovider.ResourceId , selectedAttrs map [ string ] struct {} ) (libregraph.CollectionOfPermissionsWithAllowedValues , error )
5656 DeletePermission (ctx context.Context , itemID * storageprovider.ResourceId , permissionID string ) error
5757 DeleteSpaceRootPermission (ctx context.Context , driveID * storageprovider.ResourceId , permissionID string ) error
5858 UpdatePermission (ctx context.Context , itemID * storageprovider.ResourceId , permissionID string , newPermission libregraph.Permission ) (libregraph.Permission , error )
@@ -344,7 +344,7 @@ func (s DriveItemPermissionsService) SpaceRootInvite(ctx context.Context, driveI
344344}
345345
346346// ListPermissions lists the permissions of a driveItem
347- func (s DriveItemPermissionsService ) ListPermissions (ctx context.Context , itemID * storageprovider.ResourceId , listFederatedRoles , selectRoles bool ) (libregraph.CollectionOfPermissionsWithAllowedValues , error ) {
347+ func (s DriveItemPermissionsService ) ListPermissions (ctx context.Context , itemID * storageprovider.ResourceId , listFederatedRoles bool , selectedAttrs map [ string ] struct {} ) (libregraph.CollectionOfPermissionsWithAllowedValues , error ) {
348348 collectionOfPermissions := libregraph.CollectionOfPermissionsWithAllowedValues {}
349349 gatewayClient , err := s .gatewaySelector .Next ()
350350 if err != nil {
@@ -365,17 +365,22 @@ func (s DriveItemPermissionsService) ListPermissions(ctx context.Context, itemID
365365 permissionSet := statResponse .GetInfo ().GetPermissionSet ()
366366 allowedActions := unifiedrole .CS3ResourcePermissionsToLibregraphActions (permissionSet )
367367
368- collectionOfPermissions = libregraph.CollectionOfPermissionsWithAllowedValues {
369- LibreGraphPermissionsActionsAllowedValues : allowedActions ,
370- LibreGraphPermissionsRolesAllowedValues : conversions .ToValueSlice (
368+ collectionOfPermissions = libregraph.CollectionOfPermissionsWithAllowedValues {}
369+
370+ if _ , ok := selectedAttrs ["@libre.graph.permissions.actions.allowedValues" ]; ok || len (selectedAttrs ) == 0 {
371+ collectionOfPermissions .LibreGraphPermissionsActionsAllowedValues = allowedActions
372+ }
373+
374+ if _ , ok := selectedAttrs ["@libre.graph.permissions.roles.allowedValues" ]; ok || len (selectedAttrs ) == 0 {
375+ collectionOfPermissions .LibreGraphPermissionsRolesAllowedValues = conversions .ToValueSlice (
371376 unifiedrole .GetRolesByPermissions (
372377 unifiedrole .GetRoles (unifiedrole .RoleFilterIDs (s .config .UnifiedRoles .AvailableRoles ... )),
373378 allowedActions ,
374379 condition ,
375380 listFederatedRoles ,
376381 false ,
377382 ),
378- ),
383+ )
379384 }
380385
381386 for i , definition := range collectionOfPermissions .LibreGraphPermissionsRolesAllowedValues {
@@ -384,10 +389,8 @@ func (s DriveItemPermissionsService) ListPermissions(ctx context.Context, itemID
384389 collectionOfPermissions .LibreGraphPermissionsRolesAllowedValues [i ] = definition
385390 }
386391
387- if selectRoles {
388- // drop the actions
389- collectionOfPermissions .LibreGraphPermissionsActionsAllowedValues = nil
390- // no need to fetch shares, we are only interested in the roles
392+ if len (selectedAttrs ) > 0 {
393+ // no need to fetch shares, we are only interested allowedActions and/or allowedRoles
391394 return collectionOfPermissions , nil
392395 }
393396
@@ -441,7 +444,7 @@ func (s DriveItemPermissionsService) ListPermissions(ctx context.Context, itemID
441444}
442445
443446// ListSpaceRootPermissions handles ListPermissions request on project spaces
444- func (s DriveItemPermissionsService ) ListSpaceRootPermissions (ctx context.Context , driveID * storageprovider.ResourceId , selectRoles bool ) (libregraph.CollectionOfPermissionsWithAllowedValues , error ) {
447+ func (s DriveItemPermissionsService ) ListSpaceRootPermissions (ctx context.Context , driveID * storageprovider.ResourceId , selectedAttrs map [ string ] struct {} ) (libregraph.CollectionOfPermissionsWithAllowedValues , error ) {
445448 collectionOfPermissions := libregraph.CollectionOfPermissionsWithAllowedValues {}
446449 gatewayClient , err := s .gatewaySelector .Next ()
447450 if err != nil {
@@ -459,7 +462,7 @@ func (s DriveItemPermissionsService) ListSpaceRootPermissions(ctx context.Contex
459462 }
460463
461464 rootResourceID := space .GetRoot ()
462- return s .ListPermissions (ctx , rootResourceID , false , selectRoles ) // federated roles are not supported for spaces
465+ return s .ListPermissions (ctx , rootResourceID , false , selectedAttrs ) // federated roles are not supported for spaces
463466}
464467
465468// DeletePermission deletes a permission from a drive item
@@ -769,15 +772,15 @@ func (api DriveItemPermissionsApi) ListSpaceRootPermissions(w http.ResponseWrite
769772 return
770773 }
771774
772- selectRoles , err := api .listPermissionsQuerySelectValues (odataReq .Query )
775+ selected , err := api .listPermissionsQuerySelectValues (odataReq .Query )
773776 if err != nil {
774777 api .logger .Debug ().Err (err ).Interface ("query" , r .URL .Query ()).Msg ("Error parsing ListPermissionRequest: query error" )
775778 errorcode .InvalidRequest .Render (w , r , http .StatusBadRequest , err .Error ())
776779 return
777780 }
778781
779782 ctx := r .Context ()
780- permissions , err := api .driveItemPermissionsService .ListSpaceRootPermissions (ctx , & driveID , selectRoles )
783+ permissions , err := api .driveItemPermissionsService .ListSpaceRootPermissions (ctx , & driveID , selected )
781784
782785 if err != nil {
783786 errorcode .RenderError (w , r , err )
@@ -934,20 +937,18 @@ func (api DriveItemPermissionsApi) UpdateSpaceRootPermission(w http.ResponseWrit
934937 render .JSON (w , r , & updatedPermission )
935938}
936939
937- func (api DriveItemPermissionsApi ) listPermissionsQuerySelectValues (odataQuery * godata.GoDataQuery ) (bool , error ) {
940+ func (api DriveItemPermissionsApi ) listPermissionsQuerySelectValues (odataQuery * godata.GoDataQuery ) (map [string ]struct {}, error ) {
941+ selectedAttrs := map [string ]struct {}{}
938942 if odataQuery .Select != nil {
939943 for _ , item := range odataQuery .Select .SelectItems {
940- if len (item .Segments ) != 1 {
941- api .logger .Debug ().Msg ("Error parsing ListPermissionRequest: unsupported select item" )
942- return false , errorcode .New (errorcode .InvalidRequest , "unsupported select item" )
943- }
944- // for now we only support the select for the roles
945- if item .Segments [0 ].Value != "@libre.graph.permissions.roles.allowedValues" {
944+ // for now we only support a limitted set of $select attributes
945+ if item .Segments [0 ].Value == "@libre.graph.permissions.roles.allowedValues" || item .Segments [0 ].Value == "@libre.graph.permissions.actions.allowedValues" {
946+ selectedAttrs [item .Segments [0 ].Value ] = struct {}{}
947+ } else {
946948 api .logger .Debug ().Msg ("Error parsing ListPermissionRequest: unsupported select item" )
947- return false , errorcode .New (errorcode .InvalidRequest , "unsupported select item" )
949+ return selectedAttrs , errorcode .New (errorcode .InvalidRequest , "unsupported select item" )
948950 }
949- return true , nil
950951 }
951952 }
952- return false , nil
953+ return selectedAttrs , nil
953954}
0 commit comments