浏览代码

解决dir-tree能获取不属于自己权限目录 的BUG。

wukai 1 年之前
父节点
当前提交
c4f7c7ac8e
共有 1 个文件被更改,包括 32 次插入21 次删除
  1. 32 21
      doc-biz/src/main/java/com/doc/biz/controller/DocDirController.java

+ 32 - 21
doc-biz/src/main/java/com/doc/biz/controller/DocDirController.java

@@ -121,17 +121,45 @@ public class DocDirController extends BaseController {
         DocDir docDir = new DocDir();
         docDir.setSpaceId(space.getSpaceId());
         docDir.setParentId(0L);
+
+        addRole(docDir, type);
         List<DocDir> list = docDirService.selectDocDirList(docDir);
 
-        TreeVO vo = getChildren(list.get(0), st);
-        return vo;
+        return getChildren(list.get(0), st);
+    }
+
+    /**
+     * 添加公共目录和部门目录权限控制
+     *
+     * @param dir  目录
+     * @param type 空间类型
+     */
+    private void addRole(DocDir dir, String type) {
+        String pubKey = "1";
+        String deptKey = "2";
+        String pubRole = "system";
+        String deptRole = "dept";
+        //如果不是个人空间,则需要按权限
+        List<SysRole> roles = SecurityUtils.getLoginUser().getUser().getRoles();
+        Set<String> roleKeys = roles.stream().map(SysRole::getRoleKey).collect(Collectors.toSet());
+        //如果是公共空间,且不为系统管理员
+        boolean pubFlag = pubKey.equals(type) && !roleKeys.contains(pubRole);
+        //如果是部门空间,且不为部门管理员
+        boolean deptFlag = deptKey.equals(type) && !roleKeys.contains(deptRole);
+        if (pubFlag || deptFlag) {
+            //则需要判断组织目录是否有权限访问
+            Map<String, Object> params = new HashMap<>(4);
+            params.put("flag", 1);
+            params.put("uid", SecurityUtils.getUserId());
+            dir.setParams(params);
+        }
     }
 
     /**
      * 递归获取目录树
      *
      * @param dir 目录信息
-     * @return
+     * @return tree
      */
     private TreeVO getChildren(DocDir dir, String st) {
         TreeVO vo = new TreeVO();
@@ -199,24 +227,7 @@ public class DocDirController extends BaseController {
     @ApiOperation("按空间类型查询目录列表")
     @GetMapping("/list/{type}")
     public AjaxResult listByType(@ApiParam(value = "目录类型(1.公共 2.部门 3.个人)", required = true) @PathVariable("type") String type, DocDir docDir) {
-        String pub_t = "1";
-        String dept_t = "2";
-        String pub_k = "system";
-        String dept_k = "dept";
-        //如果不是个人空间,则需要按权限
-        List<SysRole> roles = SecurityUtils.getLoginUser().getUser().getRoles();
-        Set<String> roleKeys = roles.stream().map(SysRole::getRoleKey).collect(Collectors.toSet());
-
-        if ((pub_t.equals(type) && !roleKeys.contains(pub_k)) || (dept_t.equals(type) && !roleKeys.contains(dept_k))) {
-            //如果是公共空间,且不为系统管理员
-            //如果是部门空间,且不为部门管理员
-            //则需要判断组织目录是否有权限访问
-            Map<String, Object> params = new HashMap<>(4);
-            params.put("flag", 1);
-            params.put("uid", SecurityUtils.getUserId());
-            docDir.setParams(params);
-        }
-
+        addRole(docDir, type);
         return list(docDir);
     }