public RoleSharedPermission(string id, string module, Role source, Role target, RoleSharedAction action = RoleSharedAction.READ_ONLY)
 {
     this.id = id;
     this.module = module;
     this.source = source;
     this.target = target;
     this.action = action;
 }
예제 #2
0
 /// <summary>
 /// 创建一个新角色
 /// </summary>
 /// <param name="name"></param>
 /// <param name="profileIds"></param>
 /// <returns></returns>
 public ActionResult Create(string name, string desc,  string[] profileIds)
 {
     if (profileIds == null)
         profileIds = new string[0];
     Role role = new Role();
     role.Id = Guid.NewGuid().ToString();
     role.Name = name;
     role.Description = desc;
     try
     {
         //TODO:调用DAO数据持久层类创建角色RolePermissionDatabase.CreateRole(role, profileIds);
         return Json(new { msg = "创建成功!" });
     }
     catch (Exception e)
     {//TODO:根据具体异常中的信息处理错误内容
         logger.Error("创建角色出错!", e);
         return Json(new { msg = "创建角色失败!" });
     }
 }
예제 #3
0
 /// <summary>
 /// 实际保持修改的角色以及角色中包含的profile,传递的profileid数组为新数组,之前的首先删除
 /// </summary>
 /// <param name="id"></param>
 /// <param name="name"></param>
 /// <param name="desc"></param>
 /// <param name="profileIds"></param>
 /// <returns></returns>
 public ActionResult Save(string id, string name, string desc, string[] profileIds)
 {
     if (profileIds == null)
         profileIds = new string[0];
     Role role = new Role();
     role.Id = id;
     role.Name = name;
     role.Description = desc;
     try
     {
         //TODO:调用DAO对象保存 RolePermissionDatabase.SaveRole(role, profileIds);
         return Json(new { msg = "修改成功!" });
     }
     catch (Exception e)
     {//TODO:根据具体异常中的信息处理错误内容
         logger.Error("修改角色出错!", e);
         return Json(new { msg = "修改角色失败!" });
     }
 }
        private SharedPermissionCollection sharedPermissions; //共享的权限子集

        #endregion Fields

        #region Constructors

        public XcrmPermissionCollection(IXcrmPrincipal principal)
        {
            this.role = principal.Role ?? Role.EMPTY_ROLE;
            this.managedUserGroup = principal.ManagedUserGroup;
            string p = "/";
            if (principal.Org != null)
            {
                p = principal.Org.Path.EndsWith("/") ? principal.Org.Path : principal.Org.Path + "/";
            }
            this.selfPermission = new OrgPermission(principal.IsAdmin ? p + "**/*" : p + principal.Name + "/**/*");
            this.sharedPermissions = SharedPermissionCollection.GetSharedPermissionCollection(principal);
        }
 /// <summary>
 /// 创建共享的角色权限
 /// </summary>
 /// <param name="module">模块名</param>
 /// <param name="id">共享权限id</param>
 /// <param name="source">被共享的角色</param>
 /// <param name="target">共享的角色</param>
 /// <param name="action">角色共享动作枚举</param>
 public void CreateRoleSharedPermission(string module, string id, Role source, Role target, RoleSharedPermission.RoleSharedAction action)
 {
     if (SharedPermissionCollection.RoleSharedPermissions.ContainsKey(module))
     {
         int count = SharedPermissionCollection.RoleSharedPermissions[module].Count(rsp =>
         {
             if (rsp.Id == id)
                 return true;
             else
                 return false;
         });
         if (count >= 1)
             throw new ArgumentException("the role shared permission:" + id + " exist!");
         SharedPermissionCollection.RoleSharedPermissions[module].Add(new RoleSharedPermission(id, module, source, target, action));
     }
     else
     {
         SharedPermissionCollection.RoleSharedPermissions.Add(module, new List<RoleSharedPermission>() { new RoleSharedPermission(id, module, source, target, action) });
     }
 }
예제 #6
0
 /// <summary>
 /// 添加角色
 /// </summary>
 /// <param name="role"></param>
 public void AddManagedRole(Role role)
 {
     CheckNullArg(role);
     if (role == null)
     {
         throw new ArgumentException();
     }
     if (managedRoles.ContainsKey(role.Id))
     {
         Logger.Error("角色[" + role.Id + ":" + role.Name + "] 已经存在! 你不能添加相同的角色到同一个可管理用户组中!");
         throw new ArgumentException("the role[" + role.Id + ":" + role.Name + "] exists!");
     }
     managedRoles.Add(role.Id, role);
 }