Example #1
0
    public static void ApplayRecordPermision(BPMConnection cn, JsonItemCollection items, string rsid, string tableName, string jsonitemKeyAttrName)
    {
        //获得资源上的记录级权限种类
        UserResourcePermisionCollection resourcePerms = UserResourceSecurityManager.GetResourcePermisions(cn, rsid);
        BPMObjectNameCollection         permNames     = new BPMObjectNameCollection();

        foreach (UserResourcePermision resourcePerm in resourcePerms)
        {
            if (resourcePerm.PermType == UserResourcePermisionType.Record)
            {
                permNames.Add(resourcePerm.PermName);
            }
        }

        //应用权限
        foreach (JsonItem item in items)
        {
            string key = Convert.ToString(item.Attributes[jsonitemKeyAttrName]);
            bool[] rv  = RecordSecurityManager.CheckPermision(cn, tableName, key, permNames);

            JsonItem jsonPerm = new JsonItem();
            item.Attributes["perm"] = jsonPerm;
            for (int i = 0; i < permNames.Count; i++)
            {
                jsonPerm.Attributes[permNames[i]] = rv[i];
            }
        }
    }
Example #2
0
    public static void ApplayPermision(BPMConnection cn, JsonItemCollection items)
    {
        for (int moduleIndex = 0; moduleIndex < items.Count; moduleIndex++)
        {
            JsonItem item          = items[moduleIndex];
            bool     moduleExecute = true;

            if (item.Attributes.ContainsKey("modulePerm"))
            {
                YZModulePermision perm = item.Attributes["modulePerm"] as YZModulePermision;
                item.Attributes.Remove("modulePerm");

                //检查模块权限
                moduleExecute = UserResourceSecurityManager.CheckPermision(cn, perm.RSID, "Execute");

                if (moduleExecute)
                {
                    //获得模块config配置项
                    JsonItem config = null;
                    if (item.Attributes.ContainsKey("config"))
                    {
                        config = item.Attributes["config"] as JsonItem;
                    }
                    else
                    {
                        config = new JsonItem();
                        item.Attributes["config"] = config;
                    }

                    //在config配置项下建perm配置
                    JsonItem jsonPerm = new JsonItem();
                    config.Attributes["perm"] = jsonPerm;

                    //记录模块rsid
                    jsonPerm.Attributes["rsid"] = perm.RSID;

                    //生成工具条上的访问权限
                    if (perm.GenToolbarPermision)
                    {
                        //获得工具条上的模块级权限种类
                        UserResourcePermisionCollection resourcePerms = UserResourceSecurityManager.GetResourcePermisions(cn, perm.RSID);
                        BPMObjectNameCollection         permNames     = new BPMObjectNameCollection();
                        foreach (UserResourcePermision resourcePerm in resourcePerms)
                        {
                            if (resourcePerm.PermType == UserResourcePermisionType.Module)
                            {
                                permNames.Add(resourcePerm.PermName);
                            }
                        }

                        //记录工具条上的模块级权限许可情况
                        bool[] rv = UserResourceSecurityManager.CheckPermision(cn, perm.RSID, permNames);
                        for (int i = 0; i < permNames.Count; i++)
                        {
                            jsonPerm.Attributes[permNames[i]] = rv[i];
                        }
                    }
                }
                else
                {
                    items.RemoveAt(moduleIndex);
                    moduleIndex--;
                }
            }

            //此模块可见则检查子级
            if (moduleExecute)
            {
                if (item.Attributes.ContainsKey("children"))
                {
                    JsonItemCollection children = item.Attributes["children"] as JsonItemCollection;
                    if (children != null)
                    {
                        int allCount = children.Count;
                        ApplayPermision(cn, children);

                        if (allCount != 0 && children.Count == 0)
                        {
                            //item.Attributes["empty"] = true;
                            items.RemoveAt(moduleIndex);
                            moduleIndex--;
                            continue;
                        }
                    }
                }

                if (item.Attributes.ContainsKey("tabs"))
                {
                    JsonItemCollection tabs = item.Attributes["tabs"] as JsonItemCollection;
                    if (tabs != null)
                    {
                        int allCount = tabs.Count;
                        ApplayPermision(cn, tabs);

                        if (allCount != 0 && tabs.Count == 0)
                        {
                            //item.Attributes["empty"] = true;
                            items.RemoveAt(moduleIndex);
                            moduleIndex--;
                            continue;
                        }
                    }
                }
            }
        }
    }