feat(项目管理红山裁剪): 隐藏掉流水线、制品库模块

1. 通过Nacos增加配置项,可设置需屏蔽的菜单标识
2. 菜单被屏蔽则用户在菜单栏及权限分配时屏蔽相关菜单
3. 在权限判断时对被屏蔽菜单进行拦截
This commit is contained in:
OTTO 2024-05-31 15:52:51 +08:00
parent 696778a515
commit 6d96d90432
4 changed files with 49 additions and 18 deletions

View File

@ -9,11 +9,9 @@ import com.microservices.common.log.enums.BusinessType;
import com.microservices.common.security.annotation.Logical;
import com.microservices.common.security.annotation.RequiresPermissions;
import com.microservices.system.api.domain.SysRole;
import com.microservices.system.domain.SysMenu;
import com.microservices.system.domain.vo.SysRoleInputVo;
import com.microservices.system.domain.vo.SysRoleUpdateVo;
import com.microservices.system.service.ISysDeptRoleService;
import com.microservices.system.service.ISysMenuService;
import com.microservices.system.service.ISysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -22,7 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/**
@ -39,8 +36,6 @@ public class SysDeptRoleController extends BaseController {
@Autowired
private ISysDeptRoleService sysDeptRoleService;
@Autowired
private ISysMenuService menuService;
@Autowired
private ISysRoleService roleService;
/**
@ -114,17 +109,7 @@ public class SysDeptRoleController extends BaseController {
@ApiOperation("查看角色对应菜单列表树")
public AjaxResult roleMenuTreeSelect(@PathVariable Long currentDeptId,
@ApiParam(value = "角色Id") Long roleId) {
List<SysMenu> menus = menuService.selectMenuList(new SysMenu());
AjaxResult ajax = AjaxResult.success();
List<Long> checkedKeys;
if (roleId != null) {
checkedKeys = menuService.selectMenuListByRoleId(roleId);
} else {
checkedKeys = new ArrayList<>();
}
ajax.put("checkedKeys", checkedKeys);
ajax.put("menus", menuService.buildMenuTreeSelect(menus));
return ajax;
return sysDeptRoleService.roleMenuTreeSelect(currentDeptId, roleId);
}
/**

View File

@ -1,5 +1,6 @@
package com.microservices.system.service;
import com.microservices.common.core.web.domain.AjaxResult;
import com.microservices.system.api.domain.SysDept;
import com.microservices.system.api.domain.SysRole;
import com.microservices.system.domain.vo.SysRoleInputVo;
@ -110,4 +111,13 @@ public interface ISysDeptRoleService {
* @return 更新结果
*/
int updateSysRole(Long deptId, SysRole sysRole);
/**
* 查看角色对应菜单列表树
*
* @param currentDeptId 组织id
* @param roleId 角色id
* @return 结果
*/
AjaxResult roleMenuTreeSelect(Long currentDeptId, Long roleId);
}

View File

@ -5,6 +5,7 @@ import com.microservices.common.core.enums.SystemRole;
import com.microservices.common.core.exception.ServiceException;
import com.microservices.common.core.utils.StringUtils;
import com.microservices.common.core.utils.uuid.IdUtils;
import com.microservices.common.core.web.domain.AjaxResult;
import com.microservices.common.security.utils.SecurityUtils;
import com.microservices.system.api.domain.SysDept;
import com.microservices.system.api.domain.SysRole;
@ -46,6 +47,8 @@ public class SysDeptRoleServiceImpl implements ISysDeptRoleService {
private SysUserDeptRoleMapper sysUserDeptRoleMapper;
@Autowired
private ISysMenuService sysMenuService;
@Autowired
private ISysMenuService menuService;
@Override
public SysDept selectSysDeptById(Long deptId) {
@ -165,6 +168,21 @@ public class SysDeptRoleServiceImpl implements ISysDeptRoleService {
return roleService.updateRole(role);
}
@Override
public AjaxResult roleMenuTreeSelect(Long currentDeptId, Long roleId) {
List<SysMenu> menus = menuService.selectMenuList(new SysMenu());
AjaxResult ajax = AjaxResult.success();
List<Long> checkedKeys;
if (roleId != null) {
checkedKeys = menuService.selectMenuListByRoleId(roleId);
} else {
checkedKeys = new ArrayList<>();
}
ajax.put("checkedKeys", checkedKeys);
ajax.put("menus", menuService.buildMenuTreeSelect(menus));
return ajax;
}
@Override
@Transactional(rollbackFor = Exception.class)

View File

@ -16,6 +16,8 @@ import com.microservices.system.mapper.SysRoleMapper;
import com.microservices.system.service.ISysMenuService;
import com.microservices.system.service.ISysRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;
import java.util.*;
@ -27,6 +29,7 @@ import java.util.stream.Collectors;
* @author microservices
*/
@Service
@RefreshScope
public class SysMenuServiceImpl implements ISysMenuService
{
public static final String PREMISSION_STRING = "perms[\"{0}\"]";
@ -39,6 +42,8 @@ public class SysMenuServiceImpl implements ISysMenuService
@Autowired
private ISysRoleMenuService roleMenuService;
@Value("${system.hidePerms:}")
private String hidePerms;
/**
* 根据用户查询系统菜单列表
@ -361,7 +366,13 @@ public class SysMenuServiceImpl implements ISysMenuService
@Override
public Set<String> selectMenuPermsByRoleKey(String roleKey) {
SysRole sysRole = roleMapper.selectRoleByKey(roleKey);
return selectMenuPermsByRoleId(sysRole.getRoleId());
Set<String> menuPerms = selectMenuPermsByRoleId(sysRole.getRoleId());
// 隐藏部分菜单
if (StringUtils.isNotEmpty(hidePerms)) {
List<String> hidePermList = Arrays.asList(hidePerms.split(","));
menuPerms = menuPerms.stream().filter(x -> !hidePermList.contains(x)).collect(Collectors.toSet());
}
return menuPerms;
}
@Override
@ -371,9 +382,16 @@ public class SysMenuServiceImpl implements ISysMenuService
if (userIdentify != null && userIdentify.getSysDept() != null) {
sysMenu.setDeptType(userIdentify.getSysDept().getDeptType());
}
return menuMapper.selectMenuList(sysMenu);
List<SysMenu> sysMenuList = menuMapper.selectMenuList(sysMenu);
// 隐藏部分菜单
if (StringUtils.isNotEmpty(hidePerms)) {
List<String> hidePermList = Arrays.asList(hidePerms.split(","));
sysMenuList = sysMenuList.stream().filter(x -> !hidePermList.contains(x.getPerms())).collect(Collectors.toList());
}
return sysMenuList;
}
@Override
public List<SysMenu> selectMenuListByMenuIds(Long[] menuIds) {
if (menuIds.length > 0) {