public async Task <XResult <bool> > _validateContextChain(XSecurityContext context, Guid userId, int securityTypes) { if (context.Members.Contains(userId) && (context.Permissions & securityTypes) != 0) { return(new XResult <bool>(true, true, $"Authorised by {context.Name} ({context.Id})")); } var parent = await GetParentContext(context.Id); if (!parent || parent.Object == null) { return (XResult <bool> .GetNotAuthorised( $"Could not find parent context on context {context.Name} ({context.Id}). looking for permisssions {securityTypes} ")); } var c = await _validateContextChain(parent.Object, userId, securityTypes); if (c) { return(c); } return (XResult <bool> .GetNotAuthorised( $"Could not find parent context on context {context.Name} ({context.Id}). looking for permisssions {securityTypes} (last try)")); }
public async Task <XResult <XSecurityContext> > GetAccess(Guid userId, List <XSecurityContext> context, int securityTypes) { if (context == null || context.Count == 0) { return(XResult <XSecurityContext> .GetNotAuthorised("GetAccess - Context was null")); } foreach (var xSecurityContext in context) { var validatedChainResult = await _validateContextChain(xSecurityContext, userId, securityTypes); if (validatedChainResult) { return(new XResult <XSecurityContext>(xSecurityContext, true, validatedChainResult.Message)); } } return(XResult <XSecurityContext> .GetNotAuthorised($"No access chains success user:{userId}, permissions: {securityTypes}. {context.Count} contexts searched")); }