fix(系统设置): 组织不存在项目时或项目被禁用涉及的路由跳转问题

--bug=1039530 --user=宋昌昌 【系统设置】项目-模版-新创建组织没有项目的情况下提示已开启项目模版,建议优化 https://www.tapd.cn/55049933/s/1505085
This commit is contained in:
song-cc-rock 2024-04-22 16:28:23 +08:00 committed by Craftsman
parent 5bde86d4d9
commit d9943bbf14
5 changed files with 53 additions and 21 deletions

View File

@ -113,10 +113,12 @@ public class BugAttachmentService {
Map<String, FileMetadata> fileMetadataMap = getLinkFileMetaMap(associateFileIds); Map<String, FileMetadata> fileMetadataMap = getLinkFileMetaMap(associateFileIds);
fileAssociations.forEach(associatedFile -> { fileAssociations.forEach(associatedFile -> {
FileMetadata associatedFileMetadata = fileMetadataMap.get(associatedFile.getFileId()); FileMetadata associatedFileMetadata = fileMetadataMap.get(associatedFile.getFileId());
BugFileDTO associatedFileDTO = BugFileDTO.builder().refId(associatedFile.getId()).fileId(associatedFile.getFileId()).fileName(associatedFileMetadata.getName() + "." + associatedFileMetadata.getType()) if (associatedFileMetadata != null) {
.fileType(associatedFileMetadata.getType()).fileSize(associatedFileMetadata.getSize()).createTime(associatedFileMetadata.getCreateTime()) BugFileDTO associatedFileDTO = BugFileDTO.builder().refId(associatedFile.getId()).fileId(associatedFile.getFileId()).fileName(associatedFileMetadata.getName() + "." + associatedFileMetadata.getType())
.createUser(associatedFileMetadata.getCreateUser()).local(false).build(); .fileType(associatedFileMetadata.getType()).fileSize(associatedFileMetadata.getSize()).createTime(associatedFileMetadata.getCreateTime())
bugFiles.add(associatedFileDTO); .createUser(associatedFileMetadata.getCreateUser()).local(false).build();
bugFiles.add(associatedFileDTO);
}
}); });
} }
if (CollectionUtils.isEmpty(bugFiles)) { if (CollectionUtils.isEmpty(bugFiles)) {

View File

@ -1,20 +1,22 @@
package io.metersphere.system.controller; package io.metersphere.system.controller;
import io.metersphere.project.domain.Project;
import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.sdk.constants.HttpMethodConstants; import io.metersphere.sdk.constants.HttpMethodConstants;
import io.metersphere.sdk.constants.UserSource; import io.metersphere.sdk.constants.UserSource;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.RsaKey;
import io.metersphere.sdk.util.RsaUtils;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.controller.handler.result.MsHttpResultCode; import io.metersphere.system.controller.handler.result.MsHttpResultCode;
import io.metersphere.system.dto.sdk.LoginRequest; import io.metersphere.system.dto.sdk.LoginRequest;
import io.metersphere.system.dto.sdk.SessionUser; import io.metersphere.system.dto.sdk.SessionUser;
import io.metersphere.system.dto.user.UserDTO; import io.metersphere.system.dto.user.UserDTO;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.service.UserLoginService; import io.metersphere.system.service.UserLoginService;
import io.metersphere.sdk.util.RsaKey;
import io.metersphere.sdk.util.RsaUtils;
import io.metersphere.system.utils.SessionUtils; import io.metersphere.system.utils.SessionUtils;
import io.metersphere.sdk.util.Translator;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@ -34,6 +36,8 @@ public class LoginController {
@Resource @Resource
private UserLoginService userLoginService; private UserLoginService userLoginService;
@Resource
private ProjectMapper projectMapper;
@GetMapping(value = "/is-login") @GetMapping(value = "/is-login")
@ -49,8 +53,9 @@ public class LoginController {
userLoginService.autoSwitch(userDTO); userLoginService.autoSwitch(userDTO);
SessionUser sessionUser = SessionUser.fromUser(userDTO, SessionUtils.getSessionId()); SessionUser sessionUser = SessionUser.fromUser(userDTO, SessionUtils.getSessionId());
SessionUtils.putUser(sessionUser); SessionUtils.putUser(sessionUser);
// 用户只有工作空间权限 // 用户只有工作空间权限, 或者项目已被禁用
if (StringUtils.isBlank(sessionUser.getLastProjectId())) { Project lastProject = projectMapper.selectByPrimaryKey(sessionUser.getLastProjectId());
if (StringUtils.isBlank(sessionUser.getLastProjectId()) || lastProject == null || !lastProject.getEnable()) {
sessionUser.setLastProjectId("no_such_project"); sessionUser.setLastProjectId("no_such_project");
} }
return ResultHolder.success(sessionUser); return ResultHolder.success(sessionUser);

View File

@ -12,7 +12,7 @@
import { getOrgOptions, switchUserOrg } from '@/api/modules/system'; import { getOrgOptions, switchUserOrg } from '@/api/modules/system';
import { useI18n } from '@/hooks/useI18n'; import { useI18n } from '@/hooks/useI18n';
import useUser from '@/hooks/useUser'; import useUser from '@/hooks/useUser';
import { BOTTOM_MENU_LIST } from '@/router/constants'; import { BOTTOM_MENU_LIST, NO_PROJECT_ROUTE_NAME } from '@/router/constants';
import { useAppStore, useUserStore } from '@/store'; import { useAppStore, useUserStore } from '@/store';
import useLicenseStore from '@/store/modules/setting/license'; import useLicenseStore from '@/store/modules/setting/license';
import { openWindow, regexUrl } from '@/utils'; import { openWindow, regexUrl } from '@/utils';
@ -20,7 +20,7 @@
import { getFisrtRouterNameByCurrentRoute } from '@/utils/permission'; import { getFisrtRouterNameByCurrentRoute } from '@/utils/permission';
import { listenerRouteChange } from '@/utils/route-listener'; import { listenerRouteChange } from '@/utils/route-listener';
import { SettingRouteEnum } from '@/enums/routeEnum'; import { ProjectManagementRouteEnum, SettingRouteEnum } from '@/enums/routeEnum';
import useMenuTree from './use-menu-tree'; import useMenuTree from './use-menu-tree';
import type { RouteMeta } from 'vue-router'; import type { RouteMeta } from 'vue-router';
@ -148,14 +148,34 @@
personalMenusVisible.value = false; personalMenusVisible.value = false;
orgKeyword.value = ''; orgKeyword.value = '';
await userStore.isLogin(true); await userStore.isLogin(true);
router.replace({ if (!appStore.currentProjectId || appStore.currentProjectId === 'no_such_project') {
path: route.path, // (, )
query: { router.push({
...route.query, name: NO_PROJECT_ROUTE_NAME,
orgId: appStore.currentOrgId, });
pId: appStore.currentProjectId, return;
}, }
}); if (route.name === NO_PROJECT_ROUTE_NAME) {
// ,
router.replace({
name: ProjectManagementRouteEnum.PROJECT_MANAGEMENT_PERMISSION_BASIC_INFO,
query: {
...route.query,
orgId: appStore.currentOrgId,
pId: appStore.currentProjectId,
},
});
} else {
//
router.replace({
path: route.path,
query: {
...route.query,
orgId: appStore.currentOrgId,
pId: appStore.currentProjectId,
},
});
}
} catch (error) { } catch (error) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log(error); console.log(error);

View File

@ -16,6 +16,7 @@ export default function usePermission() {
* @returns * @returns
*/ */
accessRouter(route: RouteLocationNormalized | RouteRecordRaw) { accessRouter(route: RouteLocationNormalized | RouteRecordRaw) {
console.log(useUserStore());
if ( if (
(useUserStore().lastProjectId === 'no_such_project' || useUserStore().lastProjectId === '') && (useUserStore().lastProjectId === 'no_such_project' || useUserStore().lastProjectId === '') &&
route.name === 'projectManagement' route.name === 'projectManagement'

View File

@ -36,7 +36,11 @@ const useTemplateStore = defineStore('template', {
if (currentOrgId.value && hasAnyPermission(['ORGANIZATION_TEMPLATE:READ'])) { if (currentOrgId.value && hasAnyPermission(['ORGANIZATION_TEMPLATE:READ'])) {
this.ordStatus = await getOrdTemplate(currentOrgId.value); this.ordStatus = await getOrdTemplate(currentOrgId.value);
} }
if (currentProjectId.value && hasAnyPermission(['PROJECT_TEMPLATE:READ'])) { if (
currentProjectId.value &&
hasAnyPermission(['PROJECT_TEMPLATE:READ']) &&
currentProjectId.value !== 'no_such_project'
) {
this.projectStatus = await getProTemplate(currentProjectId.value); this.projectStatus = await getProTemplate(currentProjectId.value);
} }
} catch (error) { } catch (error) {