浏览代码

修改公共文件和部门文件组织目录访问权限问题

wukai 1 年之前
父节点
当前提交
7a46369aa9

+ 35 - 3
doc-biz/src/main/java/com/doc/biz/controller/DocDirController.java

@@ -8,6 +8,7 @@ import com.doc.common.annotation.Log;
 import com.doc.common.constant.Constants;
 import com.doc.common.core.controller.BaseController;
 import com.doc.common.core.domain.AjaxResult;
+import com.doc.common.core.domain.entity.SysRole;
 import com.doc.common.enums.BusinessType;
 import com.doc.common.enums.EventLevel;
 import com.doc.common.utils.SecurityUtils;
@@ -17,8 +18,8 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 文档目录管理Controller
@@ -50,7 +51,11 @@ public class DocDirController extends BaseController {
     @GetMapping(value = "/top-dir/{type}")
     public DocDir topDir(@ApiParam(value = "目录类型(1.公共 2.部门 3.个人)", required = true) @PathVariable("type") String type) {
         DocSpace space = spaceService.selectDocSpaceListByType(type);
-
+        String dept = "2";
+        if (space.getSpaceId() == null && dept.equals(type)) {
+            spaceService.initDeptSpace(SecurityUtils.getLoginUser().getUser().getDept());
+            space = spaceService.selectDocSpaceListByType(type);
+        }
         DocDir dir = new DocDir();
         dir.setSpaceId(space.getSpaceId());
         dir.setParentId(0L);
@@ -188,6 +193,33 @@ 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);
+        }
+
+        return list(docDir);
+    }
+
+    /**
      * 导出文档目录管理列表
      */
 //    @ApiOperation("导出文档目录管理列表")

+ 8 - 0
doc-biz/src/main/java/com/doc/biz/service/IDocDirService.java

@@ -84,4 +84,12 @@ public interface IDocDirService {
      * @return 结果集
      */
     Map<String, Object> selectDirByUser(Long userId);
+
+    /**
+     * 根据权限控制查询目录列表
+     *
+     * @param docDir 对象
+     * @return 结果
+     */
+    List<DocDir> selectDocDirList4type(DocDir docDir);
 }

+ 11 - 0
doc-biz/src/main/java/com/doc/biz/service/impl/DocDirServiceImpl.java

@@ -189,4 +189,15 @@ public class DocDirServiceImpl implements IDocDirService {
         result.put("dir", docDirMapper.selectDirByUser(spaceIds, userId));
         return result;
     }
+
+    /**
+     * 根据权限控制查询目录列表
+     *
+     * @param docDir 对象
+     * @return 结果
+     */
+    @Override
+    public List<DocDir> selectDocDirList4type(DocDir docDir) {
+        return null;
+    }
 }

+ 11 - 0
doc-biz/src/main/resources/mapper/biz/DocDirMapper.xml

@@ -48,6 +48,17 @@
             <if test="dirName != null  and dirName != ''">and DIR_NAME like concat('%', #{dirName}, '%')</if>
             <if test="searchValue != null  and searchValue != ''">and DIR_NAME =#{searchValue}</if>
             <if test="parentId != null ">and PARENT_ID = #{parentId}</if>
+            <if test="params.flag !=null ">
+                AND (
+                dir_type = '1' OR (
+                dir_type = '2' AND dir_id IN
+                (
+                SELECT dir_id FROM doc_dir_user WHERE user_id = #{params.uid}
+                )
+                )
+                )
+            </if>
+
         </where>
     </select>