Пример #1
0
        public void Parse()
        {
            var dic = new Dictionary <String, Object>(StringComparer.OrdinalIgnoreCase)
            {
                ["userid"] = 1234
            };
            var builder = new WhereBuilder
            {
                Factory    = Log.Meta.Factory,
                Expression = "CreateUserID={$userId}",
            };

            builder.SetData(dic);

            var exp = builder.GetExpression();

            Assert.NotNull(exp);

            var fe = exp as FieldExpression;

            Assert.NotNull(fe);
            Assert.Equal(Log._.CreateUserID, fe.Field);
            Assert.Equal("=", fe.Action);
            Assert.Equal(1234, fe.Value);
        }
Пример #2
0
        /// <summary>创建查询条件构造器,主要用于数据权限</summary>
        /// <returns></returns>
        protected virtual WhereBuilder CreateWhere()
        {
            var att = GetType().GetCustomAttribute <DataPermissionAttribute>();

            if (att == null)
            {
                return(null);
            }

            // 已登录用户判断系统角色,未登录时不判断
            var user = HttpContext.Items["CurrentUser"] as IUser;

            if (user == null)
            {
                user = ManageProvider.User;
            }
            if (user != null && (user.Roles.Any(e => e.IsSystem) || att.Valid(user.Roles)))
            {
                return(null);
            }

            var builder = new WhereBuilder
            {
                Factory    = Factory,
                Expression = att.Expression,
#if __CORE__
                //Data = Session,
#endif
            };

#if __CORE__
            builder.SetData(Session);
#else
            builder.Data = new SessionExtend {
                Session = Session
            };
#endif
            builder.Data2 = new ItemsExtend {
                Items = HttpContext.Items
            };

            return(builder);
        }
Пример #3
0
        public void ParseUnknown()
        {
            var user = new UserX {
                ID = 1234
            };
            var dic = new Dictionary <String, Object>(StringComparer.OrdinalIgnoreCase)
            {
                ["user"] = user
            };
            var builder = new WhereBuilder
            {
                Factory    = Log.Meta.Factory,
                Expression = "CreateUserID>={$User.ID}",
            };

            builder.SetData(dic);

            var ex = Assert.Throws <XCodeException>(() => builder.GetExpression());

            Assert.NotNull(ex);
        }
Пример #4
0
        public void EvalFail(String exp)
        {
            var dic = new Dictionary <String, Object>(StringComparer.OrdinalIgnoreCase)
            {
                ["SiteIds"] = new[] { 2, 4, 8, 16 },
                ["userid"]  = 1234
            };
            var builder = new WhereBuilder
            {
                Factory    = Log.Meta.Factory,
                Expression = exp,
            };

            builder.SetData(dic);
            builder.SetData2(dic);

            var log = new Log {
                LinkID = 17, CreateUserID = 1235
            };

            var rs = builder.Eval(log);

            Assert.False(rs);
        }