chore: merge master
This commit is contained in:
@@ -25,6 +25,7 @@ import (
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/render"
|
||||
libregraph "github.com/owncloud/libre-graph-api-go"
|
||||
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/l10n"
|
||||
l10n_pkg "github.com/owncloud/ocis/v2/services/graph/pkg/l10n"
|
||||
|
||||
@@ -227,7 +228,7 @@ func (s DriveItemPermissionsService) Invite(ctx context.Context, resourceId *sto
|
||||
} else if IsSpaceRoot(statResponse.GetInfo().GetId()) {
|
||||
// permissions on a space root are not handled by a share manager so
|
||||
// they don't get a share-id
|
||||
permission.SetId(identitySetToSpacePermissionID(permission.GetGrantedToV2(), s.config.UnifiedRoles.AvailableRoles))
|
||||
permission.SetId(identitySetToSpacePermissionID(permission.GetGrantedToV2()))
|
||||
}
|
||||
|
||||
if expiration != nil {
|
||||
|
||||
@@ -95,7 +95,8 @@ func (g BaseGraphService) CS3ReceivedOCMSharesToDriveItems(ctx context.Context,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return cs3ReceivedOCMSharesToDriveItems(ctx, g.logger, gatewayClient, g.identityCache, receivedShares)
|
||||
availableRoles := unifiedrole.GetRoles(unifiedrole.RoleFilterIDs(g.config.UnifiedRoles.AvailableRoles...))
|
||||
return cs3ReceivedOCMSharesToDriveItems(ctx, g.logger, gatewayClient, g.identityCache, receivedShares, availableRoles)
|
||||
}
|
||||
|
||||
func (g BaseGraphService) cs3SpacePermissionsToLibreGraph(ctx context.Context, space *storageprovider.StorageSpace, apiVersion APIVersion) []libregraph.Permission {
|
||||
@@ -184,7 +185,7 @@ func (g BaseGraphService) cs3SpacePermissionsToLibreGraph(ctx context.Context, s
|
||||
} else {
|
||||
identitySet.SetUser(identity)
|
||||
}
|
||||
p.SetId(identitySetToSpacePermissionID(identitySet, g.config.UnifiedRoles.AvailableRoles))
|
||||
p.SetId(identitySetToSpacePermissionID(identitySet))
|
||||
p.SetGrantedToV2(identitySet)
|
||||
}
|
||||
|
||||
@@ -554,7 +555,9 @@ func (g BaseGraphService) cs3OCMShareToPermission(ctx context.Context, share *oc
|
||||
}
|
||||
}
|
||||
|
||||
role := unifiedrole.CS3ResourcePermissionsToUnifiedRole(
|
||||
availableRoles := unifiedrole.GetRoles(unifiedrole.RoleFilterIDs(g.config.UnifiedRoles.AvailableRoles...))
|
||||
role := unifiedrole.CS3ResourcePermissionsToRole(
|
||||
availableRoles,
|
||||
permissions,
|
||||
roleCondition,
|
||||
true,
|
||||
|
||||
@@ -53,7 +53,7 @@ func (g Graph) listSharedWithMe(ctx context.Context) ([]libregraph.DriveItem, er
|
||||
g.logger.Error().Err(err).Msg("listing shares failed")
|
||||
return nil, err
|
||||
}
|
||||
ocmDriveItems, err := cs3ReceivedOCMSharesToDriveItems(ctx, g.logger, gatewayClient, g.identityCache, listReceivedOCMSharesResponse.GetShares())
|
||||
ocmDriveItems, err := cs3ReceivedOCMSharesToDriveItems(ctx, g.logger, gatewayClient, g.identityCache, listReceivedOCMSharesResponse.GetShares(), availableRoles)
|
||||
if err != nil {
|
||||
g.logger.Error().Err(err).Msg("could not convert received shares to drive items")
|
||||
return nil, err
|
||||
|
||||
@@ -159,7 +159,7 @@ func groupIdToIdentity(ctx context.Context, cache identity.IdentityCache, groupI
|
||||
// As permissions on space to not map to a cs3 share we need something else of the ids. So we just
|
||||
// construct the id for the id of the user or group that the permission applies to and prefix that
|
||||
// with a "u:" for userids and "g:" for group ids.
|
||||
func identitySetToSpacePermissionID(identitySet libregraph.SharePointIdentitySet, allowedRoleIDs []string) (id string) {
|
||||
func identitySetToSpacePermissionID(identitySet libregraph.SharePointIdentitySet) (id string) {
|
||||
switch {
|
||||
case identitySet.HasUser():
|
||||
id = "u:" + identitySet.User.GetId()
|
||||
@@ -523,7 +523,7 @@ func cs3ReceivedOCMSharesToDriveItems(ctx context.Context,
|
||||
logger *log.Logger,
|
||||
gatewayClient gateway.GatewayAPIClient,
|
||||
identityCache identity.IdentityCache,
|
||||
receivedShares []*ocm.ReceivedShare) ([]libregraph.DriveItem, error) {
|
||||
receivedShares []*ocm.ReceivedShare, availableRoles []*libregraph.UnifiedRoleDefinition) ([]libregraph.DriveItem, error) {
|
||||
|
||||
group := new(errgroup.Group)
|
||||
// Set max concurrency
|
||||
@@ -567,7 +567,7 @@ func cs3ReceivedOCMSharesToDriveItems(ctx context.Context,
|
||||
return errCode
|
||||
}
|
||||
|
||||
driveItem, err := fillDriveItemPropertiesFromReceivedOCMShare(ctx, logger, identityCache, receivedShares, shareStat.GetInfo())
|
||||
driveItem, err := fillDriveItemPropertiesFromReceivedOCMShare(ctx, logger, identityCache, receivedShares, shareStat.GetInfo(), availableRoles)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -704,7 +704,7 @@ func cs3ReceivedOCMSharesToDriveItems(ctx context.Context,
|
||||
|
||||
func fillDriveItemPropertiesFromReceivedOCMShare(ctx context.Context, logger *log.Logger,
|
||||
identityCache identity.IdentityCache, receivedShares []*ocm.ReceivedShare,
|
||||
resourceInfo *storageprovider.ResourceInfo) (*libregraph.DriveItem, error) {
|
||||
resourceInfo *storageprovider.ResourceInfo, availableRoles []*libregraph.UnifiedRoleDefinition) (*libregraph.DriveItem, error) {
|
||||
|
||||
driveItem := libregraph.NewDriveItem()
|
||||
permissions := make([]libregraph.Permission, 0, len(receivedShares))
|
||||
@@ -718,7 +718,7 @@ func fillDriveItemPropertiesFromReceivedOCMShare(ctx context.Context, logger *lo
|
||||
oldestReceivedShare = receivedShare
|
||||
}
|
||||
|
||||
permission, err := cs3ReceivedOCMShareToLibreGraphPermissions(ctx, logger, identityCache, receivedShare, resourceInfo)
|
||||
permission, err := cs3ReceivedOCMShareToLibreGraphPermissions(ctx, logger, identityCache, receivedShare, resourceInfo, availableRoles)
|
||||
if err != nil {
|
||||
return driveItem, err
|
||||
}
|
||||
@@ -783,7 +783,7 @@ func fillDriveItemPropertiesFromReceivedOCMShare(ctx context.Context, logger *lo
|
||||
|
||||
func cs3ReceivedOCMShareToLibreGraphPermissions(ctx context.Context, logger *log.Logger,
|
||||
identityCache identity.IdentityCache, receivedShare *ocm.ReceivedShare,
|
||||
resourceInfo *storageprovider.ResourceInfo) (*libregraph.Permission, error) {
|
||||
resourceInfo *storageprovider.ResourceInfo, availableRoles []*libregraph.UnifiedRoleDefinition) (*libregraph.Permission, error) {
|
||||
permission := libregraph.NewPermission()
|
||||
if id := receivedShare.GetId().GetOpaqueId(); id != "" {
|
||||
permission.SetId(id)
|
||||
@@ -807,7 +807,8 @@ func cs3ReceivedOCMShareToLibreGraphPermissions(ctx context.Context, logger *log
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
role := unifiedrole.CS3ResourcePermissionsToUnifiedRole(
|
||||
role := unifiedrole.CS3ResourcePermissionsToRole(
|
||||
availableRoles,
|
||||
permissions,
|
||||
condition,
|
||||
true,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package unifiedrole
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
"github.com/cs3org/reva/v2/pkg/conversions"
|
||||
libregraph "github.com/owncloud/libre-graph-api-go"
|
||||
@@ -143,7 +145,7 @@ func CS3ResourcePermissionsToLibregraphActions(p *provider.ResourcePermissions)
|
||||
}
|
||||
|
||||
// CS3ResourcePermissionsToRole converts the provided cs3 ResourcePermissions to a libregraph UnifiedRoleDefinition
|
||||
func CS3ResourcePermissionsToRole(roleSet []*libregraph.UnifiedRoleDefinition, p *provider.ResourcePermissions, constraints string) *libregraph.UnifiedRoleDefinition {
|
||||
func CS3ResourcePermissionsToRole(roleSet []*libregraph.UnifiedRoleDefinition, p *provider.ResourcePermissions, constraints string, listFederatedRoles bool) *libregraph.UnifiedRoleDefinition {
|
||||
actionSet := map[string]struct{}{}
|
||||
for _, action := range CS3ResourcePermissionsToLibregraphActions(p) {
|
||||
actionSet[action] = struct{}{}
|
||||
@@ -151,20 +153,27 @@ func CS3ResourcePermissionsToRole(roleSet []*libregraph.UnifiedRoleDefinition, p
|
||||
|
||||
var res *libregraph.UnifiedRoleDefinition
|
||||
for _, uRole := range roleSet {
|
||||
matchFound := false
|
||||
for _, uPerm := range uRole.GetRolePermissions() {
|
||||
if uPerm.GetCondition() != constraints {
|
||||
// the requested constraints don't match, this isn't our role
|
||||
definitionMatch := false
|
||||
|
||||
for _, permission := range uRole.GetRolePermissions() {
|
||||
// this is a dirty comparison because we are not really parsing the SDDL, but as long as we && the conditions we are good
|
||||
isFederatedRole := strings.Contains(permission.GetCondition(), UnifiedRoleConditionFederatedUser)
|
||||
switch {
|
||||
case !strings.Contains(permission.GetCondition(), constraints):
|
||||
continue
|
||||
case listFederatedRoles && !isFederatedRole:
|
||||
continue
|
||||
case !listFederatedRoles && isFederatedRole:
|
||||
continue
|
||||
}
|
||||
|
||||
// if the actions converted from the ResourcePermissions equal the action the defined for the role, we have match
|
||||
if resourceActionsEqual(actionSet, uPerm.GetAllowedResourceActions()) {
|
||||
matchFound = true
|
||||
if resourceActionsEqual(actionSet, permission.GetAllowedResourceActions()) {
|
||||
definitionMatch = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if matchFound {
|
||||
if definitionMatch {
|
||||
res = uRole
|
||||
break
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ func TestCS3ResourcePermissionsToRole(t *testing.T) {
|
||||
for name, tc := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
NewWithT(t).Expect(
|
||||
unifiedrole.CS3ResourcePermissionsToRole(unifiedrole.BuildInRoles, tc.cs3ResourcePermissions, tc.constraints),
|
||||
unifiedrole.CS3ResourcePermissionsToRole(unifiedrole.BuildInRoles, tc.cs3ResourcePermissions, tc.constraints, false),
|
||||
).To(Equal(tc.unifiedRoleDefinition))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user