Exemplo n.º 1
0
 public static bool CheckMutex(Role role1, Role role2, int type)
 {
     List<string> groupList = GetGroupList();
     List<RoleMutex> mutexList = GetRoleMutexList();
     foreach (var group in groupList)
     {
         var rs1 = mutexList.Exists(rm => rm.Group == group && rm.RoleId == role1.Id && rm.Type == type);
         var rs2 = mutexList.Exists(rm => rm.Group == group && rm.RoleId == role2.Id && rm.Type == type);
         if (rs1 && rs2)
         {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 2
0
        public Role GiveRole(Role role)
        {
            if (!PositionInfoRepo.Exists(this.MappingTo<PositionInfo>()))
            {
                throw new Exception("岗位不存在");
            }
            if (!Role.RoleInfoRepo.Exists(role.MappingTo<RoleInfo>()))
            {
                throw new Exception("角色不存在");
            }
            if (RolePositionInfoRepo.Read().Exists(ro => ro.RoleId == role.Id
                && ro.OrganizationId == this.OrganizationId
                && ro.PositionId == this.Id))
            {
                return role;
            }

            //检查互斥,除检查自身外,需检查所有上级组件层叠过来的角色(DeepRoleList 包括上级组件的角色)
            List<Role> linkRoleList = this.DeepRoleList;
            foreach (Role linkRole in linkRoleList)
            {
                if (RoleMutex.CheckMutex(role, linkRole, RoleMutexType.Static))
                {
                    throw new Exception("授予的角色和当前岗位或其所在组织的角色存在静态互斥关系");
                }
            }

            RolePositionInfo rolePositionInfo = new RolePositionInfo();
            rolePositionInfo.RoleId = role.Id;
            rolePositionInfo.OrganizationId = this.OrganizationId;
            rolePositionInfo.PositionId = this.Id;
            RolePositionInfoRepo.Add(rolePositionInfo);
            return role;
        }
Exemplo n.º 3
0
 public Role CancelRole(Role role)
 {
     if (!PositionInfoRepo.Exists(this.MappingTo<PositionInfo>()))
     {
         throw new Exception("岗位不存在");
     }
     RolePositionInfo rolePositionInfo = new RolePositionInfo();
     rolePositionInfo.RoleId = role.Id;
     rolePositionInfo.OrganizationId = this.OrganizationId;
     rolePositionInfo.PositionId = this.Id;
     RolePositionInfoRepo.Delete(rolePositionInfo);
     return role;
 }
Exemplo n.º 4
0
        /// <summary>
        /// 授予角色
        /// </summary>
        /// <param name="role"></param>
        public Role GiveRole(Role role)
        {
            //角色是否已存在
            if (RoleUserInfoRepo.Read().Exists(ru => ru.RoleId == role.Id && ru.UserId == this.Id))
            {
                return role;
            }

            //检查互斥
            List<Role> linkRoleList = this.DeepRoleList;
            foreach (Role linkRole in linkRoleList)
            {
                if (RoleMutex.CheckMutex(role, linkRole, RoleMutexType.Static))
                {
                    throw new Exception("授予的角色和当前用户或其所在的组织的角色存在静态互斥关系");
                }
            }

            RoleUserInfo roleUserInfo = new RoleUserInfo();
            roleUserInfo.RoleId = role.Id;
            roleUserInfo.UserId = this.Id;
            RoleUserInfoRepo.Add(roleUserInfo);
            return role;
        }
Exemplo n.º 5
0
 /// <summary>
 /// 取消角色
 /// </summary>
 /// <param name="role"></param>
 public Role CancelRole(Role role)
 {
     RoleUserInfo roleUserInfo = new RoleUserInfo();
     roleUserInfo.RoleId = role.Id;
     roleUserInfo.UserId = this.Id;
     RoleUserInfoRepo.Delete(roleUserInfo);
     return role;
 }
Exemplo n.º 6
0
        /// <summary>
        /// 授予角色
        /// </summary>
        /// <param name="role"></param>
        public Role GiveRole(Role role)
        {
            if (!Role.GetRoleList().Exists(r => r.Id == role.Id))
            {
                throw new Exception("授予的角色不存在");
            }
            if (RoleOrganizationInfoRepo.Read().Exists(ro => ro.RoleId == role.Id && ro.OrganizationId == this.Id))
            {
                return role;
            }

            //检查互斥
            List<Role> linkRoleList = this.LinkRoleList;
            foreach (Role linkRole in linkRoleList)
            {
                if (RoleMutex.CheckMutex(role, linkRole, RoleMutexType.Static))
                {
                    throw new Exception("授予的角色和当前组织或其父级或其子级的角色存在静态互斥关系");
                }
            }

            RoleOrganizationInfo roleOrganizationInfo = new RoleOrganizationInfo();
            roleOrganizationInfo.RoleId = role.Id;
            roleOrganizationInfo.OrganizationId = this.Id;
            RoleOrganizationInfoRepo.Save(roleOrganizationInfo);
            return role;
        }
Exemplo n.º 7
0
 /// <summary>
 /// 取消角色
 /// </summary>
 /// <param name="role"></param>
 public Role CancelRole(Role role)
 {
     RoleOrganizationInfo roleOrganizationInfo = new RoleOrganizationInfo();
     roleOrganizationInfo.RoleId = role.Id;
     roleOrganizationInfo.OrganizationId = this.Id;
     RoleOrganizationInfoRepo.Delete(roleOrganizationInfo);
     return role;
 }
Exemplo n.º 8
0
 /// <summary>
 /// 构造函数
 /// </summary>
 public static Role Create()
 {
     Role role = new Role();
     return role;
 }