diff --git a/backend/src/main/java/io/metersphere/service/WorkspaceService.java b/backend/src/main/java/io/metersphere/service/WorkspaceService.java index 5ba3806335..aa8ef7ebae 100644 --- a/backend/src/main/java/io/metersphere/service/WorkspaceService.java +++ b/backend/src/main/java/io/metersphere/service/WorkspaceService.java @@ -6,13 +6,15 @@ import io.metersphere.base.mapper.GroupMapper; import io.metersphere.base.mapper.ProjectMapper; import io.metersphere.base.mapper.UserGroupMapper; import io.metersphere.base.mapper.WorkspaceMapper; -import io.metersphere.base.mapper.ext.*; +import io.metersphere.base.mapper.ext.ExtOrganizationMapper; +import io.metersphere.base.mapper.ext.ExtUserGroupMapper; +import io.metersphere.base.mapper.ext.ExtUserMapper; +import io.metersphere.base.mapper.ext.ExtWorkspaceMapper; import io.metersphere.commons.constants.UserGroupConstants; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.SessionUtils; import io.metersphere.controller.request.WorkspaceRequest; import io.metersphere.dto.RelatedSource; -import io.metersphere.dto.UserRoleHelpDTO; import io.metersphere.dto.WorkspaceDTO; import io.metersphere.dto.WorkspaceMemberDTO; import io.metersphere.i18n.Translator; @@ -40,8 +42,6 @@ public class WorkspaceService { @Resource private ExtWorkspaceMapper extWorkspaceMapper; @Resource - private ExtUserRoleMapper extUserRoleMapper; - @Resource private GroupMapper groupMapper; @Resource private ExtOrganizationMapper extOrganizationMapper; @@ -195,15 +195,14 @@ public class WorkspaceService { } public List getWorkspaceListByUserId(String userId) { - List userRoleHelpList = extUserRoleMapper.getUserRoleHelpList(userId); - List workspaceIds = new ArrayList<>(); - userRoleHelpList.forEach(r -> { - if (!StringUtils.isEmpty(r.getParentId())) { - workspaceIds.add(r.getSourceId()); - } - }); + List relatedSource = extUserGroupMapper.getRelatedSource(userId); + List wsIds = relatedSource + .stream() + .map(RelatedSource::getWorkspaceId) + .distinct() + .collect(Collectors.toList()); WorkspaceExample workspaceExample = new WorkspaceExample(); - workspaceExample.createCriteria().andIdIn(workspaceIds); + workspaceExample.createCriteria().andIdIn(wsIds); return workspaceMapper.selectByExample(workspaceExample); } diff --git a/backend/src/main/resources/db/migration/V97__v1.14_release.sql b/backend/src/main/resources/db/migration/V97__v1.14_release.sql index e24d3d1be0..2df84d39c2 100644 --- a/backend/src/main/resources/db/migration/V97__v1.14_release.sql +++ b/backend/src/main/resources/db/migration/V97__v1.14_release.sql @@ -1 +1,38 @@ -alter table test_plan drop column principal; \ No newline at end of file +ALTER TABLE test_plan + DROP COLUMN principal; + +-- 组织用户组配置到工作空间上 +DROP PROCEDURE IF EXISTS test_cursor; +DELIMITER // +CREATE PROCEDURE test_cursor() +BEGIN + DECLARE sourceId VARCHAR(64); + DECLARE userId VARCHAR(64); + DECLARE groupId VARCHAR(64); + DECLARE done INT DEFAULT 0; + DECLARE cursor1 CURSOR FOR (SELECT user_id, source_id, group_id + FROM user_group + WHERE group_id IN ('org_admin', 'org_member')); + + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + OPEN cursor1; + outer_loop: + LOOP + FETCH cursor1 INTO userId, sourceId, groupId; + IF done + THEN + LEAVE outer_loop; + END IF; + INSERT INTO user_group (id, user_id, group_id, source_id, create_time, update_time) + SELECT UUID(), userId, REPLACE(groupId, 'org', 'ws'), id, create_time, update_time + FROM workspace + WHERE organization_id = sourceId; + END LOOP; + CLOSE cursor1; +END +// +DELIMITER ; + +CALL test_cursor(); +DROP PROCEDURE IF EXISTS test_cursor; \ No newline at end of file diff --git a/frontend/src/business/components/common/head/HeaderOrgWs.vue b/frontend/src/business/components/common/head/HeaderOrgWs.vue index 2fc70aa047..2ba49c5bac 100644 --- a/frontend/src/business/components/common/head/HeaderOrgWs.vue +++ b/frontend/src/business/components/common/head/HeaderOrgWs.vue @@ -1,57 +1,19 @@