mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-22 05:29:01 -06:00
* bump libregraph-go lib Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * add appRoleAssignment stubs Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * add get application stub Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * fetch appRoles for application from settings service Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * initial list appRoleAssignments implementation Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * initial create appRoleAssignment implementation, extract assignmentToAppRoleAssignment, configurable app id and displayname Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * initial delete appRoleAssignment implementation, changed error handling and logging Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * initial expand appRoleAssignment on users Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * test user expand appRoleAssignment Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * test appRoleAssignment Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * fix education test by actually using the mocked roleManager Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * test getapplication Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * list assignments Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * use common not exists error handling Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * default to just 'ownCloud Infinite Scale' as application name Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * fix store_test Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * roll application uuid on init Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * fix tests Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * extract method Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * Apply suggestions from code review Co-authored-by: Michael Barz <mbarz@owncloud.com> Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> Co-authored-by: Michael Barz <mbarz@owncloud.com>
73 lines
2.5 KiB
Go
73 lines
2.5 KiB
Go
package store
|
|
|
|
import (
|
|
settingsmsg "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/settings/v0"
|
|
"github.com/owncloud/ocis/v2/services/settings/pkg/settings"
|
|
"github.com/owncloud/ocis/v2/services/settings/pkg/util"
|
|
)
|
|
|
|
// ListPermissionsByResource collects all permissions from the provided roleIDs that match the requested resource
|
|
func (s *Store) ListPermissionsByResource(resource *settingsmsg.Resource, roleIDs []string) ([]*settingsmsg.Permission, error) {
|
|
records := make([]*settingsmsg.Permission, 0)
|
|
for _, roleID := range roleIDs {
|
|
role, err := s.ReadBundle(roleID)
|
|
if err != nil {
|
|
s.Logger.Debug().Str("roleID", roleID).Msg("role not found, skipping")
|
|
continue
|
|
}
|
|
records = append(records, extractPermissionsByResource(resource, role)...)
|
|
}
|
|
return records, nil
|
|
}
|
|
|
|
// ReadPermissionByID finds the permission in the roles, specified by the provided roleIDs
|
|
func (s *Store) ReadPermissionByID(permissionID string, roleIDs []string) (*settingsmsg.Permission, error) {
|
|
for _, roleID := range roleIDs {
|
|
role, err := s.ReadBundle(roleID)
|
|
if err != nil {
|
|
s.Logger.Debug().Str("roleID", roleID).Msg("role not found, skipping")
|
|
continue
|
|
}
|
|
for _, permission := range role.Settings {
|
|
if permission.Id == permissionID {
|
|
if value, ok := permission.Value.(*settingsmsg.Setting_PermissionValue); ok {
|
|
return value.PermissionValue, nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
// ReadPermissionByName finds the permission in the roles, specified by the provided roleIDs
|
|
func (s *Store) ReadPermissionByName(name string, roleIDs []string) (*settingsmsg.Permission, error) {
|
|
for _, roleID := range roleIDs {
|
|
role, err := s.ReadBundle(roleID)
|
|
if err != nil {
|
|
s.Logger.Debug().Str("roleID", roleID).Msg("role not found, skipping")
|
|
continue
|
|
}
|
|
for _, permission := range role.Settings {
|
|
if permission.Name == name {
|
|
if value, ok := permission.Value.(*settingsmsg.Setting_PermissionValue); ok {
|
|
return value.PermissionValue, nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return nil, settings.ErrNotFound
|
|
}
|
|
|
|
// extractPermissionsByResource collects all permissions from the provided role that match the requested resource
|
|
func extractPermissionsByResource(resource *settingsmsg.Resource, role *settingsmsg.Bundle) []*settingsmsg.Permission {
|
|
permissions := make([]*settingsmsg.Permission, 0)
|
|
for _, setting := range role.Settings {
|
|
if value, ok := setting.Value.(*settingsmsg.Setting_PermissionValue); ok {
|
|
if util.IsResourceMatched(setting.Resource, resource) {
|
|
permissions = append(permissions, value.PermissionValue)
|
|
}
|
|
}
|
|
}
|
|
return permissions
|
|
}
|