Merge branch 'master' into toggle-unified-roles
This commit is contained in:
@@ -109,6 +109,22 @@ func userIdToIdentity(ctx context.Context, cache identity.IdentityCache, userID
|
||||
user, err := cache.GetUser(ctx, userID)
|
||||
if err == nil {
|
||||
identity.SetDisplayName(user.GetDisplayName())
|
||||
identity.SetLibreGraphUserType(user.GetUserType())
|
||||
}
|
||||
return identity, err
|
||||
}
|
||||
|
||||
// federatedIdToIdentity looks the user for the supplied id using the cache and returns it
|
||||
// as a libregraph.Identity
|
||||
func federatedIdToIdentity(ctx context.Context, cache identity.IdentityCache, userID string) (libregraph.Identity, error) {
|
||||
identity := libregraph.Identity{
|
||||
Id: libregraph.PtrString(userID),
|
||||
LibreGraphUserType: libregraph.PtrString("Federated"),
|
||||
}
|
||||
user, err := cache.GetAcceptedUser(ctx, userID)
|
||||
if err == nil {
|
||||
identity.SetDisplayName(user.GetDisplayName())
|
||||
identity.SetLibreGraphUserType(user.GetUserType())
|
||||
}
|
||||
return identity, err
|
||||
}
|
||||
@@ -116,6 +132,9 @@ func userIdToIdentity(ctx context.Context, cache identity.IdentityCache, userID
|
||||
// cs3UserIdToIdentity looks up the user for the supplied cs3 userid using the cache and returns it
|
||||
// as a libregraph.Identity. Skips the user lookup if the id type is USER_TYPE_SPACE_OWNER
|
||||
func cs3UserIdToIdentity(ctx context.Context, cache identity.IdentityCache, cs3UserID *cs3User.UserId) (libregraph.Identity, error) {
|
||||
if cs3UserID.GetType() == cs3User.UserType_USER_TYPE_FEDERATED {
|
||||
return federatedIdToIdentity(ctx, cache, cs3UserID.GetOpaqueId())
|
||||
}
|
||||
if cs3UserID.GetType() != cs3User.UserType_USER_TYPE_SPACE_OWNER {
|
||||
return userIdToIdentity(ctx, cache, cs3UserID.GetOpaqueId())
|
||||
}
|
||||
@@ -434,6 +453,7 @@ func cs3ReceivedShareToLibreGraphPermissions(ctx context.Context, logger *log.Lo
|
||||
availableRoles,
|
||||
permissionSet,
|
||||
condition,
|
||||
false,
|
||||
)
|
||||
if role != nil {
|
||||
permission.SetRoles([]string{role.GetId()})
|
||||
@@ -479,6 +499,17 @@ func roleConditionForResourceType(ri *storageprovider.ResourceInfo) (string, err
|
||||
}
|
||||
}
|
||||
|
||||
func federatedRoleConditionForResourceType(ri *storageprovider.ResourceInfo) (string, error) {
|
||||
switch {
|
||||
case ri.Type == storageprovider.ResourceType_RESOURCE_TYPE_CONTAINER:
|
||||
return unifiedrole.UnifiedRoleConditionFolderFederatedUser, nil
|
||||
case ri.Type == storageprovider.ResourceType_RESOURCE_TYPE_FILE:
|
||||
return unifiedrole.UnifiedRoleConditionFileFederatedUser, nil
|
||||
default:
|
||||
return "", errorcode.New(errorcode.InvalidRequest, "unsupported resource type for federated role")
|
||||
}
|
||||
}
|
||||
|
||||
// ExtractShareIdFromResourceId is a bit of a hack.
|
||||
// We should not rely on a specific format of the item id.
|
||||
// But currently there is no other way to get the ShareID.
|
||||
@@ -752,36 +783,43 @@ func fillDriveItemPropertiesFromReceivedOCMShare(ctx context.Context, logger *lo
|
||||
|
||||
func cs3ReceivedOCMShareToLibreGraphPermissions(ctx context.Context, logger *log.Logger,
|
||||
identityCache identity.IdentityCache, receivedShare *ocm.ReceivedShare,
|
||||
_ *storageprovider.ResourceInfo) (*libregraph.Permission, error) {
|
||||
resourceInfo *storageprovider.ResourceInfo) (*libregraph.Permission, error) {
|
||||
permission := libregraph.NewPermission()
|
||||
if id := receivedShare.GetId().GetOpaqueId(); id != "" {
|
||||
permission.SetId(id)
|
||||
}
|
||||
|
||||
if cTime := receivedShare.GetCtime(); cTime != nil {
|
||||
permission.SetCreatedDateTime(cs3TimestampToTime(cTime))
|
||||
}
|
||||
|
||||
if expiration := receivedShare.GetExpiration(); expiration != nil {
|
||||
permission.SetExpirationDateTime(cs3TimestampToTime(expiration))
|
||||
}
|
||||
|
||||
/*
|
||||
if permissionSet := receivedShare.GetShare().GetPermissions().GetPermissions(); permissionSet != nil {
|
||||
condition, err := roleConditionForResourceType(resourceInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
role := unifiedrole.CS3ResourcePermissionsToUnifiedRole(*permissionSet, condition)
|
||||
|
||||
if role != nil {
|
||||
permission.SetRoles([]string{role.GetId()})
|
||||
}
|
||||
|
||||
actions := unifiedrole.CS3ResourcePermissionsToLibregraphActions(*permissionSet)
|
||||
|
||||
// actions only make sense if no role is set
|
||||
if role == nil && len(actions) > 0 {
|
||||
permission.SetLibreGraphPermissionsActions(actions)
|
||||
}
|
||||
var permissions *storageprovider.ResourcePermissions
|
||||
for _, protocol := range receivedShare.GetProtocols() {
|
||||
if protocol.GetWebdavOptions().GetPermissions() != nil {
|
||||
permissions = protocol.GetWebdavOptions().GetPermissions().GetPermissions()
|
||||
}
|
||||
*/
|
||||
}
|
||||
condition, err := federatedRoleConditionForResourceType(resourceInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
role := unifiedrole.CS3ResourcePermissionsToUnifiedRole(
|
||||
permissions,
|
||||
condition,
|
||||
true,
|
||||
)
|
||||
if role != nil {
|
||||
permission.SetRoles([]string{role.GetId()})
|
||||
} else {
|
||||
actions := unifiedrole.CS3ResourcePermissionsToLibregraphActions(permissions)
|
||||
permission.SetLibreGraphPermissionsActions(actions)
|
||||
permission.SetRoles(nil)
|
||||
}
|
||||
|
||||
switch grantee := receivedShare.GetGrantee(); {
|
||||
case grantee.GetType() == storageprovider.GranteeType_GRANTEE_TYPE_USER:
|
||||
user, err := cs3UserIdToIdentity(ctx, identityCache, grantee.GetUserId())
|
||||
|
||||
Reference in New Issue
Block a user