Ejemplo n.º 1
0
 /// <summary>
 /// 添加权限组
 /// </summary>
 /// <param name="groupInfo"></param>
 /// <param name="relations"></param>
 /// <returns></returns>
 public long AddGroupInfo(PermissionGroupInfo groupInfo, List <long> pmsIds, BLLTransaction tran)
 {
     if (Get <PermissionGroupInfo>(string.Format(" GroupName='{0}' AND WebsiteOwner='{1}' "
                                                 , groupInfo.GroupName, groupInfo.WebsiteOwner)) != null)
     {
         throw new Exception("权限组名称已被使用");
     }
     groupInfo.GroupID = Convert.ToInt64(GetGUID(TransacType.PermissionGroupAdd));
     if (!Add(groupInfo, tran))
     {
         throw new Exception("添加权限组失败");
     }
     foreach (long pmsId in pmsIds)
     {
         PermissionRelationInfo relation = new PermissionRelationInfo();
         relation.RelationID   = groupInfo.GroupID.ToString();
         relation.PermissionID = pmsId;
         relation.RelationType = 0;
         if (!Add(relation, tran))
         {
             throw new Exception("添加权限关系失败");
         }
     }
     return(groupInfo.GroupID);
 }
Ejemplo n.º 2
0
        private string Copy(HttpContext context)
        {
            string idStr = context.Request["id"];
            long   id    = Convert.ToInt64(idStr);
            PermissionGroupInfo model = bllPms.GetPermissionGroup(null, id);
            string newIdStr           = bllPer.GetGUID(TransacType.PermissionGroupAdd);

            model.GroupID   = Convert.ToInt64(newIdStr);
            model.GroupName = model.GroupName + "—复制";
            //权限组权限关系
            List <PermissionRelationInfo> listPermissionRelation = bllPms.GetPermissionRelationList(idStr, 0);
            //权限组权限栏目关系
            List <PermissionRelationInfo> listPermissionRelation3 = bllPms.GetPermissionRelationList(idStr, 3);

            listPermissionRelation.AddRange(listPermissionRelation3);
            foreach (var item in listPermissionRelation)
            {
                item.RelationID = newIdStr;
            }
            List <MenuRelationInfo> listMenuRelation = bllMenu.GetMenuRelationList(idStr, 0);

            foreach (var item in listMenuRelation)
            {
                item.RelationID = newIdStr;
            }

            BLLTransaction tran   = new BLLTransaction();
            bool           result = bllPer.Add(model, tran);

            if (!result)
            {
                tran.Rollback();
                return("复制权限组失败");
            }
            foreach (var item in listPermissionRelation)
            {
                if (!bllPer.Add(item, tran))
                {
                    tran.Rollback();
                    return("复制权限组权限失败");
                }
            }
            foreach (var item in listMenuRelation)
            {
                if (!bllPer.Add(item, tran))
                {
                    tran.Rollback();
                    return("复制权限组菜单失败");
                }
            }
            tran.Commit();
            return(result.ToString().ToLower());
        }
