refactor(系统设置): 优化系统管理员登陆逻辑

This commit is contained in:
wxg0103 2024-05-28 11:51:26 +08:00 committed by wxg0103
parent 6f271c0dd8
commit e9009168dd
3 changed files with 25 additions and 18 deletions

View File

@ -1,5 +1,6 @@
package io.metersphere.system.mapper; package io.metersphere.system.mapper;
import io.metersphere.project.domain.Project;
import io.metersphere.system.domain.User; import io.metersphere.system.domain.User;
import io.metersphere.system.dto.CommentUserInfo; import io.metersphere.system.dto.CommentUserInfo;
import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.OptionDTO;
@ -41,8 +42,15 @@ public interface BaseUserMapper {
/** /**
* 获取评论用户信息 * 获取评论用户信息
*
* @param ids 用户ID集合 * @param ids 用户ID集合
* @return 评论用户信息集合 * @return 评论用户信息集合
*/ */
List<CommentUserInfo> getCommentUserInfoByIds(List<String> ids); List<CommentUserInfo> getCommentUserInfoByIds(List<String> ids);
/**
* 获取开启的项目和组织
*/
Project getEnableProjectAndOrganization();
} }

View File

@ -132,4 +132,11 @@
#{id} #{id}
</foreach> </foreach>
</select> </select>
<select id="getEnableProjectAndOrganization" resultType="io.metersphere.project.domain.Project">
SELECT p.*
FROM project p
LEFT JOIN organization o ON p.organization_id = o.id
WHERE p.enable = 1
AND o.enable = 1 limit 1
</select>
</mapper> </mapper>

View File

@ -237,35 +237,27 @@ public class UserLoginService {
organizationExample.createCriteria().andIdEqualTo(user.getLastOrganizationId()).andEnableEqualTo(true); organizationExample.createCriteria().andIdEqualTo(user.getLastOrganizationId()).andEnableEqualTo(true);
List<Organization> organizations = organizationMapper.selectByExample(organizationExample); List<Organization> organizations = organizationMapper.selectByExample(organizationExample);
if (CollectionUtils.isNotEmpty(organizations)) { if (CollectionUtils.isNotEmpty(organizations)) {
Organization organization = organizations.get(0); Organization organization = organizations.getFirst();
ProjectExample projectExample = new ProjectExample(); ProjectExample projectExample = new ProjectExample();
projectExample.createCriteria().andOrganizationIdEqualTo(organization.getId()).andEnableEqualTo(true); projectExample.createCriteria().andOrganizationIdEqualTo(organization.getId()).andEnableEqualTo(true);
List<Project> projectList = projectMapper.selectByExample(projectExample); List<Project> projectList = projectMapper.selectByExample(projectExample);
if (CollectionUtils.isNotEmpty(projectList)) { if (CollectionUtils.isNotEmpty(projectList)) {
Project project = projectList.get(0); Project project = projectList.getFirst();
user.setLastProjectId(project.getId()); user.setLastProjectId(project.getId());
updateUser(user); updateUser(user);
return true;
} }
return true;
} }
} }
//项目和组织都没有权限 //项目和组织都没有权限
OrganizationExample organizationExample = new OrganizationExample(); Project project = baseUserMapper.getEnableProjectAndOrganization();
organizationExample.createCriteria().andEnableEqualTo(true); if (project != null) {
List<Organization> organizations = organizationMapper.selectByExample(organizationExample); user.setLastProjectId(project.getId());
if (CollectionUtils.isNotEmpty(organizations)) { user.setLastOrganizationId(project.getOrganizationId());
Organization organization = organizations.get(0); updateUser(user);
ProjectExample projectExample = new ProjectExample(); return true;
projectExample.createCriteria().andOrganizationIdEqualTo(organization.getId()).andEnableEqualTo(true);
List<Project> projectList = projectMapper.selectByExample(projectExample);
if (CollectionUtils.isNotEmpty(projectList)) {
Project project = projectList.get(0);
user.setLastProjectId(project.getId());
user.setLastOrganizationId(organization.getId());
updateUser(user);
return true;
}
} }
return true;
} }
return false; return false;