From d9943bbf14bf3978de1ba3aa32af15f1c7941bda Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Mon, 22 Apr 2024 16:28:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E7=BB=84=E7=BB=87=E4=B8=8D=E5=AD=98=E5=9C=A8=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=97=B6=E6=88=96=E9=A1=B9=E7=9B=AE=E8=A2=AB=E7=A6=81=E7=94=A8?= =?UTF-8?q?=E6=B6=89=E5=8F=8A=E7=9A=84=E8=B7=AF=E7=94=B1=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1039530 --user=宋昌昌 【系统设置】项目-模版-新创建组织没有项目的情况下提示已开启项目模版,建议优化 https://www.tapd.cn/55049933/s/1505085 --- .../bug/service/BugAttachmentService.java | 10 +++-- .../system/controller/LoginController.java | 17 +++++--- .../src/components/business/ms-menu/index.vue | 40 ++++++++++++++----- frontend/src/hooks/usePermission.ts | 1 + .../src/store/modules/setting/template.ts | 6 ++- 5 files changed, 53 insertions(+), 21 deletions(-) diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugAttachmentService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugAttachmentService.java index e525f7f40e..9b27b92cf4 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugAttachmentService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugAttachmentService.java @@ -113,10 +113,12 @@ public class BugAttachmentService { Map fileMetadataMap = getLinkFileMetaMap(associateFileIds); fileAssociations.forEach(associatedFile -> { FileMetadata associatedFileMetadata = fileMetadataMap.get(associatedFile.getFileId()); - BugFileDTO associatedFileDTO = BugFileDTO.builder().refId(associatedFile.getId()).fileId(associatedFile.getFileId()).fileName(associatedFileMetadata.getName() + "." + associatedFileMetadata.getType()) - .fileType(associatedFileMetadata.getType()).fileSize(associatedFileMetadata.getSize()).createTime(associatedFileMetadata.getCreateTime()) - .createUser(associatedFileMetadata.getCreateUser()).local(false).build(); - bugFiles.add(associatedFileDTO); + if (associatedFileMetadata != null) { + BugFileDTO associatedFileDTO = BugFileDTO.builder().refId(associatedFile.getId()).fileId(associatedFile.getFileId()).fileName(associatedFileMetadata.getName() + "." + associatedFileMetadata.getType()) + .fileType(associatedFileMetadata.getType()).fileSize(associatedFileMetadata.getSize()).createTime(associatedFileMetadata.getCreateTime()) + .createUser(associatedFileMetadata.getCreateUser()).local(false).build(); + bugFiles.add(associatedFileDTO); + } }); } if (CollectionUtils.isEmpty(bugFiles)) { diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/LoginController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/LoginController.java index fd50185534..74de4ff020 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/LoginController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/LoginController.java @@ -1,20 +1,22 @@ 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.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.result.MsHttpResultCode; import io.metersphere.system.dto.sdk.LoginRequest; import io.metersphere.system.dto.sdk.SessionUser; import io.metersphere.system.dto.user.UserDTO; -import io.metersphere.sdk.exception.MSException; import io.metersphere.system.log.constants.OperationLogType; 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.sdk.util.Translator; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; @@ -34,6 +36,8 @@ public class LoginController { @Resource private UserLoginService userLoginService; + @Resource + private ProjectMapper projectMapper; @GetMapping(value = "/is-login") @@ -49,8 +53,9 @@ public class LoginController { userLoginService.autoSwitch(userDTO); SessionUser sessionUser = SessionUser.fromUser(userDTO, SessionUtils.getSessionId()); 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"); } return ResultHolder.success(sessionUser); diff --git a/frontend/src/components/business/ms-menu/index.vue b/frontend/src/components/business/ms-menu/index.vue index 3bcab67b22..c16fe60605 100644 --- a/frontend/src/components/business/ms-menu/index.vue +++ b/frontend/src/components/business/ms-menu/index.vue @@ -12,7 +12,7 @@ import { getOrgOptions, switchUserOrg } from '@/api/modules/system'; import { useI18n } from '@/hooks/useI18n'; 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 useLicenseStore from '@/store/modules/setting/license'; import { openWindow, regexUrl } from '@/utils'; @@ -20,7 +20,7 @@ import { getFisrtRouterNameByCurrentRoute } from '@/utils/permission'; import { listenerRouteChange } from '@/utils/route-listener'; - import { SettingRouteEnum } from '@/enums/routeEnum'; + import { ProjectManagementRouteEnum, SettingRouteEnum } from '@/enums/routeEnum'; import useMenuTree from './use-menu-tree'; import type { RouteMeta } from 'vue-router'; @@ -148,14 +148,34 @@ personalMenusVisible.value = false; orgKeyword.value = ''; await userStore.isLogin(true); - router.replace({ - path: route.path, - query: { - ...route.query, - orgId: appStore.currentOrgId, - pId: appStore.currentProjectId, - }, - }); + if (!appStore.currentProjectId || appStore.currentProjectId === 'no_such_project') { + // 没有项目权限(组织没有项目, 或项目全被禁用) + router.push({ + name: NO_PROJECT_ROUTE_NAME, + }); + 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) { // eslint-disable-next-line no-console console.log(error); diff --git a/frontend/src/hooks/usePermission.ts b/frontend/src/hooks/usePermission.ts index 1456aaa911..ad503f7d38 100644 --- a/frontend/src/hooks/usePermission.ts +++ b/frontend/src/hooks/usePermission.ts @@ -16,6 +16,7 @@ export default function usePermission() { * @returns 是否 */ accessRouter(route: RouteLocationNormalized | RouteRecordRaw) { + console.log(useUserStore()); if ( (useUserStore().lastProjectId === 'no_such_project' || useUserStore().lastProjectId === '') && route.name === 'projectManagement' diff --git a/frontend/src/store/modules/setting/template.ts b/frontend/src/store/modules/setting/template.ts index b639e01e78..aca9691428 100644 --- a/frontend/src/store/modules/setting/template.ts +++ b/frontend/src/store/modules/setting/template.ts @@ -36,7 +36,11 @@ const useTemplateStore = defineStore('template', { if (currentOrgId.value && hasAnyPermission(['ORGANIZATION_TEMPLATE:READ'])) { 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); } } catch (error) {