Example #1
0
        /// <summary>
        /// 删除操作
        /// </summary>
        public void DoDelete()
        {
            // 同时删除相关授权
            using (TransactionScope trans = new TransactionScope())
            {
                try
                {
                    DynamicPermission[] permissions = DynamicPermission.FindAllByProperty("CatalogCode", this.Code);
                    foreach (DynamicPermission tpermission in permissions)
                    {
                        tpermission.DoDelete();
                    }

                    base.Delete();

                    trans.VoteCommit();
                }
                catch (Exception ex)
                {
                    trans.VoteRollBack();

                    throw ex;
                }
            }
        }
        /// <summary>
        /// 删除操作
        /// </summary>
        public void DoDelete()
        {
            using (TransactionScope trans = new TransactionScope())
            {
                try
                {
                    // 删除所有授权(这里应当使用存储过程--暂时使用 表关联功能)
                    DynamicPermission[] dps = DynamicPermission.FindAllByProperty("AuthID", this.DynamicAuthID);
                    foreach (DynamicPermission tdp in dps)
                    {
                        tdp.DoDelete();
                    }

                    base.Delete();

                    trans.VoteCommit();
                }
                catch (Exception ex)
                {
                    trans.VoteRollBack();

                    throw ex;
                }
            }
        }
        /// <summary>
        /// 回收权限
        /// </summary>
        public static void RevokeDAuths(IList <string> authIDs, IList <string> datas, string pcatalog)
        {
            DynamicPermission[] dps = DynamicPermission.FindAll(Expression.In("AuthID", authIDs.ToList()), Expression.In("Data", datas.ToList()), Expression.Eq("CatalogCode", pcatalog));

            foreach (DynamicPermission tdp in dps)
            {
                tdp.DoDelete();
            }
        }
        public void DoCreate()
        {
            this.DoValidate();

            if (String.IsNullOrEmpty(this.EditStatus))
            {
                bool isEditable  = this.Editable;
                bool isGrantable = this.Grantable;
                this.SetFullEditStatus();
                this.Editable  = isEditable;
                this.Grantable = isGrantable;
            }

            this.CreateAndFlush();

            IList <string> ops = this.Catalog.GetAllowOperations().Select(tent => tent.Code).ToList();

            DynamicPermission.GrantDAuthToUsers(this, new string[] { this.CreaterID }, ops, null, SysSystem.SYS_USERID, SysSystem.SYS_USERNAME);
        }
        public static IList <DynamicPermission> GrantDAuths(IList <DynamicAuth> dauths, IList <string> datas, IList <string> operations, string pcatalog, string tag, string granterID, string granterName)
        {
            IList <DynamicPermission> rtnps = new List <DynamicPermission>();

            IList authIDs = dauths.Select(tent => tent.DynamicAuthID).ToList();

            DynamicPermission[] dps = DynamicPermission.FindAll(Expression.Eq("CatalogCode", pcatalog), Expression.In("AuthID", authIDs), Expression.In("Data", datas.ToList()));

            // 获取权限分类
            IList dacatalogcode = dauths.Select(tent => tent.CatalogCode).Distinct().ToList();

            DynamicAuthCatalog[] dac = DynamicAuthCatalog.FindAll(Expression.In("Code", dacatalogcode));

            foreach (DynamicAuth dauth in dauths)
            {
                DynamicAuthCatalog tdac = dac.First(tent => tent.Code == dauth.CatalogCode);
                IList <string>     defaultOperations = null;

                if (tdac != null)
                {
                    defaultOperations = tdac.GetDefauleOperations().Select(tent => tent.Code).ToList();
                }

                foreach (string data in datas)
                {
                    IEnumerable <DynamicPermission> tdps = dps.Where <DynamicPermission>(tent => tent.AuthID == dauth.DynamicAuthID && tent.Data == data && tent.CatalogCode == pcatalog);

                    if (tdps.Count() > 0)
                    {
                        if (operations != null && operations.Count > 0)
                        {
                            foreach (DynamicPermission tdp in tdps)
                            {
                                if (operations != null && operations.Count() > 0)
                                {
                                    tdp.AddOperation(operations);
                                }
                                else if (defaultOperations != null)
                                {
                                    // 添加默认操作
                                    tdp.AddOperation(defaultOperations);
                                }

                                if (tag != null)
                                {
                                    tdp.Tag = tag;
                                }

                                tdp.Update();

                                rtnps.Add(tdp);
                            }
                        }
                    }
                    else
                    {
                        DynamicPermission dp = new DynamicPermission();

                        dp.AuthID          = dauth.DynamicAuthID;
                        dp.AuthCatalogCode = dauth.CatalogCode;
                        dp.Data            = data;
                        dp.CatalogCode     = pcatalog;
                        dp.CreaterID       = granterID;
                        dp.CreaterName     = granterName;
                        dp.Name            = string.Format("{0} to {1}", dauth.Name, data);

                        if (tag != null)
                        {
                            // 设置tag
                            dp.Tag = tag;
                        }

                        if (operations != null && operations.Count() > 0)
                        {
                            dp.AddOperation(operations);
                        }
                        else if (defaultOperations != null)
                        {
                            // 添加默认操作
                            dp.AddOperation(defaultOperations);
                        }

                        dp.Create();

                        rtnps.Add(dp);
                    }
                }
            }

            return(rtnps);
        }
        /// <summary>
        /// 由权限分类获取权限
        /// </summary>
        /// <param name="pdata"></param>
        /// <param name="syspCatalog"></param>
        /// <returns></returns>
        public static DynamicPermission[] GetPermissionsByCatalogCode(string pdata, string pCatalogString)
        {
            DynamicPermission[] dps = DynamicPermission.FindAll(Expression.Eq("Data", pdata), Expression.Eq("CatalogCode", pCatalogString));

            return(dps);
        }