コード例 #1
0
ファイル: AuthCache.cs プロジェクト: crazyants/extensions
        void IManualAuth <K, A> .SetAllowed(Lite <RoleEntity> role, K key, A allowed)
        {
            R resource = ToEntity(key);

            var keyCoercer = coercer.GetCoerceValueManual(key);

            ManualResourceCache miniCache = new ManualResourceCache(key, resource, merger, keyCoercer);

            allowed = keyCoercer(role, allowed);

            if (miniCache.GetAllowed(role).Equals(allowed))
            {
                return;
            }

            IQueryable <RT> query = Database.Query <RT>().Where(a => a.Resource == resource && a.Role == role);

            if (miniCache.GetAllowedBase(role).Equals(allowed))
            {
                if (query.UnsafeDelete() == 0)
                {
                    throw new InvalidOperationException("Inconsistency in the data");
                }
            }
            else
            {
                if (query.UnsafeUpdate().Set(a => a.Allowed, a => allowed).Execute() == 0)
                {
                    new RT
                    {
                        Role     = role,
                        Resource = resource,
                        Allowed  = allowed,
                    }
                }
コード例 #2
0
        void IManualAuth <Type, TypeAllowedAndConditions> .SetAllowed(Lite <RoleEntity> role, Type key, TypeAllowedAndConditions allowed)
        {
            TypeEntity resource = TypeLogic.TypeToEntity.GetOrThrow(key);

            ManualResourceCache miniCache = new ManualResourceCache(resource, merger);

            if (miniCache.GetAllowed(role).Equals(allowed))
            {
                return;
            }

            IQueryable <RuleTypeEntity> query = Database.Query <RuleTypeEntity>().Where(a => a.Resource == resource && a.Role == role);

            if (miniCache.GetAllowedBase(role).Equals(allowed))
            {
                if (query.UnsafeDelete() == 0)
                {
                    throw new InvalidOperationException("Inconsistency in the data");
                }
            }
            else
            {
                query.UnsafeDelete();

                allowed.ToRuleType(role, resource).Save();
            }
        }