Beispiel #1
0
 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);
 }
Beispiel #2
0
        // -------------------------- 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);
        }
Beispiel #3
0
 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);
 }
Beispiel #4
0
 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);
     }
 }
Beispiel #5
0
 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));
 }
Beispiel #6
0
 // 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 }));
 }
Beispiel #7
0
 public static bool Type <T>(this IRolCan me) => me.Type(typeof(T));
Beispiel #8
0
 // 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)));
 }
Beispiel #9
0
 public static bool AnyLocations(this IRolCan me, params LocationDao[] locations) => me.ByAny(locations);
Beispiel #10
0
 public static bool AllLocations(this IRolCan me, params LocationDto[] locations) => me.ByAll(locations);
Beispiel #11
0
 // Three types
 public static bool AllTypes <T1, T2, T3>(this IRolCan me) => me.AllTypes(typeof(T1), typeof(T2), typeof(T3));
Beispiel #12
0
 public static bool ByAny <TDiscriminator>(this IRolCan me, params TDiscriminator[] discriminators)
     where TDiscriminator : IDiscriminator
 => CheckDiscriminators(me, false, discriminators.Cast <IDiscriminator>().ToArray());
Beispiel #13
0
 public static bool AnyInstance <T>(this IRolCan me, params T[] values) => me.CheckInstances(false, values);
Beispiel #14
0
 // Many instances
 public static bool AllInstances <T>(this IRolCan me, params T[] values) => me.CheckInstances(true, values);
Beispiel #15
0
 // One instance
 public static bool Instance <T>(this IRolCan me, T value) => me.AllInstances(new[] { value });
Beispiel #16
0
 public static bool AnyType(this IRolCan me, params Type[] types) => me.ByAny(types.Select(t => Factory.Get <TypeDiscriminatorFactory>().FromType(t)).ToArray());
Beispiel #17
0
 public static bool AnyType <T1, T2, T3>(this IRolCan me) => me.AnyType(typeof(T1), typeof(T2), typeof(T3));
Beispiel #18
0
 //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);
Beispiel #19
0
 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));
 }
Beispiel #20
0
 // Only one type
 public static bool Type(this IRolCan me, Type type) => me.AllTypes(type);