Skip to content

Dev #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 6, 2024
Merged

Dev #81

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ v.3.x 为springboot 3.x版本,使用jdk17版本

* springboot-starter | Springboot领域驱动框架
* springboot-starter-data-fast | 快速数据呈现框架
* springboot-starter-data-authorization | 数据权限框架
* springboot-starter-flow | 流程引擎框架
* springboot-starter-security | security权限框架支持基于JWT的无状态权限认证与Redis的有状态权限认证

Expand All @@ -42,6 +43,13 @@ v.3.x 为springboot 3.x版本,使用jdk17版本
<version>${last.version}</version>
</dependency>

<!-- 数据权限框架 -->
<dependency>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-starter-data-authorization</artifactId>
<version>${last.version}</version>
</dependency>

<!-- 流程引擎框架 -->
<dependency>
<groupId>com.codingapi.springboot</groupId>
Expand Down
34 changes: 28 additions & 6 deletions admin-ui/src/components/Flow/flow/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,36 @@ export class FlowData extends FlowWorkData {
this.formParams = formParams;
}

// 是否可以审批
canHandle = () => {
return this.data.canHandle;
}

// 是否是开始节点
isStartFlow = () => {
if (this.data) {
return this.data.flowNode.startNode;
}
return false;
}

// 获取当前节点的code
getNodeCode = () => {
if (this.data) {
return this.data.flowNode.code;
}
return null;
}

// 获取当前节点的按钮
getNodeButtons = () => {
if (this.data) {
return this.data.flowNode.buttons;
}
return null;
}

