feat:(feature/REQ-2750-1) 改造list接口,支持超管角色合并
This commit is contained in:
parent
53aa5c0ebc
commit
e34157104b
@ -91,13 +91,9 @@ public class SaasRoleDao extends ServiceImpl<SaasRoleMapper, SaasRole> {
|
||||
.list();
|
||||
}
|
||||
|
||||
public Page<SaasRole> pageQueryForOUWorkspace(RoleWithUserQueryReq req) {
|
||||
public Page<SaasRole> pageQueryForOUWorkspace(RoleWithUserQueryReq req, Integer superAdminWorkspaceType) {
|
||||
IPage<SaasRole> page = new Page<>(req.getPage(), req.getPageSize());
|
||||
return this.baseMapper.pageQueryForOUWorkspace(page, req.getOuId(), req.getWorkspaceId(), req.getWorkspaceJoinType());
|
||||
}
|
||||
|
||||
public List<SaasRole> listForOUWorkspace(Long ouId, Long workspaceId, Integer workspaceJoinType) {
|
||||
return this.baseMapper.listForOUWorkspace(ouId, workspaceId, workspaceJoinType);
|
||||
return this.baseMapper.pageQueryForOUWorkspace(page, req.getOuId(), req.getWorkspaceId(), req.getWorkspaceJoinType(), superAdminWorkspaceType);
|
||||
}
|
||||
|
||||
public void removeWorkspaceOuAllRole(Long workspaceId, Long ouId) {
|
||||
|
||||
@ -22,7 +22,8 @@ public interface SaasRoleMapper extends BaseMapper<SaasRole> {
|
||||
|
||||
List<SaasRoleWithUser> listRoleUserByPermissionGroup(List<Long> permissionGroupIds, Set<Long> workspaceIds);
|
||||
|
||||
Page<SaasRole> pageQueryForOUWorkspace(IPage<SaasRole> page, Long ouId, Long workspaceId, Integer workspaceJoinType);
|
||||
Page<SaasRole> pageQueryForOUWorkspace(IPage<SaasRole> page, Long ouId, Long workspaceId, Integer workspaceJoinType,
|
||||
Integer superAdminWorkspaceType);
|
||||
|
||||
List<SaasRole> listForOUWorkspace(Long ouId, Long workspaceId, Integer workspaceJoinType);
|
||||
|
||||
|
||||
@ -378,6 +378,8 @@ public class RoleServiceImpl extends ServiceImpl<SaasRoleMapper, SaasRole>
|
||||
}
|
||||
|
||||
return saasRoleDao.lambdaQuery()
|
||||
.eq(SaasRole::getWorkspaceId, 0)
|
||||
.eq(SaasRole::getOwnerOuId, 0)
|
||||
.in(SaasRole::getWorkspaceType, Lists.transform(workspaces, SimpleWorkspaceRes::getType))
|
||||
.eq(SaasRole::getRoleType, RoleTypeEnum.SUPER_ADMIN.getValue())
|
||||
.list();
|
||||
@ -876,11 +878,35 @@ public class RoleServiceImpl extends ServiceImpl<SaasRoleMapper, SaasRole>
|
||||
.list();
|
||||
}
|
||||
|
||||
/**
|
||||
* 历史每个workspaceId都有一个超管角色,现在每个业务类一个超管角色,
|
||||
* 新的超管角色workspaceId = 0(不是-1是因为很多接口默认就会查询-1的数据,要过滤掉超管角色比较复杂)
|
||||
* 历史传入workspaceId时会查询出项目的超管角色,所以有传workspaceId时需要兼容历史接口
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
private Integer resolveSuperAdminWorkspaceType(RoleWithUserQueryReq req) {
|
||||
if (Objects.isNull(req.getWorkspaceId())) {
|
||||
return null;
|
||||
}
|
||||
GetSimpleWorkspaceReqV2 build = GetSimpleWorkspaceReqV2.builder()
|
||||
.ids(Lists.newArrayList(req.getWorkspaceId()))
|
||||
.build();
|
||||
List<SimpleWorkspaceRes> workspaces = RpcExternalUtil.rpcApolloProcessor(() -> workspaceApi.getListV2(build),
|
||||
"查询项目信息", build);
|
||||
return workspaces.stream()
|
||||
.map(SimpleWorkspaceRes::getType)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResp<RoleWithUserRes> queryRoleWithUser(RoleWithUserQueryReq req) {
|
||||
page2Default(req);
|
||||
//按role进行分页查询 -
|
||||
Page<SaasRole> rolePage = saasRoleDao.pageQueryForOUWorkspace(req);
|
||||
Integer superAdminWorkspaceType = resolveSuperAdminWorkspaceType(req);
|
||||
Page<SaasRole> rolePage = saasRoleDao.pageQueryForOUWorkspace(req, superAdminWorkspaceType);
|
||||
|
||||
if (CollectionUtil.isEmpty(rolePage.getRecords())) {
|
||||
return PageResp.list(req.getPage(), req.getPageSize(), 0L, Collections.emptyList());
|
||||
}
|
||||
@ -1337,6 +1363,9 @@ public class RoleServiceImpl extends ServiceImpl<SaasRoleMapper, SaasRole>
|
||||
wrapper.in(CollectionUtils.isNotEmpty(roleIds), "id", roleIds);
|
||||
}
|
||||
|
||||
// 因为历史是每一个workspaceId一个超管角色,现在是一个workspaceType一个超管角色,
|
||||
// 为了兼容历史情况,入参有workspaceId,且roleType为空或者roleType包含superAdmin的,需要组装superAdmin的查询条件
|
||||
|
||||
|
||||
IPage<SaasRole> page = this.page(PageConverter.toMybatis(param, SaasRole.class), wrapper);
|
||||
|
||||
|
||||
@ -104,6 +104,8 @@
|
||||
( r.workspace_id = #{workspaceId} AND r.owner_ou_id = #{ouId} AND (r.role_type = 'common' OR r.role_type = 'super_admin') )
|
||||
OR
|
||||
( r.owner_ou_id = - 1 AND FIND_IN_SET( #{workspaceJoinType},g.ou_type_code) > 0)
|
||||
OR
|
||||
( r.workspace_type = #{superAdminWorkspaceType} AND r.workspace_id = 0 AND r.owner_ou_id = 0 and r.role_type = 'super_admin')
|
||||
)
|
||||
</sql>
|
||||
|
||||
@ -111,10 +113,6 @@
|
||||
<include refid="sql-queryForOUWorkspace"/>
|
||||
</select>
|
||||
|
||||
<select id="listForOUWorkspace" resultType="cn.axzo.tyr.server.repository.entity.SaasRole">
|
||||
<include refid="sql-queryForOUWorkspace"/>
|
||||
</select>
|
||||
|
||||
<select id="listFeatureByIds" resultType="cn.axzo.tyr.server.model.RoleFeatureRelation">
|
||||
SELECT rg.role_id AS roleId, pg.feature_id AS featureId
|
||||
FROM saas_pgroup_role_relation rg, saas_pgroup_permission_relation pg
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package cn.axzo.tyr.base;
|
||||
|
||||
import cn.axzo.apollo.workspace.api.workspace.WorkspaceApi;
|
||||
import cn.axzo.basics.profiles.api.UserProfileServiceApi;
|
||||
import cn.axzo.framework.rocketmq.Event;
|
||||
import cn.axzo.framework.rocketmq.EventProducer;
|
||||
import cn.axzo.thrones.client.saas.ServicePkgClient;
|
||||
@ -46,6 +47,8 @@ public class TestConfig {
|
||||
|
||||
@MockBean
|
||||
private WorkspaceApi workspaceApi;
|
||||
@MockBean
|
||||
private UserProfileServiceApi userProfileServiceApi;
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
|
||||
@ -69,18 +69,6 @@ public class RoleUserTest {
|
||||
System.out.println(JSON.toJSONString(result));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPageQueryForOUWorkspace() {
|
||||
RoleWithUserQueryReq req = new RoleWithUserQueryReq();
|
||||
req.setOuId(5195L);
|
||||
req.setWorkspaceId(371L);
|
||||
req.setWorkspaceJoinType(2);
|
||||
req.setPage(1L);
|
||||
req.setPageSize(20L);
|
||||
Page<SaasRole> page = saasRoleDao.pageQueryForOUWorkspace(req);
|
||||
System.out.println(JSON.toJSONString(page));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListAdmin() {
|
||||
roleService.listAdmins(111L, 22L);
|
||||
|
||||
@ -4,13 +4,18 @@ import cn.axzo.apollo.core.web.Results;
|
||||
import cn.axzo.apollo.workspace.api.workspace.WorkspaceApi;
|
||||
import cn.axzo.apollo.workspace.api.workspace.req.GetSimpleWorkspaceReqV2;
|
||||
import cn.axzo.apollo.workspace.api.workspace.res.SimpleWorkspaceRes;
|
||||
import cn.axzo.basics.profiles.api.UserProfileServiceApi;
|
||||
import cn.axzo.tyr.base.BaseTest;
|
||||
import cn.axzo.tyr.base.MysqlDataLoader;
|
||||
import cn.axzo.tyr.client.common.enums.RoleTypeEnum;
|
||||
import cn.axzo.tyr.client.model.req.ListRoleReq;
|
||||
import cn.axzo.tyr.client.model.req.QueryByIdentityIdTypeReq;
|
||||
import cn.axzo.tyr.client.model.req.QuerySaasRoleReq;
|
||||
import cn.axzo.tyr.client.model.res.IsSuperAdminRes;
|
||||
import cn.axzo.tyr.client.model.res.SaasRoleRes;
|
||||
import cn.axzo.tyr.client.model.roleuser.req.ListRoleUserRelationParam;
|
||||
import cn.axzo.tyr.client.model.vo.SaasRoleVO;
|
||||
import cn.azxo.framework.common.model.CommonResponse;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
@ -20,7 +25,10 @@ import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class RoleServiceTest extends BaseTest {
|
||||
|
||||
@ -30,6 +38,8 @@ class RoleServiceTest extends BaseTest {
|
||||
private MysqlDataLoader mysqlDataLoader;
|
||||
@Autowired
|
||||
private WorkspaceApi workspaceApi;
|
||||
@Autowired
|
||||
private UserProfileServiceApi userProfileServiceApi;
|
||||
|
||||
@BeforeEach
|
||||
@Override
|
||||
@ -78,6 +88,99 @@ class RoleServiceTest extends BaseTest {
|
||||
.roleIds(Lists.newArrayList(24425L, 25324L))
|
||||
.build());
|
||||
Assertions.assertEquals(roles.size(), 2);
|
||||
|
||||
Mockito.when(userProfileServiceApi.postPersonProfiles(Mockito.any()))
|
||||
.thenReturn(CommonResponse.success(Lists.newArrayList()));
|
||||
|
||||
// 根据workspaceId查询所有角色,包括超管
|
||||
roles = roleService.list(ListRoleReq.builder()
|
||||
.workspaceOuPairs(Lists.newArrayList(ListRoleUserRelationParam.WorkspaceOuPair.builder()
|
||||
.workspaceId(3L)
|
||||
.ouId(4L)
|
||||
.build()))
|
||||
.needRoleUser(true)
|
||||
.build());
|
||||
Assertions.assertEquals(roles.size(), 2);
|
||||
Assertions.assertEquals(roles.stream()
|
||||
.filter(e -> Objects.equals(e.getRoleType(), RoleTypeEnum.SUPER_ADMIN.getValue()))
|
||||
.map(SaasRoleRes::getSaasRoleUsers)
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList())
|
||||
.size(), 1);
|
||||
|
||||
Assertions.assertEquals(roles.stream()
|
||||
.filter(e -> Objects.equals(e.getRoleType(), RoleTypeEnum.COMMON.getValue()))
|
||||
.map(SaasRoleRes::getSaasRoleUsers)
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList())
|
||||
.size(), 0);
|
||||
// 根据workspaceId查询所有角色,包括超管
|
||||
|
||||
// 根据workspaceId查询超管角色
|
||||
roles = roleService.list(ListRoleReq.builder()
|
||||
.workspaceOuPairs(Lists.newArrayList(ListRoleUserRelationParam.WorkspaceOuPair.builder()
|
||||
.workspaceId(3L)
|
||||
.ouId(4L)
|
||||
.build()))
|
||||
.roleTypes(Lists.newArrayList(RoleTypeEnum.SUPER_ADMIN.getValue()))
|
||||
.needRoleUser(true)
|
||||
.build());
|
||||
Assertions.assertEquals(roles.size(), 1);
|
||||
Assertions.assertEquals(roles.stream()
|
||||
.filter(e -> Objects.equals(e.getRoleType(), RoleTypeEnum.SUPER_ADMIN.getValue()))
|
||||
.map(SaasRoleRes::getSaasRoleUsers)
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList())
|
||||
.size(), 1);
|
||||
// 根据workspaceId查询超管角色
|
||||
|
||||
// 根据workspaceId查询自定义角色
|
||||
roles = roleService.list(ListRoleReq.builder()
|
||||
.workspaceOuPairs(Lists.newArrayList(ListRoleUserRelationParam.WorkspaceOuPair.builder()
|
||||
.workspaceId(3L)
|
||||
.ouId(4L)
|
||||
.build()))
|
||||
.roleTypes(Lists.newArrayList(RoleTypeEnum.COMMON.getValue()))
|
||||
.needRoleUser(true)
|
||||
.build());
|
||||
Assertions.assertEquals(roles.size(), 1);
|
||||
Assertions.assertEquals(roles.stream()
|
||||
.filter(e -> Objects.equals(e.getRoleType(), RoleTypeEnum.COMMON.getValue()))
|
||||
.map(SaasRoleRes::getSaasRoleUsers)
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList())
|
||||
.size(), 0);
|
||||
// 根据workspaceId查询自定义角色
|
||||
|
||||
// 根据workspaceId查询自定义角色、预设角色
|
||||
roles = roleService.list(ListRoleReq.builder()
|
||||
.workspaceOuPairs(Lists.newArrayList(ListRoleUserRelationParam.WorkspaceOuPair.builder()
|
||||
.workspaceId(3L)
|
||||
.ouId(4L)
|
||||
.build()))
|
||||
.needRoleUser(true)
|
||||
.needPresetRole(true)
|
||||
.build());
|
||||
Assertions.assertEquals(roles.size(), 6);
|
||||
Assertions.assertEquals(roles.stream()
|
||||
.filter(e -> Objects.equals(e.getRoleType(), RoleTypeEnum.COMMON.getValue()))
|
||||
.map(SaasRoleRes::getSaasRoleUsers)
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList())
|
||||
.size(), 0);
|
||||
Assertions.assertEquals(roles.stream()
|
||||
.filter(e -> Objects.equals(e.getRoleType(), RoleTypeEnum.SUPER_ADMIN.getValue()))
|
||||
.map(SaasRoleRes::getSaasRoleUsers)
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList())
|
||||
.size(), 1);
|
||||
// 根据workspaceId查询自定义角色、预设角色
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -140,7 +243,30 @@ class RoleServiceTest extends BaseTest {
|
||||
.workspaceId(Lists.newArrayList(3L))
|
||||
.ouId(Lists.newArrayList(4L))
|
||||
.build());
|
||||
Assertions.assertEquals(query.size(), 3);
|
||||
Assertions.assertEquals(query.size(), 4);
|
||||
// 根据workspaceId、workspaceTypeCode查询
|
||||
}
|
||||
|
||||
@Test
|
||||
void isSuperAdmin() {
|
||||
List<IsSuperAdminRes> superAdmin = roleService.isSuperAdmin(Lists.newArrayList(QueryByIdentityIdTypeReq.builder()
|
||||
.identityId(28801L)
|
||||
.identityType(3)
|
||||
.workspaceId(3L)
|
||||
.ouId(4L)
|
||||
.personId(24510L)
|
||||
.build()));
|
||||
Assertions.assertEquals(superAdmin.size(), 1);
|
||||
Assertions.assertTrue(superAdmin.get(0).getIsSuperAdmin());
|
||||
|
||||
superAdmin = roleService.isSuperAdmin(Lists.newArrayList(QueryByIdentityIdTypeReq.builder()
|
||||
.identityId(28802L)
|
||||
.identityType(3)
|
||||
.workspaceId(3L)
|
||||
.ouId(4L)
|
||||
.personId(24511L)
|
||||
.build()));
|
||||
Assertions.assertEquals(superAdmin.size(), 1);
|
||||
Assertions.assertFalse(superAdmin.get(0).getIsSuperAdmin());
|
||||
}
|
||||
}
|
||||
@ -28,6 +28,9 @@ VALUES (101102, '超级管理员', '超级管理员', 'super_admin', 'oms_supera
|
||||
INSERT INTO saas_role (id, NAME, description, role_type, role_code, workspace_id, owner_ou_id, product_unit_type, workspace_type, is_delete, create_at, update_at, create_by, update_by, fit_ou_type_bit, fit_ou_node_type_bit, position_template_id, project_team_manage_role_resource_id, from_pre_role_id, job_code, is_display, sort, enabled)
|
||||
VALUES (101103, '超级管理员', '超级管理员', 'super_admin', 'zw_superadmin', 0, 0, 3, 3, 0, '2024-09-25 21:47:42', '2024-09-29 17:17:27', 2051297, 2051297, 1, 65535, 0, null, 0, '', 1, 0, 1);
|
||||
|
||||
INSERT INTO saas_role (id, NAME, description, role_type, role_code, workspace_id, owner_ou_id, product_unit_type, workspace_type, is_delete, create_at, update_at, create_by, update_by, fit_ou_type_bit, fit_ou_node_type_bit, position_template_id, project_team_manage_role_resource_id, from_pre_role_id, job_code, is_display, sort, enabled)
|
||||
VALUES (3416, '自定义', '', 'common', '', 3, 4, 1, 2, 0, '2022-10-19 15:52:33', '2024-09-29 17:16:27', 0, 0, 65535, 65535, 0, 0, 0, '', 1, 0, 1);
|
||||
|
||||
INSERT INTO saas_role_group_relation (id, role_id, saas_role_group_id, is_delete, create_at, update_at)
|
||||
VALUES (549, 101100, 18, 0, '2024-09-25 21:47:42', '2024-09-25 21:47:42');
|
||||
INSERT INTO saas_role_group_relation (id, role_id, saas_role_group_id, is_delete, create_at, update_at)
|
||||
@ -47,10 +50,11 @@ VALUES (197519, 28801, 3414, 3, 24510, 3, 4, 0, 0, 0, '2024-01-18 16:36:16', '20
|
||||
INSERT INTO saas_role_user_relation (id, identity_id, role_id, identity_type, natural_person_id, workspace_id, ou_id, resource_type, resource_id, is_delete, create_at, update_at, create_by, update_by, job_type)
|
||||
VALUES (183677, 40, 3415, 3, 2232, 8, 1, 0, 0, 0, '2023-10-06 15:13:35', '2024-09-29 17:16:39', 0, 0, 2);
|
||||
INSERT INTO saas_role_user_relation (id, identity_id, role_id, identity_type, natural_person_id, workspace_id, ou_id, resource_type, resource_id, is_delete, create_at, update_at, create_by, update_by, job_type)
|
||||
VALUES (1158315, 30903, 101100, 3, 25998, 3, 4, 0, 0, 0, '2024-09-29 16:33:31', '2024-09-29 16:33:31', 0, 0, 2);
|
||||
VALUES (1158315, 28801, 101100, 3, 24510, 3, 4, 0, 0, 0, '2024-09-29 16:33:31', '2024-09-29 16:33:31', 0, 0, 2);
|
||||
INSERT INTO saas_role_user_relation (id, identity_id, role_id, identity_type, natural_person_id, workspace_id, ou_id, resource_type, resource_id, is_delete, create_at, update_at, create_by, update_by, job_type)
|
||||
VALUES (1157571, 2007583, 101101, 3, 60411, 8, 1, 0, 0, 0, '2024-09-27 09:39:49', '2024-09-27 09:39:48', 0, 0, 2);
|
||||
|
||||
VALUES (1157571, 40, 101101, 3, 2232, 8, 1, 0, 0, 0, '2024-09-27 09:39:49', '2024-09-27 09:39:48', 0, 0, 2);
|
||||
INSERT INTO saas_role_user_relation (id, identity_id, role_id, identity_type, natural_person_id, workspace_id, ou_id, resource_type, resource_id, is_delete, create_at, update_at, create_by, update_by, job_type)
|
||||
VALUES (197520, 28802, 24425, 3, 24511, 3, 4, 0, 0, 0, '2024-01-18 16:36:16', '2024-09-29 17:16:39', 0, 0, 2);
|
||||
|
||||
|
||||
#-->SaasRoleUserRelationServiceImplTest.sql
|
||||
Loading…
Reference in New Issue
Block a user