示例#1
0
        public virtual void DenyAccess <TActionParamsType>(string actionName, string roleName, string entityId, TActionParamsType T) where TActionParamsType : new()
        {
            var entityPermission =
                Query().SingleOrDefault(ep => ep.Action == actionName &&
                                        ep.RoleName == roleName && ep.EntityId == entityId);

            if (entityPermission == null)
            {
                var ep = new EntityPermission
                {
                    Action     = actionName,
                    EntityId   = entityId,
                    RoleName   = roleName,
                    Permission = Permission.Deny,
                };

                var            type          = typeof(TActionParamsType);
                PropertyInfo[] propertyInfos = type.GetProperties();
                foreach (var propertyInfo in propertyInfos)
                {
                    ep.RawActionParams.Add(propertyInfo.Name, propertyInfo.GetValue(T).ToString());
                }
                _dataStore.Insert(ep);
            }
            else
            {
                if (entityPermission.Permission != Permission.Deny)
                {
                    entityPermission.Permission = Permission.Deny;
                    _dataStore.Update(entityPermission);
                }
            }
        }
示例#2
0
        public virtual void DenyAccess(string actionName, string roleName, string entityId)
        {
            var entityPermission =
                Query().SingleOrDefault(ep => ep.Action == actionName &&
                                        ep.RoleName == roleName && ep.EntityId == entityId);

            if (entityPermission == null)
            {
                var ep = new EntityPermission
                {
                    Action     = actionName,
                    EntityId   = entityId,
                    RoleName   = roleName,
                    Permission = Permission.Deny
                };
                _dataStore.Insert(ep);
            }
            else
            {
                if (entityPermission.Permission != Permission.Deny)
                {
                    entityPermission.Permission = Permission.Deny;
                    _dataStore.Update(entityPermission);
                }
            }
        }
示例#3
0
        //public virtual IQueryable<EntityPermission> Query(string actionName)
        //{
        //    return Query().Where(ep => ep.ActionName == actionName);
        //}

        public virtual IEnumerable <EntityPermission <TActionParamsType> > Query <TActionParamsType>(string action, string userid = null) where TActionParamsType : new()
        {
            var entityPermisions = Query().Where(ep => ep.Action == action);

            if (userid != null)
            {
                var roles = _rolesProvider(userid).ToList();
                entityPermisions = entityPermisions.Where(ep => roles.Contains(ep.RoleName));
            }
            var result = new List <EntityPermission <TActionParamsType> >();

            var type = typeof(TActionParamsType);

            foreach (var entityPermission in entityPermisions)
            {
                var permsStr = new EntityPermission <TActionParamsType>
                {
                    EntityId         = entityPermission.EntityId,
                    Id               = entityPermission.Id,
                    Action           = entityPermission.Action,
                    RoleName         = entityPermission.RoleName,
                    Permission       = entityPermission.Permission,
                    ActionParameters = new TActionParamsType()
                };
                foreach (var rawActionParam in entityPermission.RawActionParams)
                {
                    var prop = type.GetProperty(rawActionParam.Key);
                    if (null != prop && prop.CanWrite)
                    {
                        prop.SetValue(permsStr.ActionParameters, rawActionParam.Value);
                    }
                }
                result.Add(permsStr);
            }
            return(result);
        }