# 流程流转时添加文档/附件共享权限二开口子

<font color="#FF0000">最低版本支持：weaver-workflow-core 1.76.0-hotfix35</font>


## 一、后端口子-流转时不触发添加文档/附件共享权限

### 1.1、概述及说明

标准”文档/附件权限设置“--”流转时添加文档/附件共享权限“ 配置后，默认一定会赋权。需要可以自己实现规则，比如字段满足某些条件 才执行赋权。

### 1.2、注意事项

在下图”表单关联文档字段“、”表单附件字段“、”意见关联文档、附件“勾选的基础上，可二开复写改为关闭（即自定义规则下不触发赋权）。

![](${appMdRes}/1747215472-image.png)


### 1.3、二开服务增加注册hook

~~~java

package com.weaver.seconddev.workflow.hooks;

import com.weaver.loom.api.annotation.RegHook;
import com.weaver.loom.context.register.AbstractRegHookEvent;
import com.weaver.workflow.common.constant.event.WorkflowEvent;
import com.weaver.workflow.common.entity.core.flow.WorkflowRequestEntityInterface;
import com.weaver.workflow.common.entity.org.WeaUser;
import com.weaver.workflow.common.entity.pathdef.path.docshare.WfpDocShareConfigEntity;
import com.weaver.workflow.common.util.DataTransUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 注册二开埋点钩子实现,文档/附件赋权，复写赋权自定义开关二开口子
 */
@Slf4j
@Component
@RegHook(module = "workflow", event = "wfcDocShareCustomMainSwitch", order = 1)
public class WfcAddDocShareCustomMainSwitchHook extends AbstractRegHookEvent {


    @Override
    public Object handle(Object[] args) throws Exception {
        log.error("WfcAddDocShareCustomMainSwitchHook start");
        if(Objects.nonNull(args) && args.length >1){
            WorkflowEvent eventType = (WorkflowEvent) args[0];
            WorkflowRequestEntityInterface requestEntity = (WorkflowRequestEntityInterface) args[1];
            WfpDocShareConfigEntity docShareConfigEntity = (WfpDocShareConfigEntity) args[2]; //文档/附件权限设置
            WeaUser user = (WeaUser) args[3]; //user对象
            Map<String,Object> otherParam = (Map<String, Object>) args[4];

            long requestId = requestEntity.getRequestId();
            long workflowId = requestEntity.getWorkflowId();
            long currentNodeId = DataTransUtil.getLongValue(otherParam.get("userCurrentNodeId"));
            log.error("requestId:{},workflowId:{},currentNodeId：{}", requestId,workflowId,currentNodeId);

            Map<String,Object> result = new HashMap<>();
            if(workflowId == 1114906087816806501l){
                result.put("enableFormDoc",false); //关闭表单文档字段赋权。仅支持复写关闭，即false
                result.put("enablFormFile",false); //关闭表单附件字段赋权。仅支持复写关闭，即false
                result.put("enableReqlogShare",false);//关闭意见中文档和附件字段赋权。仅支持复写关闭，即false
            }
            log.error("WfcAddDocShareCustomMainSwitchHook tenantkey:{},result:{}",user.getTenantKey(),result);
            log.error("WfcAddDocShareCustomMainSwitchHook end");
            return result;
        }
        return null;
    }

}


~~~

注意：代码中Map返回值：enableFormDoc、enablFormFile、enableReqlogShare分别对应”表单关联文档字段“、”表单附件字段“、”意见关联文档、附件“ 3个选项开关。










