1、功能需求描述

由于系统自带的权限管理无法满足系统需求,需要根据用户角色进行数据权限限制。

2、列表设计后端代码

   protected override void OnInit(H3.SmartForm.LoadListViewResponse response)
    {
        base.OnInit(response);
        //获取用户ID
        string userId = this.Request.UserContext.UserId;
        //获取用户角色集
        H3.Organization.OrgRole[] roles = this.Request.Engine.Organization.GetUserRoles(userId, true);
        bool isAuthority = false;
        //遍历循环角色集,满足角色权限不进行数据过滤
        foreach(H3.Organization.OrgRole role in roles)
        {
            string roleName = role.Name;
            if(roleName == "财务" || roleName == "人事" || role.Name == "总经理")
            {
                isAuthority = true;
                break;
            }
        }
        if(!isAuthority)
        {
            //没有权限数据过滤
            H3.Data.Filter.Filter filter = new H3.Data.Filter.Filter();  //构建过滤器
            H3.Data.Filter.And andMatcher = new H3.Data.Filter.And();      //构造And匹配器
            andMatcher.Add(new H3.Data.Filter.ItemMatcher("CreatedBy", H3.Data.ComparisonOperatorType.Equal, userId)); //添加查询条件
            filter.Matcher = andMatcher;
            this.Request.Filter = filter;

            if(response.Actions != null && response.Actions.ContainsKey("Import"))
            {
                response.Actions.Remove("Import");
            }

            if(response.Actions != null && response.Actions.ContainsKey("Export"))
            {
                response.Actions.Remove("Export");
            }
        }
    }