fix: 调整 Permissions 接口
1.Permissions 只查询已分配的 workspace 2.内置 readonly 角色
This commit is contained in:
@@ -13,9 +13,8 @@ import net.geedge.asw.module.sys.entity.SysRoleEntity;
|
||||
@Mapper
|
||||
public interface SysRoleDao extends BaseMapper<SysRoleEntity> {
|
||||
|
||||
@Select("select sr.* from sys_role sr left join sys_user_role sur on sr.id = sur.role_id where sur.user_id = #{userId}")
|
||||
public List<SysRoleEntity> findRoleByUserId(String userId);
|
||||
|
||||
@Select("select sm.* from sys_menu sm LEFT JOIN sys_role_menu srm on sm.id = srm.menu_id LEFT JOIN sys_user_role sur on srm.role_id = sur.role_id where sur.user_id = #{userId} and sm.state = 1 order by sm.order")
|
||||
public List<SysMenuEntity> findMenuByUserId(String userId);
|
||||
|
||||
@Select("select sm.* from sys_menu sm LEFT JOIN sys_role_menu srm on sm.id = srm.menu_id LEFT JOIN sys_user_role sur on srm.role_id = sur.role_id where sur.role_id = #{roleId} and sm.state = 1 order by sm.order")
|
||||
public List<SysMenuEntity> findMenuByRoleId(String roleId);
|
||||
}
|
||||
|
||||
@@ -76,45 +76,42 @@ public class SysAuthServiceImpl implements ISysAuthService {
|
||||
SysUserEntity sysUserEntity = userDao.selectById(userId);
|
||||
String accessLevel = sysUserEntity.getAccessLevel();
|
||||
|
||||
List<WorkspaceEntity> workspaceEntityList = workspaceService.list();
|
||||
if (accessLevel.equalsIgnoreCase("regular")) {
|
||||
List<WorkspaceMemberEntity> workbookMemberEntityList = workspaceMemberService.list(new LambdaQueryWrapper<WorkspaceMemberEntity>().eq(WorkspaceMemberEntity::getUserId, userId));
|
||||
List<String> workspaceIdList = workbookMemberEntityList.stream().map(x -> x.getWorkspaceId()).toList();
|
||||
workspaceEntityList = workspaceService.list(new LambdaQueryWrapper<WorkspaceEntity>().in(WorkspaceEntity::getId, workspaceIdList));
|
||||
// public workspace
|
||||
List<WorkspaceEntity> publicWorkspaces = workspaceService.list(new LambdaQueryWrapper<WorkspaceEntity>().eq(WorkspaceEntity::getVisibility, "public"));
|
||||
workspaceEntityList.addAll(publicWorkspaces);
|
||||
}
|
||||
SysRoleEntity role = roleDao.findRoleByUserId(userId).get(0);
|
||||
// 组织 button 数据
|
||||
List<SysMenuEntity> menuList = roleDao.findMenuByUserId(userId);
|
||||
List<String> buttonList = menuList.stream().filter(menu -> T.StrUtil.equalsIgnoreCase(menu.getType(), "button"))
|
||||
.map(menu -> menu.getName()).collect(Collectors.toList());
|
||||
role.setButtons(buttonList);
|
||||
|
||||
//生成 menu tree结构
|
||||
Map<String, List<SysMenuEntity>> groupMap = menuList.stream()
|
||||
.filter(menu -> !T.StrUtil.equalsIgnoreCase(menu.getPid(), "0"))
|
||||
.collect(Collectors.groupingBy(SysMenuEntity::getPid));
|
||||
|
||||
menuList.forEach(menu -> {
|
||||
menu.setChildren(groupMap.get(menu.getId()));
|
||||
});
|
||||
|
||||
List<SysMenuEntity> collect = menuList.stream()
|
||||
.filter(menu -> T.StrUtil.equals(menu.getPid(), "0"))
|
||||
.filter(menu -> T.StrUtil.equals(menu.getType(), "menu"))
|
||||
.collect(Collectors.toList());
|
||||
role.setMenus(collect);
|
||||
List<WorkspaceMemberEntity> workbookMemberEntityList = workspaceMemberService.list(new LambdaQueryWrapper<WorkspaceMemberEntity>().eq(WorkspaceMemberEntity::getUserId, userId));
|
||||
|
||||
List records = ListUtil.list(false);
|
||||
for (WorkspaceEntity workspace : workspaceEntityList) {
|
||||
for (WorkspaceMemberEntity workspaceMemberEntity : workbookMemberEntityList) {
|
||||
WorkspaceEntity workspace = workspaceService.getById(workspaceMemberEntity.getWorkspaceId());
|
||||
SysRoleEntity role = roleDao.selectById(workspaceMemberEntity.getRoleId());
|
||||
|
||||
// 组织 button 数据
|
||||
List<SysMenuEntity> menuList = roleDao.findMenuByRoleId(workspaceMemberEntity.getRoleId());
|
||||
List<String> buttonList = menuList.stream().filter(menu -> T.StrUtil.equalsIgnoreCase(menu.getType(), "button"))
|
||||
.map(menu -> menu.getName()).collect(Collectors.toList());
|
||||
role.setButtons(buttonList);
|
||||
|
||||
//生成 menu tree结构
|
||||
Map<String, List<SysMenuEntity>> groupMap = menuList.stream()
|
||||
.filter(menu -> !T.StrUtil.equalsIgnoreCase(menu.getPid(), "0"))
|
||||
.collect(Collectors.groupingBy(SysMenuEntity::getPid));
|
||||
|
||||
menuList.forEach(menu -> {
|
||||
menu.setChildren(groupMap.get(menu.getId()));
|
||||
});
|
||||
|
||||
List<SysMenuEntity> collect = menuList.stream()
|
||||
.filter(menu -> T.StrUtil.equals(menu.getPid(), "0"))
|
||||
.filter(menu -> T.StrUtil.equals(menu.getType(), "menu"))
|
||||
.collect(Collectors.toList());
|
||||
role.setMenus(collect);
|
||||
|
||||
Map<Object, Object> map = MapUtil.builder()
|
||||
.put("workspace", workspace)
|
||||
.put("role", role)
|
||||
.put("role",role)
|
||||
.build();
|
||||
|
||||
records.add(map);
|
||||
}
|
||||
|
||||
Map<String, Object> result = T.MapUtil.newHashMap();
|
||||
result.put("records", records);
|
||||
result.put("accessLevel", accessLevel);
|
||||
|
||||
@@ -41,11 +41,10 @@ INSERT INTO `sys_role_menu`(`role_id`, `menu_id`) VALUES ('admin', '1');
|
||||
|
||||
|
||||
-- common
|
||||
INSERT INTO `sys_role_menu`(`role_id`, `menu_id`) VALUES ('common', '1001');
|
||||
INSERT INTO `sys_role_menu`(`role_id`, `menu_id`) VALUES ('common', '2001');
|
||||
INSERT INTO `sys_role_menu`(`role_id`, `menu_id`) VALUES ('common', '3001');
|
||||
INSERT INTO `sys_role_menu`(`role_id`, `menu_id`) VALUES ('common', '4001');
|
||||
INSERT INTO `sys_role_menu`(`role_id`, `menu_id`) VALUES ('common', '5001');
|
||||
INSERT INTO `sys_role_menu`(`role_id`, `menu_id`) VALUES ('common', '6001');
|
||||
INSERT INTO `sys_role_menu`(`role_id`, `menu_id`) VALUES ('common', '7001');
|
||||
INSERT INTO `sys_role_menu`(`role_id`, `menu_id`) VALUES ('common', '1');
|
||||
INSERT INTO `sys_role_menu`(`role_id`, `menu_id`) VALUES ('readonly', '1001');
|
||||
INSERT INTO `sys_role_menu`(`role_id`, `menu_id`) VALUES ('readonly', '2001');
|
||||
INSERT INTO `sys_role_menu`(`role_id`, `menu_id`) VALUES ('readonly', '3001');
|
||||
INSERT INTO `sys_role_menu`(`role_id`, `menu_id`) VALUES ('readonly', '4001');
|
||||
INSERT INTO `sys_role_menu`(`role_id`, `menu_id`) VALUES ('readonly', '5001');
|
||||
INSERT INTO `sys_role_menu`(`role_id`, `menu_id`) VALUES ('readonly', '6001');
|
||||
INSERT INTO `sys_role_menu`(`role_id`, `menu_id`) VALUES ('readonly', '7001');
|
||||
@@ -44,7 +44,7 @@ CREATE TABLE `sys_role` (
|
||||
|
||||
-- 添加内置角色
|
||||
INSERT INTO `sys_role` (`id`, `name`, `i18n`, `remark`, `build_in`, `create_timestamp`) VALUES ('admin', 'admin', 'admin', 'admin', 1, UNIX_TIMESTAMP(NOW())*1000);
|
||||
INSERT INTO `sys_role` (`id`, `name`, `i18n`, `remark`, `build_in`, `create_timestamp`) VALUES ('common', 'common', 'common', 'common', 1, UNIX_TIMESTAMP(NOW())*1000);
|
||||
INSERT INTO `sys_role` (`id`, `name`, `i18n`, `remark`, `build_in`, `create_timestamp`) VALUES ('readonly', 'readonly', 'readonly', 'readonly', 1, UNIX_TIMESTAMP(NOW())*1000);
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `sys_menu`;
|
||||
|
||||
Reference in New Issue
Block a user