Ejemplo n.º 3
0
        private string Edit(HttpContext context)
        {
            //#region 权限处理
            //if (!DataLoadTool.CheckCurrUserPms(PermissionKey.Pms_PermissionGroup_EditPermissionGroup))
            //{
            //    return "无权修改权限组";
            //}
            //#endregion
            string jsonData           = context.Request["JsonData"];
            PermissionGroupInfo model = ZentCloud.Common.JSONHelper.JsonToModel <PermissionGroupInfo>(jsonData);
            bool result = bllPer.Update(model);

            return(result.ToString().ToLower());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 添加权限组
        /// </summary>
        /// <param name="groupInfo"></param>
        /// <param name="relations"></param>
        /// <returns></returns>
        public void UpdateGroupInfo(PermissionGroupInfo groupInfo, List <long> pmsIds, BLLTransaction tran)
        {
            PermissionGroupInfo tempOld = Get <PermissionGroupInfo>(string.Format(" GroupName='{0}' AND WebsiteOwner='{1}' "
                                                                                  , groupInfo.GroupName, groupInfo.WebsiteOwner));

            if (tempOld != null && tempOld.GroupID != groupInfo.GroupID)
            {
                throw new Exception("权限组名称已被使用");
            }
            if (!Update(groupInfo, tran))
            {
                throw new Exception("编辑权限组失败");
            }
            List <PermissionRelationInfo> oldList = GetList <PermissionRelationInfo>(
                string.Format(" RelationType=0 AND RelationID='{0}' ", groupInfo.GroupID));

            foreach (PermissionRelationInfo item in oldList)
            {
                if (!pmsIds.Exists(p => p == item.PermissionID))
                {
                    if (Delete(item, tran) == -1)
                    {
                        throw new Exception("删除旧权限关系失败失败");
                    }
                }
            }
            foreach (long pmsId in pmsIds)
            {
                if (!oldList.Exists(p => p.PermissionID == pmsId))
                {
                    PermissionRelationInfo relation = new PermissionRelationInfo();
                    relation.RelationID   = groupInfo.GroupID.ToString();
                    relation.PermissionID = pmsId;
                    relation.RelationType = 0;
                    if (!Add(relation, tran))
                    {
                        throw new Exception("添加新权限关系失败");
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private string Add(HttpContext context)
        {
            //#region 权限处理
            //if (!DataLoadTool.CheckCurrUserPms(PermissionKey.Pms_PermissionGroup_AddPermissionGroup))
            //{
            //    return "无权添加权限组";
            //}
            //#endregion

            string jsonData           = context.Request["JsonData"];
            PermissionGroupInfo model = ZentCloud.Common.JSONHelper.JsonToModel <PermissionGroupInfo>(jsonData);

            model.GroupID = long.Parse(bllPer.GetGUID(Common.TransacType.PermissionGroupAdd));
            model.PreID   = 0;
            if (model.GroupType == 2)
            {
                model.WebsiteOwner = bllPer.WebsiteOwner;
            }
            bool result = bllPer.Add(model);

            return(result.ToString().ToLower());
        }
Ejemplo n.º 6
0
        public List <PermissionGroupInfo> ListPermissions(bool onlyDangerous = false, bool onlyUserVisible = false)
        {
            // list packages [options] filter
            // start [options] intent
            var builder = new ProcessArgumentBuilder();

            runner.AddSerial(AdbSerial, builder);

            builder.Append("shell");
            builder.Append("pm");

            builder.Append("list");
            builder.Append("permissions");
            builder.Append("-g");
            builder.Append("-f");

            if (onlyDangerous)
            {
                builder.Append("-d");
            }
            if (onlyUserVisible)
            {
                builder.Append("-u");
            }

            var r = runner.RunAdb(AndroidSdkHome, builder);

            var results = new List <PermissionGroupInfo>();

            PermissionGroupInfo currentGroup = null;
            PermissionInfo      currentPerm  = null;

            foreach (var line in r.StandardOutput)
            {
                if (string.IsNullOrWhiteSpace(line) || line.StartsWith("All Permissions:", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                if (line.StartsWith("+ group:"))
                {
                    if (currentPerm != null)
                    {
                        currentGroup.Permissions.Add(currentPerm);
                        currentPerm = null;
                    }

                    if (currentGroup != null)
                    {
                        results.Add(currentGroup);
                    }

                    currentGroup       = new PermissionGroupInfo();
                    currentGroup.Group = line.Substring(8);
                }
                else if (line.StartsWith("  package:"))
                {
                    currentGroup.PackageName = line.Substring(10);
                }
                else if (line.StartsWith("  label:"))
                {
                    currentGroup.Label = line.Substring(8);
                }
                else if (line.StartsWith("  description:"))
                {
                    currentGroup.Label = line.Substring(14);
                }
                else if (line.StartsWith("  + permission:"))
                {
                    if (currentPerm != null && currentGroup != null)
                    {
                        currentGroup.Permissions.Add(currentPerm);
                    }

                    currentPerm            = new PermissionInfo();
                    currentPerm.Permission = line.Substring(15);
                }
                else if (line.StartsWith("    package:"))
                {
                    currentPerm.PackageName = line.Substring(12);
                }
                else if (line.StartsWith("    label:"))
                {
                    currentPerm.Label = line.Substring(10);
                }
                else if (line.StartsWith("    description:"))
                {
                    currentPerm.Description = line.Substring(16);
                }
                else if (line.StartsWith("    protectionLevel:"))
                {
                    var plraw = line.Substring(20);
                    currentPerm.ProtectionLevels.AddRange(plraw.Split('|'));
                }
            }

            if (currentPerm != null && currentGroup != null)
            {
                currentGroup.Permissions.Add(currentPerm);
            }

            if (currentGroup != null)
            {
                results.Add(currentGroup);
            }

            return(results);
        }