Search in sources :

Example 1 with IamRoleVO

use of com.diboot.iam.vo.IamRoleVO in project diboot by dibo-software.

the class IamUserRoleServiceImpl method buildRoleVo4FrontEnd.

@Override
public IamRoleVO buildRoleVo4FrontEnd(BaseLoginUser loginUser) {
    List<IamRoleVO> roleVOList = getAllRoleVOList(loginUser);
    if (V.isEmpty(roleVOList)) {
        return null;
    }
    // 附加额外的一些权限给与特性的角色
    for (IamRoleVO roleVO : roleVOList) {
        if (Cons.ROLE_SUPER_ADMIN.equalsIgnoreCase(roleVO.getCode())) {
            List<IamResourcePermission> iamPermissions = iamResourcePermissionService.getAllResourcePermissions(Cons.APPLICATION);
            roleVO.setPermissionList(iamPermissions);
            break;
        }
    }
    // 组合为前端格式
    return IamHelper.buildRoleVo4FrontEnd(roleVOList);
}
Also used : IamRoleVO(com.diboot.iam.vo.IamRoleVO)

Example 2 with IamRoleVO

use of com.diboot.iam.vo.IamRoleVO in project diboot by dibo-software.

the class IamHelper method buildRoleVo4FrontEnd.

/**
 * 构建role-permission角色权限数据格式(合并role等),用于前端适配
 * @param roleVOList
 * @return
 */
public static IamRoleVO buildRoleVo4FrontEnd(List<IamRoleVO> roleVOList) {
    if (V.isEmpty(roleVOList)) {
        return null;
    }
    // 对RoleList做聚合处理,以适配前端
    List<String> nameList = new ArrayList<>(roleVOList.size());
    List<String> codeList = new ArrayList<>(roleVOList.size());
    List<IamResourcePermission> allPermissionList = new ArrayList<>();
    roleVOList.forEach(vo -> {
        nameList.add(vo.getName());
        codeList.add(vo.getCode());
        if (V.notEmpty(vo.getPermissionList())) {
            allPermissionList.addAll(vo.getPermissionList());
        }
    });
    // 对permissionList进行去重
    List permissionList = BeanUtils.distinctByKey(allPermissionList, IamResourcePermission::getId);
    IamRoleVO roleVO = new IamRoleVO();
    roleVO.setName(S.join(nameList));
    roleVO.setCode(S.join(codeList));
    roleVO.setPermissionList(permissionList);
    return roleVO;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) IamResourcePermission(com.diboot.iam.entity.IamResourcePermission) IamRoleVO(com.diboot.iam.vo.IamRoleVO)

Aggregations

IamRoleVO (com.diboot.iam.vo.IamRoleVO)2 IamResourcePermission (com.diboot.iam.entity.IamResourcePermission)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1