Esempio n. 1
0
        public List <string> GetObjectsByPermission(string accountID, string permission)
        {
            List <string> channels = new List <string>();
            object        tmpObj   = HttpContext.Current.Session[accountID + "MyPermissionChannelList" + permission];

            if (tmpObj != null)
            {
                channels = (List <string>)tmpObj;
            }
            else
            {
                IAccountHelper ah          = AccountFactory.CreateInstance();
                List <string>  allowOwners = ah.GetRolesOfAccount(accountID);
                allowOwners.Add(accountID);
                channels = GetObjectID(allowOwners, permission);
                HttpContext.Current.Session[accountID + "MyPermissionChannelList" + permission] = channels;
            }
            return(channels);
        }
        /// <summary>
        /// 获取用户所具有的所有权限内容列表(包含了所属角色的权限列表)
        /// </summary>
        /// <param name="accountID">用户ID</param>
        /// <param name="objectID">菜单ID或栏目ID</param>
        /// <returns>权限列表</returns>
        public List <string> GetPermissionContents(string accountID, string objectID)
        {
            List <string> contents = new List <string>();
            string        key      = "$AccountAllPermissionContents" + accountID + objectID;

            if (HttpContext.Current.Items[key] == null)
            {
                Criteria c    = new Criteria(CriteriaType.Equals, "ObjectID", objectID);
                Criteria subc = new Criteria(CriteriaType.None);
                subc.Mode = CriteriaMode.Or;
                subc.Add(CriteriaType.Equals, "OwnerID", accountID);

                //获取用户所拥有的角色,如果拥有则继续获取每个角色的权限
                IAccountHelper ah    = AccountFactory.CreateInstance();
                List <string>  roles = ah.GetRolesOfAccount(accountID);
                if (roles != null)
                {
                    foreach (string ar in roles)
                    {
                        subc.Add(CriteriaType.Equals, "OwnerID", ar);
                    }
                    c.Criterias.Add(subc);
                }

                List <Permission> plist = Assistant.List <Permission>(c, null);
                if (plist != null)
                {
                    foreach (Permission p in plist)
                    {
                        contents.Add(p.Content);
                    }
                }

                HttpContext.Current.Items[key] = contents;
            }
            else
            {
                contents = HttpContext.Current.Items[key] as List <string>;
            }

            return(contents);
        }
Esempio n. 3
0
        public override void InitControl()
        {
            string keyword  = Control.Params["keyword"];
            string format   = Control.Params["format"];
            string parentId = Control.Params["parentId"];
            string role     = Control.Params["role"];

            List <Department> departments;
            string            siteID = SiteConfigs.GetConfig().SiteGroupEnabled ? SiteConfigs.GetConfig().SiteID : string.Empty;

            if (String.Compare("true", format, true) == 0)
            {
                departments = helper.GetDepartmentTreeWithFormat(siteID, parentId);
            }
            else
            {
                departments = helper.GetDepartmentTree(siteID, parentId);
            }

            ddlDepartment.DataSource     = departments;
            ddlDepartment.DataTextField  = "Name";
            ddlDepartment.DataValueField = "ID";
            ddlDepartment.DataBind();
            ddlDepartment.Items.Insert(0, new ListItem("请选择", ""));

            string val = Value as string;

            if (String.IsNullOrEmpty(val))
            {
                if (CurrentAccount != null)
                {
                    foreach (ListItem item in ddlDepartment.Items)
                    {
                        item.Selected = item.Value == CurrentAccount.DepartmentID;
                    }
                }
            }
            else
            {
                ddlDepartment.SelectedValue = val;
            }

            if (!String.IsNullOrEmpty(role) && Security.CurrentAccountID != We7Helper.EmptyGUID)
            {
                List <string> actids = helper.GetRolesOfAccount(Security.CurrentAccountID);
                bool          flag   = false;
                if (actids != null)
                {
                    foreach (string s in actids)
                    {
                        if (s == role.Trim('{', '}'))
                        {
                            flag = true;
                            break;
                        }
                    }
                }
                ddlDepartment.Enabled = flag;
            }

            if (!String.IsNullOrEmpty(Control.Width))
            {
                ddlDepartment.Width = Unit.Parse(Control.Width);
            }
            if (!String.IsNullOrEmpty(Control.Height))
            {
                ddlDepartment.Height = Unit.Parse(Control.Height);
            }

            ddlDepartment.CssClass = Control.CssClass;
            if (Control.Required && !ddlDepartment.CssClass.Contains("required"))
            {
                ddlDepartment.CssClass += " required";
            }
        }