mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-12 00:19:08 +02:00
[management] user info with role permissions
This commit is contained in:
@@ -20,6 +20,8 @@ type Manager interface {
|
||||
ValidateUserPermissions(ctx context.Context, accountID, userID string, module modules.Module, operation operations.Operation) (bool, error)
|
||||
ValidateRoleModuleAccess(ctx context.Context, accountID string, role roles.RolePermissions, module modules.Module, operation operations.Operation) bool
|
||||
ValidateAccountAccess(ctx context.Context, accountID string, user *types.User, allowOwnerAndAdmin bool) error
|
||||
|
||||
GetRolePermissions(ctx context.Context, role types.UserRole) (roles.RolePermissions, error)
|
||||
}
|
||||
|
||||
type managerImpl struct {
|
||||
@@ -64,9 +66,9 @@ func (m *managerImpl) ValidateUserPermissions(
|
||||
return true, nil // this should be replaced by proper granular access role
|
||||
}
|
||||
|
||||
role, ok := roles.RolesMap[user.Role]
|
||||
if !ok {
|
||||
return false, status.NewUserRoleNotFoundError(string(user.Role))
|
||||
role, err := m.GetRolePermissions(ctx, user.Role)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return m.ValidateRoleModuleAccess(ctx, accountID, role, module, operation), nil
|
||||
@@ -96,3 +98,12 @@ func (m *managerImpl) ValidateAccountAccess(ctx context.Context, accountID strin
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *managerImpl) GetRolePermissions(ctx context.Context, role types.UserRole) (roles.RolePermissions, error) {
|
||||
permissions, ok := roles.RolesMap[role]
|
||||
if !ok {
|
||||
return roles.RolePermissions{}, status.NewUserRoleNotFoundError(string(role))
|
||||
}
|
||||
|
||||
return permissions, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user