diff --git a/backend/src/main/java/io/metersphere/controller/OrganizationController.java b/backend/src/main/java/io/metersphere/controller/OrganizationController.java index 1ebc2d3f6f..edd6699293 100644 --- a/backend/src/main/java/io/metersphere/controller/OrganizationController.java +++ b/backend/src/main/java/io/metersphere/controller/OrganizationController.java @@ -9,6 +9,7 @@ import io.metersphere.commons.utils.Pager; import io.metersphere.controller.request.OrganizationRequest; import io.metersphere.dto.OrganizationMemberDTO; import io.metersphere.service.OrganizationService; +import io.metersphere.service.UserService; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresRoles; import org.springframework.web.bind.annotation.*; @@ -22,6 +23,8 @@ public class OrganizationController { @Resource private OrganizationService organizationService; + @Resource + private UserService userService; @PostMapping("/add") @RequiresRoles(RoleConstants.ADMIN) @@ -45,6 +48,7 @@ public class OrganizationController { @GetMapping("/delete/{organizationId}") @RequiresRoles(RoleConstants.ADMIN) public void deleteOrganization(@PathVariable(value = "organizationId") String organizationId) { + userService.refreshSessionUser("organization", organizationId); organizationService.deleteOrganization(organizationId); } diff --git a/backend/src/main/java/io/metersphere/controller/UserController.java b/backend/src/main/java/io/metersphere/controller/UserController.java index 4d2a968141..85d2ec8d18 100644 --- a/backend/src/main/java/io/metersphere/controller/UserController.java +++ b/backend/src/main/java/io/metersphere/controller/UserController.java @@ -23,6 +23,7 @@ import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresRoles; import org.springframework.beans.BeanUtils; import org.springframework.web.bind.annotation.*; + import javax.annotation.Resource; import java.util.List; @@ -115,7 +116,7 @@ public class UserController { // admin api @GetMapping("/list") - @RequiresRoles(value = {RoleConstants.ADMIN,RoleConstants.ORG_ADMIN}, logical = Logical.OR) + @RequiresRoles(value = {RoleConstants.ADMIN, RoleConstants.ORG_ADMIN}, logical = Logical.OR) public List getUserList() { return userService.getUserList(); } @@ -132,17 +133,24 @@ public class UserController { @PostMapping("/switch/source/org/{sourceId}") @RequiresRoles(RoleConstants.ORG_ADMIN) public UserDTO switchOrganization(@PathVariable(value = "sourceId") String sourceId) { - userService.switchUserRole("organization",sourceId); + userService.switchUserRole("organization", sourceId); return SessionUtils.getUser(); } @PostMapping("/switch/source/ws/{sourceId}") - @RequiresRoles(value = {RoleConstants.TEST_MANAGER,RoleConstants.TEST_VIEWER,RoleConstants.TEST_USER}, logical = Logical.OR) + @RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_VIEWER, RoleConstants.TEST_USER}, logical = Logical.OR) public UserDTO switchWorkspace(@PathVariable(value = "sourceId") String sourceId) { userService.switchUserRole("workspace", sourceId); return SessionUtils.getUser(); } + @PostMapping("/refresh/{sign}/{sourceId}") + @RequiresRoles(RoleConstants.ADMIN) + public UserDTO refreshSessionUser(@PathVariable String sign, @PathVariable String sourceId) { + userService.refreshSessionUser(sign, sourceId); + return SessionUtils.getUser(); + } + @GetMapping("/info/{userId}") public User getUserInfo(@PathVariable(value = "userId") String userId) { return userService.getUserInfo(userId); @@ -152,8 +160,8 @@ public class UserController { * 获取工作空间成员用户 */ @PostMapping("/ws/member/list/{goPage}/{pageSize}") - @RequiresRoles(value = {RoleConstants.ORG_ADMIN,RoleConstants.TEST_MANAGER, - RoleConstants.TEST_USER,RoleConstants.TEST_VIEWER}, logical = Logical.OR) + @RequiresRoles(value = {RoleConstants.ORG_ADMIN, RoleConstants.TEST_MANAGER, + RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR) public Pager> getMemberList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryMemberRequest request) { Page page = PageHelper.startPage(goPage, pageSize, true); return PageUtils.setPageInfo(page, userService.getMemberList(request)); @@ -163,8 +171,8 @@ public class UserController { * 获取工作空间成员用户 不分页 */ @PostMapping("/ws/member/list/all") - @RequiresRoles(value = {RoleConstants.ORG_ADMIN,RoleConstants.TEST_MANAGER, - RoleConstants.TEST_USER,RoleConstants.TEST_VIEWER}, logical = Logical.OR) + @RequiresRoles(value = {RoleConstants.ORG_ADMIN, RoleConstants.TEST_MANAGER, + RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR) public List getMemberList(@RequestBody QueryMemberRequest request) { return userService.getMemberList(request); } @@ -173,7 +181,7 @@ public class UserController { * 添加工作空间成员 */ @PostMapping("/ws/member/add") - @RequiresRoles(value = {RoleConstants.TEST_MANAGER,RoleConstants.ORG_ADMIN}, logical = Logical.OR) + @RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.ORG_ADMIN}, logical = Logical.OR) public void addMember(@RequestBody AddMemberRequest request) { String wsId = request.getWorkspaceId(); workspaceService.checkWorkspaceOwner(wsId); @@ -184,7 +192,7 @@ public class UserController { * 删除工作空间成员 */ @GetMapping("/ws/member/delete/{workspaceId}/{userId}") - @RequiresRoles(value = {RoleConstants.TEST_MANAGER,RoleConstants.ORG_ADMIN}, logical = Logical.OR) + @RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.ORG_ADMIN}, logical = Logical.OR) public void deleteMember(@PathVariable String workspaceId, @PathVariable String userId) { workspaceService.checkWorkspaceOwner(workspaceId); String currentUserId = SessionUtils.getUser().getId(); @@ -222,7 +230,7 @@ public class UserController { * 查询组织成员列表 */ @PostMapping("/org/member/list/{goPage}/{pageSize}") - @RequiresRoles(value = {RoleConstants.ORG_ADMIN,RoleConstants.TEST_MANAGER}, logical = Logical.OR) + @RequiresRoles(value = {RoleConstants.ORG_ADMIN, RoleConstants.TEST_MANAGER}, logical = Logical.OR) public Pager> getOrgMemberList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryOrgMemberRequest request) { Page page = PageHelper.startPage(goPage, pageSize, true); return PageUtils.setPageInfo(page, userService.getOrgMemberList(request)); @@ -232,7 +240,7 @@ public class UserController { * 组织成员列表不分页 */ @PostMapping("/org/member/list/all") - @RequiresRoles(value = {RoleConstants.ORG_ADMIN,RoleConstants.TEST_MANAGER}, logical = Logical.OR) + @RequiresRoles(value = {RoleConstants.ORG_ADMIN, RoleConstants.TEST_MANAGER}, logical = Logical.OR) public List getOrgMemberList(@RequestBody QueryOrgMemberRequest request) { return userService.getOrgMemberList(request); } diff --git a/backend/src/main/java/io/metersphere/controller/WorkspaceController.java b/backend/src/main/java/io/metersphere/controller/WorkspaceController.java index be16dbe380..3c4f7e7182 100644 --- a/backend/src/main/java/io/metersphere/controller/WorkspaceController.java +++ b/backend/src/main/java/io/metersphere/controller/WorkspaceController.java @@ -10,12 +10,12 @@ import io.metersphere.controller.request.WorkspaceRequest; import io.metersphere.dto.WorkspaceDTO; import io.metersphere.dto.WorkspaceMemberDTO; import io.metersphere.service.OrganizationService; +import io.metersphere.service.UserService; import io.metersphere.service.WorkspaceService; import io.metersphere.user.SessionUtils; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresRoles; import org.springframework.web.bind.annotation.*; - import javax.annotation.Resource; import java.util.List; @@ -26,6 +26,8 @@ public class WorkspaceController { private WorkspaceService workspaceService; @Resource private OrganizationService organizationService; + @Resource + private UserService userService; @PostMapping("add") @RequiresRoles(RoleConstants.ORG_ADMIN) @@ -57,6 +59,7 @@ public class WorkspaceController { @GetMapping("special/delete/{workspaceId}") @RequiresRoles(RoleConstants.ADMIN) public void deleteWorkspaceByAdmin(@PathVariable String workspaceId) { + userService.refreshSessionUser("workspace", workspaceId); workspaceService.deleteWorkspace(workspaceId); } @@ -64,6 +67,7 @@ public class WorkspaceController { @RequiresRoles(RoleConstants.ORG_ADMIN) public void deleteWorkspace(@PathVariable String workspaceId) { workspaceService.checkWorkspaceOwnerByOrgAdmin(workspaceId); + userService.refreshSessionUser("workspace", workspaceId); workspaceService.deleteWorkspace(workspaceId); } diff --git a/backend/src/main/java/io/metersphere/service/UserService.java b/backend/src/main/java/io/metersphere/service/UserService.java index b40f1c4869..c0cf35db30 100644 --- a/backend/src/main/java/io/metersphere/service/UserService.java +++ b/backend/src/main/java/io/metersphere/service/UserService.java @@ -256,4 +256,23 @@ public class UserService { SessionUtils.getUser().setLanguage(lang); } } + + public void refreshSessionUser(String sign, String sourceId) { + SessionUser sessionUser = SessionUtils.getUser(); + // 获取最新UserDTO + UserDTO user = getUserDTO(sessionUser.getId()); + User newUser = new User(); + if (StringUtils.equals("organization", sign) && StringUtils.equals(sourceId, user.getLastOrganizationId())) { + user.setLastOrganizationId(""); + user.setLastWorkspaceId(""); + } + if (StringUtils.equals("workspace", sign) && StringUtils.equals(sourceId, user.getLastWorkspaceId())) { + user.setLastWorkspaceId(""); + } + + BeanUtils.copyProperties(user, newUser); + + SessionUtils.putUser(SessionUser.fromUser(user)); + userMapper.updateByPrimaryKeySelective(newUser); + } } diff --git a/frontend/src/business/components/settings/organization/OrganizationWorkspace.vue b/frontend/src/business/components/settings/organization/OrganizationWorkspace.vue index 24f9d4ca51..743a9b5065 100644 --- a/frontend/src/business/components/settings/organization/OrganizationWorkspace.vue +++ b/frontend/src/business/components/settings/organization/OrganizationWorkspace.vue @@ -145,12 +145,13 @@