Example #1
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);
        }
Example #2
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);
        }
Example #3
0
 /// <summary>
 /// 新增子节点
 /// </summary>
 /// <param name="organization"></param>
 public Organization AddChild(Organization organization)
 {
     //设置上级id
     if (organization.ParentId != this.Id)
     {
         //检查互斥
         List <Role> roleList1 = this.LinkRoleList;
         List <Role> roleList2 = organization.LinkRoleList;
         foreach (Role role1 in roleList1)
         {
             foreach (Role role2 in roleList1)
             {
                 if (RoleMutex.CheckMutex(role1, role2, RoleMutexType.Static))
                 {
                     throw new Exception("当前组织或其父级或其子级的角色存在静态互斥关系");
                 }
             }
         }
         organization.ParentId = this.Id;
         organization.Save();
     }
     return(organization);
 }
Example #4
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);
        }