소스 검색

优化:管理员的权限控制

4.0
FLYPHT 2 년 전
부모
커밋
29d76d56b5
4개의 변경된 파일58개의 추가작업 그리고 7개의 파일을 삭제
  1. +20
    -6
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/preview/PreviewMenuTreeService.java
  2. +16
    -1
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanContent.java
  3. +12
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanItem.java
  4. +10
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleHelper.java

+ 20
- 6
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/preview/PreviewMenuTreeService.java 파일 보기

@@ -34,9 +34,14 @@ public class PreviewMenuTreeService {
public R treeAll(@SwParam("module") String module, UserSession us) {
String prj_id = ModelProjectCache.getInstance().getIdByModule(module);
if (!SwConsts.SysParam.SYS_DEBUG) {
List<MenuVO> menuVOList = buildMenu(prj_id, module, us);
MenuVO home = new MenuVO();
List<MenuVO> menuVOList = buildMenu(prj_id, module, us,home);
if (!CommUtil.isEmpty(menuVOList)) {
return R.success(menuVOList);
R r = R.success(menuVOList);
if(home.getId()>0){
r.put("home",home);
}
return r;
}else {
return R.success(new ArrayList<>());
}
@@ -76,11 +81,10 @@ public class PreviewMenuTreeService {
root.setPath(module);
root.setId(-1L);
List<MenuVO> data = TreeDataUtil.buildTree(root, list, MenuVO.createTreeHandler());

return R.success(data);
return R.success(data);
}

public List<MenuVO> buildMenu(String prj_id, String module, UserSession us) {
public List<MenuVO> buildMenu(String prj_id, String module, UserSession us,MenuVO home) {
Set<MenuPlan> set = RoleHelper.getMenuPlans(us.getUserId(),us.getPartyId());
if (CommUtil.isEmpty(set)) {
return new ArrayList<>();
@@ -89,8 +93,18 @@ public class PreviewMenuTreeService {
MenuPlanContent mpc = new MenuPlanContent(menuPlan.getContent());
List<MenuVO> list = new ArrayList<>();
Set<Long> rightMenuIds = RoleHelper.getRoleMenuIds(us.getUserId() , us.getPartyId(),menuPlan.getId(), true);
for(MenuPlanItem item : mpc.getHomeList()){
long id = item.getId();
if(rightMenuIds.contains(id)){
home.setId(item.getId());
home.setName(item.getLabel());
home.setIcon(item.getIcon());
home.setPath(MenuCache.getInstance().getPath(item.getMenu()));
break;
}
}
for (MenuPlanItem mp : mpc.getChildren(0)) {
List<MenuVO> menuVOList = buildMenuWithRight(-1, mp,rightMenuIds);
List<MenuVO> menuVOList = RoleHelper.isAdmin(us.getUserId())? buildMenu(-1,mp):buildMenuWithRight(-1, mp,rightMenuIds);
if (menuVOList == null) continue;
list.addAll(menuVOList);
}


+ 16
- 1
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanContent.java 파일 보기

@@ -75,6 +75,7 @@ public class MenuPlanContent {
oldItem.setMenu(item.getMenu());
oldItem.setIcon(item.getIcon());
oldItem.setSeq(item.getSeq());
oldItem.setHome(item.getHome());
}

}
@@ -122,7 +123,21 @@ public class MenuPlanContent {
MenuPlanItem parent = findById(parentId);
return parent == null ? new ArrayList<>(): parent.getChildren();
}

// 获取主页
public List<MenuPlanItem> getHomeList(){
List<MenuPlanItem> homeList = new ArrayList<>();
findHome(list,homeList);
return homeList;
}
private void findHome(List<MenuPlanItem> source,List<MenuPlanItem> homeList){
if(CommUtil.isEmpty(source))return;
for(MenuPlanItem item: source){
if(item.getHome() == 1){
homeList.add(item);
}
findHome(item.getChildren(),homeList);
}
}
private MenuPlanItem findById(long id, List<MenuPlanItem> itemList) {
if (CommUtil.isEmpty(itemList)) {
return null;


+ 12
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanItem.java 파일 보기

@@ -80,7 +80,19 @@ public class MenuPlanItem extends BaseBean {
public void setSeq(int seq) {
put("seq", seq);
}
/**
* 排序码
*/
public int getHome() {
return getInt("home");
}

/**
* 排序码
*/
public void setHome(int home) {
put("home", home);
}
public void setChildren(List<MenuPlanItem> children) {
put("children", children);
}


+ 10
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleHelper.java 파일 보기

@@ -4,6 +4,8 @@ import cc.smtweb.system.bpm.web.sys.user.menuPlan.MenuPlan;
import cc.smtweb.system.bpm.web.sys.user.menuPlan.MenuPlanCache;
import cc.smtweb.system.bpm.web.sys.user.menuPlan.MenuPlanContent;
import cc.smtweb.system.bpm.web.sys.user.menuPlan.MenuPlanItem;
import cc.smtweb.system.bpm.web.sys.user.user.User;
import cc.smtweb.system.bpm.web.sys.user.user.UserCache;
import cc.smtweb.system.bpm.web.sys.user.user.UserRoleCache;

import java.util.HashSet;
@@ -16,6 +18,14 @@ import java.util.Set;
* @Desc: 角色辅助类
*/
public final class RoleHelper {
public static boolean isAdmin(long userId){
if(userId ==1L) return true;
User user = UserCache.getInstance().get(userId);
if(user!=null){
return "admin".equalsIgnoreCase(user.getNicky());
}
return false;
}
/**
* 获取角色权限
* @param userId 用户ID


불러오는 중...
취소
저장