// 获取当前节点的标题
getCurrentNodeTitle = () => {
if (this.data) {
const node = this.data.flowNode;
Expand All @@ -125,6 +137,7 @@ export class FlowData extends FlowWorkData {
return null;
}

// 获取当前节点的视图 (内部使用)
getFlowFormView(view: React.ComponentType<FlowFormViewProps> | FlowFormView) {
if (typeof view === 'object') {
const nodeView = this.data.flowNode.view;
Expand All @@ -133,7 +146,7 @@ export class FlowData extends FlowWorkData {
return view;
}


// 获取当前节点是否可编辑
getFlowNodeEditable = () => {
if (this.data) {
const node = this.data.flowNode;
Expand All @@ -144,14 +157,15 @@ export class FlowData extends FlowWorkData {
return false
}

// 获取当前节点的表单数据
getFlowData = () => {
return {
...this.data.bindData,
...this.formParams
}
}


// 获取当前节点的表单数据 (内部使用)
getNodeState = (code: string) => {
const historyRecords = this.data.historyRecords || [];

Expand All @@ -160,9 +174,9 @@ export class FlowData extends FlowWorkData {
return "done";
}

for(const record of historyRecords){
if(record.nodeCode === code){
if(record.flowType==='TODO'){
for (const record of historyRecords) {
if (record.nodeCode === code) {
if (record.flowType === 'TODO') {
return "wait";
}
return "done";
Expand All @@ -172,6 +186,7 @@ export class FlowData extends FlowWorkData {
return "wait";
}

// 获取当前节点的流程图
getFlowSchema = () => {

if (this.data.flowWork.schema) {
Expand All @@ -186,39 +201,46 @@ export class FlowData extends FlowWorkData {
return null;
}

// 是否存在数据
hasData() {
return !!this.data;
}

// 获取当前的详情的记录数据
getCurrentFlowRecord = () => {
return this.data.flowRecord;
}

// 获取历史记录
getHistoryRecords = () => {
return this.data.historyRecords;
}

// 是否是审批完成
isDone() {
if (this.data.flowRecord) {
return this.data.flowRecord.flowStatus === 'FINISH' || this.data.flowRecord.flowType === 'DONE';
}
return false;
}

// 是否是结束节点
private isFinished() {
if (this.data.flowRecord) {
return this.data.flowRecord.flowStatus === 'FINISH';
}
return false;
}

// 是否需要展示流转记录 (内部使用)
showHistory() {
if(this.isDone()){
if (this.isDone()) {
return true;
}
return !this.isStartFlow();
}

// 是否展示审批意见 (内部使用)
showOpinion() {
return this.canHandle() && !this.isStartFlow();
}
Expand Down
8 changes: 7 additions & 1 deletion docs/wiki/home.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ maven install
<version>${last.version}</version>
</dependency>

<!-- 数据权限框架 -->
<dependency>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-starter-data-authorization</artifactId>
<version>${last.version}</version>
</dependency>

<!-- security&jwt权限框架 -->
<dependency>
Expand All @@ -31,4 +37,4 @@ maven install
[springboot-starter](./springboot-starter)
[springboot-starter-security](./springboot-starter-security)
[springboot-starter-data-fast](./springboot-starter-data-fast.md)

[springboot-starter-data-authorization](./springboot-starter-data-authorization.md)
103 changes: 103 additions & 0 deletions docs/wiki/springboot-starter-data-authorization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
springboot-starter-data-authorization

数据权限框架

## 框架介绍

基于JDBC的拦截机制实现对数据表列与行的数据查询权限控制。

## 使用教程

1. 配置数据库的JDBC驱动地址为 `com.codingapi.springboot.authorization.jdbc.AuthorizationJdbcDriver`
```
spring.datasource.driver-class-name=com.codingapi.springboot.authorization.jdbc.AuthorizationJdbcDriver
spring.datasource.url=jdbc:h2:file:./test.db
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true

```
2. 配置数据权限DataAuthorizationFilter的实现
接口定义
```java

/**
* 数据权限过滤器
*/
public interface DataAuthorizationFilter {

/**
* 列权限过滤
* @param tableName 表名
* @param columnName 列名
* @param value 值
* @return 过滤后的值
* @param <T> T
*/
<T> T columnAuthorization(String tableName, String columnName,T value);

/**
* 行权限过滤
* @param tableName 表名
* @param tableAlias 表别名
* @return 过滤后拦截sql条件
*/
Condition rowAuthorization(String tableName, String tableAlias);

/**
* 是否支持列权限过滤
* @param tableName 表名
* @param columnName 列名
* @param value 值
* @return 是否支持
*/
boolean supportColumnAuthorization(String tableName, String columnName, Object value);

/**
* 是否支持行权限过滤
* @param tableName 表名
* @param tableAlias 表别名
* @return 是否支持
*/
boolean supportRowAuthorization(String tableName, String tableAlias);
}


```
实例实现:
```

ColumnMaskContext.getInstance().addColumnMask(new IDCardMask());
ColumnMaskContext.getInstance().addColumnMask(new PhoneMask());
ColumnMaskContext.getInstance().addColumnMask(new BankCardMask());

DataAuthorizationContext.getInstance().addDataAuthorizationFilter(new DataAuthorizationFilter() {
@Override
public <T> T columnAuthorization(String tableName, String columnName, T value) {
return ColumnMaskContext.getInstance().mask(value);
}

@Override
public Condition rowAuthorization(String tableName, String tableAlias) {
if (tableName.equalsIgnoreCase("t_user")) {
String conditionTemplate = "%s.id > 1 ";
return Condition.formatCondition(conditionTemplate, tableAlias);
}
return null;
}

@Override
public boolean supportColumnAuthorization(String tableName, String columnName, Object value) {
return true;
}

@Override
public boolean supportRowAuthorization(String tableName, String tableAlias) {
return true;
}
});
```

实现的拦截器,需要添加到DataAuthorizationContext.getInstance()中才可以使用。可以通过上述实例的手动模式添加,
也可以通过定义DataAuthorizationFilter的@Bean方式添加,当设置为@Bean时既可以自动加入到DataAuthorizationContext.getInstance()中。

2 changes: 1 addition & 1 deletion example/example-application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>springboot-example</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.3.26</version>
<version>3.3.27</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion example/example-domain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>springboot-example</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.3.26</version>
<version>3.3.27</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion example/example-infra-flow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>springboot-example</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.3.26</version>
<version>3.3.27</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion example/example-infra-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>springboot-example</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.3.26</version>
<version>3.3.27</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion example/example-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>springboot-example</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.3.26</version>
<version>3.3.27</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</parent>

<artifactId>springboot-example</artifactId>
<version>3.3.26</version>
<version>3.3.27</version>

<name>springboot-example</name>
<description>springboot-example project for Spring Boot</description>
Expand Down
13 changes: 12 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<modules>
<module>springboot-starter-data-authorization</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
Expand All @@ -12,7 +15,7 @@

<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-parent</artifactId>
<version>3.3.26</version>
<version>3.3.27</version>

<url>https://github.com/codingapi/springboot-framewrok</url>
<name>springboot-parent</name>
Expand Down Expand Up @@ -45,6 +48,7 @@
<apache-groovy.version>4.0.24</apache-groovy.version>
<h2.version>2.3.232</h2.version>
<esotericsoftware.kryo.version>5.6.2</esotericsoftware.kryo.version>
<jsqlparser.version>5.0</jsqlparser.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -206,6 +210,13 @@
<version>${apache-groovy.version}</version>
</dependency>

<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>${jsqlparser.version}</version>
</dependency>


</dependencies>
</dependencyManagement>

Expand Down
Loading