mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-03 01:09:54 -05:00
graph/sharedWithMe: separate method for converting CS3 share to libregraph
For readability and reduced complexity of the sharedWithMe method. It was getting too large already.
This commit is contained in:
committed by
Ralf Haferkamp
parent
cfba9f29cc
commit
dd61270e7d
@@ -79,63 +79,9 @@ func (g Graph) listSharedWithMe(ctx context.Context) ([]libregraph.DriveItem, er
|
||||
return err
|
||||
}
|
||||
|
||||
permission := libregraph.NewPermission()
|
||||
{
|
||||
if id := receivedShare.GetShare().GetId().GetOpaqueId(); id != "" {
|
||||
permission.SetId(id)
|
||||
}
|
||||
|
||||
if expiration := receivedShare.GetShare().GetExpiration(); expiration != nil {
|
||||
permission.SetExpirationDateTime(cs3TimestampToTime(expiration))
|
||||
}
|
||||
|
||||
if permissionSet := shareStat.GetInfo().GetPermissionSet(); permissionSet != nil {
|
||||
role := unifiedrole.CS3ResourcePermissionsToUnifiedRole(
|
||||
*permissionSet,
|
||||
unifiedrole.UnifiedRoleConditionGrantee,
|
||||
g.config.FilesSharing.EnableResharing,
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
switch grantee := receivedShare.GetShare().GetGrantee(); {
|
||||
case grantee.GetType() == storageprovider.GranteeType_GRANTEE_TYPE_USER:
|
||||
user, err := g.identityCache.GetUser(ctx, grantee.GetUserId().GetOpaqueId())
|
||||
if err != nil {
|
||||
g.logger.Error().Err(err).Msg("could not get user")
|
||||
return err
|
||||
}
|
||||
|
||||
permission.SetGrantedToV2(libregraph.SharePointIdentitySet{
|
||||
User: &libregraph.Identity{
|
||||
DisplayName: user.GetDisplayName(),
|
||||
Id: user.Id,
|
||||
},
|
||||
})
|
||||
case grantee.GetType() == storageprovider.GranteeType_GRANTEE_TYPE_GROUP:
|
||||
group, err := g.identityCache.GetGroup(ctx, grantee.GetGroupId().GetOpaqueId())
|
||||
if err != nil {
|
||||
g.logger.Error().Err(err).Msg("could not get group")
|
||||
return err
|
||||
}
|
||||
|
||||
permission.SetGrantedToV2(libregraph.SharePointIdentitySet{
|
||||
Group: &libregraph.Identity{
|
||||
DisplayName: group.GetDisplayName(),
|
||||
Id: group.Id,
|
||||
},
|
||||
})
|
||||
}
|
||||
permission, err := g.cs3ShareToLibreGraphPermissions(ctx, receivedShare.GetShare(), shareStat.GetInfo())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
parentReference := libregraph.NewItemReference()
|
||||
@@ -314,3 +260,63 @@ func (g Graph) listSharedWithMe(ctx context.Context) ([]libregraph.DriveItem, er
|
||||
return reflect.ValueOf(item).IsZero()
|
||||
})), err
|
||||
}
|
||||
|
||||
func (g Graph) cs3ShareToLibreGraphPermissions(ctx context.Context, share *collaboration.Share, shareStatInfo *storageprovider.ResourceInfo) (*libregraph.Permission, error) {
|
||||
permission := libregraph.NewPermission()
|
||||
if id := share.GetId().GetOpaqueId(); id != "" {
|
||||
permission.SetId(id)
|
||||
}
|
||||
|
||||
if expiration := share.GetExpiration(); expiration != nil {
|
||||
permission.SetExpirationDateTime(cs3TimestampToTime(expiration))
|
||||
}
|
||||
|
||||
if permissionSet := shareStatInfo.GetPermissionSet(); permissionSet != nil {
|
||||
role := unifiedrole.CS3ResourcePermissionsToUnifiedRole(
|
||||
*permissionSet,
|
||||
unifiedrole.UnifiedRoleConditionGrantee,
|
||||
g.config.FilesSharing.EnableResharing,
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
switch grantee := share.GetGrantee(); {
|
||||
case grantee.GetType() == storageprovider.GranteeType_GRANTEE_TYPE_USER:
|
||||
user, err := g.identityCache.GetUser(ctx, grantee.GetUserId().GetOpaqueId())
|
||||
if err != nil {
|
||||
g.logger.Error().Err(err).Msg("could not get user")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
permission.SetGrantedToV2(libregraph.SharePointIdentitySet{
|
||||
User: &libregraph.Identity{
|
||||
DisplayName: user.GetDisplayName(),
|
||||
Id: user.Id,
|
||||
},
|
||||
})
|
||||
case grantee.GetType() == storageprovider.GranteeType_GRANTEE_TYPE_GROUP:
|
||||
group, err := g.identityCache.GetGroup(ctx, grantee.GetGroupId().GetOpaqueId())
|
||||
if err != nil {
|
||||
g.logger.Error().Err(err).Msg("could not get group")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
permission.SetGrantedToV2(libregraph.SharePointIdentitySet{
|
||||
Group: &libregraph.Identity{
|
||||
DisplayName: group.GetDisplayName(),
|
||||
Id: group.Id,
|
||||
},
|
||||
})
|
||||
}
|
||||
return permission, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user