Пример #1
0
        public async Task <IList <AuthorizeDataRuleModel> > GetDataRuleList()
        {
            var currentUser = EngineContext.Current.GetCurrentUser();

            if (currentUser == null)
            {
                throw new GirvsException(StatusCodes.Status401Unauthorized, "未授权");
            }

            var currentUserType = currentUser.UserType;

            var availableAuthorizeDataRuleList = await _cacheManager.GetAsync(
                GirvsEntityCacheDefaults <ServiceDataRule> .AllCacheKey.Create(),
                async() =>
                await _serviceDataRuleRepository.GetAllAsync());

            var result = new List <AuthorizeDataRuleModel>();

            foreach (var authorizeDataRule in availableAuthorizeDataRuleList.Where(x =>
                                                                                   currentUserType == (x.UserType & currentUserType)))
            {
                var existReturnReuslt =
                    result.FirstOrDefault(x => x.EntityTypeName == authorizeDataRule.EntityTypeName);
                if (existReturnReuslt != null)
                {
                    existReturnReuslt.AuthorizeDataRuleFieldModels.Add(new AuthorizeDataRuleFieldModel()
                    {
                        ExpressionType = authorizeDataRule.ExpressionType,
                        FieldType      = authorizeDataRule.FieldType,
                        FieldName      = authorizeDataRule.FieldName,
                        FieldValue     = authorizeDataRule.FieldValue,
                        FieldDesc      = authorizeDataRule.FieldDesc
                    });
                }
                else
                {
                    existReturnReuslt =
                        new AuthorizeDataRuleModel()
                    {
                        EntityTypeName = authorizeDataRule.EntityTypeName,
                        EntityDesc     = authorizeDataRule.EntityDesc
                    };

                    existReturnReuslt.AuthorizeDataRuleFieldModels.Add(new AuthorizeDataRuleFieldModel()
                    {
                        ExpressionType = authorizeDataRule.ExpressionType,
                        FieldType      = authorizeDataRule.FieldType,
                        FieldName      = authorizeDataRule.FieldName,
                        FieldValue     = authorizeDataRule.FieldValue,
                        FieldDesc      = authorizeDataRule.FieldDesc
                    });

                    result.Add(existReturnReuslt);
                }
            }

            return(result);
        }
Пример #2
0
        public Task <List <AuthorizeDataRuleModel> > GetAuthorizeDataRuleList()
        {
            var typeFinder = EngineContext.Current.Resolve <ITypeFinder>();

            var entities = typeFinder.FindOfType <Entity>();
            var authorizeDataRuleList = new List <AuthorizeDataRuleModel>();


            foreach (var entity in entities)
            {
                var entityDataRuleAttribute = entity.GetCustomAttribute <DataRuleAttribute>();

                if (entityDataRuleAttribute == null)
                {
                    continue;
                }

                var model = new AuthorizeDataRuleModel
                {
                    Tag            = entityDataRuleAttribute.Tag,
                    Order          = entityDataRuleAttribute.Order,
                    EntityTypeName = entity.FullName,
                    EntityDesc     = entityDataRuleAttribute.AttributeDesc
                };

                var properties = entity.GetProperties();

                foreach (var property in properties)
                {
                    var propertyDataRuleAttribute = property.GetCustomAttribute <DataRuleAttribute>();
                    if (propertyDataRuleAttribute == null)
                    {
                        continue;
                    }

                    model.AuthorizeDataRuleFieldModels.Add(new AuthorizeDataRuleFieldModel()
                    {
                        FieldName = property.Name,
                        FieldType = property.PropertyType.ToString(),
                        FieldDesc = propertyDataRuleAttribute.AttributeDesc,
                        UserType  = propertyDataRuleAttribute.UserType
                    });
                }

                authorizeDataRuleList.Add(model);
            }

            return(Task.FromResult(authorizeDataRuleList));
        }