private static bool CheckDiscriminators(this IRolCan me, bool forAll, params IDiscriminator[] discriminators) { foreach (var fun in me.Functions) { var res = forAll ? discriminators.All(dis => { var pers = me.Rol.SearchPermissions(fun, dis); return(!pers.Any(p => !p.Value) && pers.Any(p => p.Value)); }) : discriminators.Any(dis => { var pers = me.Rol.SearchPermissions(fun, dis); return(!pers.Any(p => !p.Value) && pers.Any(p => p.Value)); }); if (!res) { if (me.ThrowExceptionIfCannot) { throw new UnauthorizedAccessException($"The rol '{me.Rol.Name}' cannot '{me.Functions.Aggregate("", (a, c) => a + c.Name + "·", a => a.Trim('·'))}' for the given discriminators '{discriminators.Aggregate("", (a, c) => $"{a}, {c.Name}", a => a.Trim(',', ' ')) }'"); } return(false); } } return(true); }
// -------------------------- IMPLEMENTATION private static bool CheckInstances <T>(this IRolCan me, bool forAll, params T[] values) { var res = forAll ? values.AuthorizedTo(me.Rol, me.Functions).Count() == values.Count() : values.AuthorizedTo(me.Rol, me.Functions).Any(); if (me.ThrowExceptionIfCannot && !res) { throw new UnauthorizedAccessException($"The rol '{me.Rol.Name}' cannot '{me.Functions.Aggregate("", (a, c) => a + c.Name + "·", a => a.Trim('·'))}' for the given instances '{values}'"); } return(res); }
public static bool Something(this IRolCan me) { foreach (var fun in me.Functions) { var permissions = me.Rol.SearchPermissions(fun); if (!permissions.Any())// || permissions.All(p => p.Scopes.Any())) { return(false); } } return(true); }
public static bool Something(this IRolCan me) { using (var res = Printer.CallResult <bool>()) { var ime = (IInternalRolCan)me; if (ime.Rol == null) { return(res.Value = false); } foreach (var fun in ime.Functions) { var permissions = ime.Rol.SearchPermissions(false, fun, TypeDiscriminator.Empty); if (!permissions.Any(p => p.Value)) { return(res.Value = false); } } return(res.Value = true); } }
public static bool AnyInstances <T>(this IRolCan me, IEnumerable <T> values) { using (var res = Printer.CallResult <bool>()) return(res.Value = ((IInternalRolCan)me).CheckInstances(false, values)); }
// One instance public static bool Instance <T>(this IRolCan me, T value) { using (var res = Printer.CallResult <bool>()) return(res.Value = me.AllInstances(new[] { value })); }
public static bool Type <T>(this IRolCan me) => me.Type(typeof(T));
// Only one type public static bool Type(this IRolCan me, Type type) { using (var res = Printer.CallResult <bool>()) return(res.Value = ((IInternalRolCan)me).CheckDiscriminators(true, Singleton.Get <TypeDiscriminatorFactory>().FromType(type))); }
public static bool AnyLocations(this IRolCan me, params LocationDao[] locations) => me.ByAny(locations);
public static bool AllLocations(this IRolCan me, params LocationDto[] locations) => me.ByAll(locations);
// Three types public static bool AllTypes <T1, T2, T3>(this IRolCan me) => me.AllTypes(typeof(T1), typeof(T2), typeof(T3));
public static bool ByAny <TDiscriminator>(this IRolCan me, params TDiscriminator[] discriminators) where TDiscriminator : IDiscriminator => CheckDiscriminators(me, false, discriminators.Cast <IDiscriminator>().ToArray());
public static bool AnyInstance <T>(this IRolCan me, params T[] values) => me.CheckInstances(false, values);
// Many instances public static bool AllInstances <T>(this IRolCan me, params T[] values) => me.CheckInstances(true, values);
// One instance public static bool Instance <T>(this IRolCan me, T value) => me.AllInstances(new[] { value });
public static bool AnyType(this IRolCan me, params Type[] types) => me.ByAny(types.Select(t => Factory.Get <TypeDiscriminatorFactory>().FromType(t)).ToArray());
public static bool AnyType <T1, T2, T3>(this IRolCan me) => me.AnyType(typeof(T1), typeof(T2), typeof(T3));
//public static bool AllLocations(this IRolCan me, params LocationDto[] locations) => me.ByAll(locations); //public static bool AnyLocations(this IRolCan me, params LocationDto[] locations) => me.ByAny(locations); //public static bool AllLocations(this IRolCan me, params LocationDao[] locations) => me.ByAll(locations); //public static bool AnyLocations(this IRolCan me, params LocationDao[] locations) => me.ByAny(locations); //public static bool AllLocations(this IRolCan me, params LocationDto[] locations) => me.AllInstances(locations); //public static bool AnyLocations(this IRolCan me, params LocationDto[] locations) => me.AnyInstance(locations); //public static bool AllLocations(this IRolCan me, params LocationDao[] locations) => me.AllInstances(locations); public static bool AllLocations2 <TLocation>(this IRolCan me, params TLocation[] locations) where TLocation : LocationDao => me.AllInstances(locations);
public static bool ByAny(this IRolCan me, TypeDiscriminator typeDiscriminator, params IDiscriminator[] discriminators) { using (var res = Printer.CallResult <bool>()) return(res.Value = ((IInternalRolCan)me).CheckDiscriminators(false, typeDiscriminator, discriminators)); }
// Only one type public static bool Type(this IRolCan me, Type type) => me.AllTypes(type);