Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <exception cref="ArgumentNullException"></exception>
        /// <param name="type"></param>
        /// <returns></returns>
        public List <RowLevelRightData> GetTypeFieldsRlsRights(Type dataType)
        {
            if (dataType == null)
            {
                throw new ArgumentNullException();
            }

            var rlsList = new List <RowLevelRightData>();

            if (!TryGetPropertyRights(dataType, out var rights))
            {
                return(rlsList);
            }

            foreach (var propRight in rights)
            {
                var rlsRight = new RowLevelRightData
                {
                    Name           = propRight.PropertyName,
                    PermissionType = RowLevelModelPermissionType.All,
                    Entities       = new List <string>(0)
                };
                if (RowLevelRights.TryGetValue(propRight.EntityName, out var right))
                {
                    rlsRight.PermissionType = right.PermissionType;
                    rlsRight.Entities.AddRange(right.Entities);
                }
                if (HasFullRights)
                {
                    rlsRight.PermissionType = RowLevelModelPermissionType.All;
                }
                rlsList.Add(rlsRight);
            }

            return(rlsList);
        }
Пример #2
0
        public bool RlsAllowsAccessToEntity(string entityName, string entityId)
        {
            if (HasFullRights)
            {
                return(true);
            }

            if (string.IsNullOrEmpty(entityName) || string.IsNullOrEmpty(entityId) || !RowLevelRights.TryGetValue(entityName, out var rlsRight))
            {
                return(true);
            }

            if (rlsRight.PermissionType == RowLevelModelPermissionType.All)
            {
                return(true);
            }
            else if (rlsRight.PermissionType == RowLevelModelPermissionType.Specified)
            {
                //return rlsRight.Entities.Exists(x => entityId.Contains(x));
                return(rlsRight.Entities.Contains(entityId));
            }
            else if (rlsRight.PermissionType == RowLevelModelPermissionType.Except)
            {
                //return !rlsRight.Entities.Exists(x => entityId.Contains(x));
                return(!rlsRight.Entities.Contains(entityId));
            }

            return(false);
        }