完成权限控制
This commit is contained in:
@@ -6,6 +6,7 @@ import com.lanyuanxiaoyao.flowable.core.model.FlowableAction;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableHandler;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableInstance;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableNode;
|
||||
import com.lanyuanxiaoyao.flowable.test.accessor.RoleCheckAccessor;
|
||||
import com.lanyuanxiaoyao.flowable.test.handler.TwoApproveHandler;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -179,4 +180,23 @@ public abstract class TestFlowableManager {
|
||||
Assertions.assertEquals("88a4ef5b-9cca-4e89-8232-24b6e9e94f4a", manager.getInstance(instanceId).getCurrentNodeId());
|
||||
Assertions.assertEquals("lanyuanxiaoyao", manager.getInstance(instanceId).getMetadata().get("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAccessor() {
|
||||
FlowableManager manager = flowableManager();
|
||||
FlowableNode node = FlowableNode.builder()
|
||||
.nodeId("a3f3f055-aa0e-49ed-9bc5-d0c04f11017e")
|
||||
.name("a3f3f055-aa0e-49ed-9bc5-d0c04f11017e")
|
||||
.description("a3f3f055-aa0e-49ed-9bc5-d0c04f11017e")
|
||||
.type(FlowableNode.Type.MANUAL)
|
||||
.accessor(RoleCheckAccessor.class.getName())
|
||||
.build();
|
||||
manager.create(node);
|
||||
String instanceId = manager.start(node.getNodeId());
|
||||
Assertions.assertEquals(FlowableInstance.Status.RUNNING, manager.getInstance(instanceId).getStatus());
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> manager.approve(instanceId));
|
||||
|
||||
manager.approve(instanceId, MapHelper.of("role", "admin"));
|
||||
Assertions.assertEquals(FlowableInstance.Status.COMPLETED, manager.getInstance(instanceId).getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.lanyuanxiaoyao.flowable.test.accessor;
|
||||
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableAccessor;
|
||||
import com.lanyuanxiaoyao.flowable.core.model.FlowableMetadata;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250103
|
||||
*/
|
||||
public class RoleCheckAccessor implements FlowableAccessor {
|
||||
@Override
|
||||
public boolean access(FlowableMetadata metadata) {
|
||||
return metadata.containsKey("role");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user