Skip to content

Commit

Permalink
Merge pull request #1244 from scottsut/master
Browse files Browse the repository at this point in the history
feat: 1.0.0-beta.3 release
  • Loading branch information
scottsut authored Apr 22, 2022
2 parents 5624919 + 3692b1c commit e2450b2
Show file tree
Hide file tree
Showing 709 changed files with 30,569 additions and 11,248 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

# IDE
.idea
.DS_Store

/static

Expand Down
10 changes: 10 additions & 0 deletions config/datart.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ server.address=0.0.0.0
datart.address=http://127.0.0.1
datart.send-mail=false
datart.webdriver-path=http://127.0.0.1:4444/wd/hub
datart.user.register=true
# 注册邮件有效期/小时, 默认48小时
datart.register.expire-hours=
# 邀请邮件有效期/小时, 默认48小时
datart.invite.expire-hours=
# 租户管理模式:platform-平台(默认),team-团队
datart.tenant-management-mode=platform
# 团队模式初始组织拥有者用户名/密码: 仅团队模式且两者都不为空时重置
datart.admin.username=
datart.admin.password=
30 changes: 25 additions & 5 deletions config/profiles/application-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ spring:
# name: "attributes.name"
# avatar: "attributes.avatar"

# ldap config

# ldap:
# urls: ldap://{IP}:{PORT}
# base: xxx
# username: {username}
# password: {password}

# mail config

# mail:
Expand Down Expand Up @@ -62,19 +70,31 @@ spring:
server:
port: ${server.port:8080}
address: ${server.ip:0.0.0.0}
ssl.enabled: false
ssl.key-store: keystore.p12 # Absolute path
ssl.key-store-password: password
ssl.keyStoreType: PKCS12
ssl.keyAlias: tomcat
ssl:
enabled: false
key-store: keystore.p12 # Absolute path
key-store-password: password
keyStoreType: PKCS12
keyAlias: tomcat

datart:
server:
address: ${datart.address:http://127.0.0.1:8080}

# 租户管理模式:platform-平台(默认),team-团队
tenant-management-mode: platform
# 团队管理员用户名/密码: 仅team模式且两者都不为空时重置
admin:
username:
password:

user:
register: true # 是否允许注册
active:
send-mail: ${datart.send-mail:false} # 注册用户时是否需要邮件验证激活
expire-hours: ${datart.register.expire-hours:48} # 注册邮件有效期/小时
invite:
expire-hours: ${datart.invite.expire-hours:48} # 邀请邮件有效期/小时

security:
token:
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>datart-parent</artifactId>
<groupId>datart</groupId>
<version>1.0.0-beta.2</version>
<version>1.0.0-beta.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
19 changes: 17 additions & 2 deletions core/src/main/java/datart/core/base/consts/AttachmentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,23 @@

public enum AttachmentType {

EXCEL,
EXCEL(".xlsx"),

IMAGE
IMAGE(".png"),

PDF(".pdf");

private String suffix;

AttachmentType(String suffix) {
this.suffix = suffix;
}

public void setSuffix(String suffix) {
this.suffix = suffix;
}

public String getSuffix() {
return suffix;
}
}
5 changes: 3 additions & 2 deletions core/src/main/java/datart/core/base/consts/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public class Const {
/**
* 权限变量
*/
// //管理员权限,拥有所有数据的权限
// public static final String ALL_PERMISSION = "@ALL_PERMISSION@";
public static final String ALL_PERMISSION = "@DATART_ALL_PERMISSION@";

/**
* Token Key
Expand Down Expand Up @@ -101,4 +100,6 @@ public class Const {

public static final String ENCRYPT_FLAG = "_encrypted_";

public static final String USER_DEFAULT_PSW = "123456";

}
4 changes: 3 additions & 1 deletion core/src/main/java/datart/core/base/consts/FileOwner.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public enum FileOwner {

SCHEDULE("schedule/files/"),

DOWNLOAD("download/");
DOWNLOAD("download/"),

EXPORT("export/");

private final String path;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@

package datart.core.base.consts;

public enum ShareType {
public enum ShareAuthenticationMode {

TOKEN_SHARE,
NONE,

PASSWORD_SHARE,
CODE,

LOGIN

AUTH_SHARE
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package datart.core.base.consts;

public enum ShareRowPermissionBy {

// use share creator's permission
CREATOR,
// use visitor's permission
VISITOR

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package datart.core.base.consts;

public enum TenantManagementMode {
/** 团队模式 */
TEAM,
/** 平台模式 */
PLATFORM;

}
40 changes: 40 additions & 0 deletions core/src/main/java/datart/core/common/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,26 @@

package datart.core.common;

import datart.core.base.consts.TenantManagementMode;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

import static datart.core.base.consts.TenantManagementMode.PLATFORM;

@Component
@Slf4j
public class Application implements ApplicationContextAware {

private static ApplicationContext context;

private static TenantManagementMode currMode;

@Override
public void setApplicationContext(@NonNull ApplicationContext applicationContext) throws BeansException {
Application.context = applicationContext;
Expand All @@ -43,6 +51,10 @@ public static <T> T getBean(Class<T> t) {
return context.getBean(t);
}

public static <T> T getBean(String beanName, Class<T> t) {
return context.getBean(beanName, t);
}

public static String getProperty(String key) {
return context.getEnvironment().getProperty(key);
}
Expand Down Expand Up @@ -74,8 +86,36 @@ public static String getApiPrefix() {
return getProperty("datart.server.path-prefix");
}

public static String getServerPrefix() {
return getProperty("server.servlet.context-path","/");
}

public static String getTokenSecret() {
return getProperty("datart.security.token.secret", "d@a$t%a^r&a*t");
}

public static boolean canRegister() {
return BooleanUtils.toBoolean(getProperty("datart.user.register", "true"));
}

public static String getAdminId() {
if (getCurrMode().equals(TenantManagementMode.TEAM)){
return getProperty("datart.admin-id", "datart-admin");
}
return "";
}

public static TenantManagementMode getCurrMode() {
if (currMode == null) {
String mode = Application.getProperty("datart.tenant-management-mode");
try {
return TenantManagementMode.valueOf(mode.toUpperCase());
} catch (Exception e) {
log.warn("Unrecognized tenant-management-mode: '{}', and this will run in platform tenant-management-mode", mode);
}
currMode = PLATFORM;
}
return currMode;
}

}
66 changes: 66 additions & 0 deletions core/src/main/java/datart/core/common/ClassTransformer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Datart
* <p>
* Copyright 2021
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package datart.core.common;

import org.apache.ibatis.javassist.ClassPool;
import org.apache.ibatis.javassist.CtClass;
import org.apache.ibatis.javassist.CtMethod;

public class ClassTransformer {

public static void transform() {
transformSqlWriter();
transformFlyway();
}

private static void transformSqlWriter() {
try {
ClassPool classPool = ClassPool.getDefault();
CtClass ctClass = classPool.get("org.apache.calcite.sql.pretty.SqlPrettyWriter");
CtMethod keyword = ctClass.getDeclaredMethod("keyword");
keyword.setBody("{ maybeWhitespace($1);" +
" buf.append($1);" +
" if (!$1.equals(\"\")) {" +
" setNeedWhitespace(needWhitespaceAfter($1));" +
" } " +
"return;} ");
ctClass.toClass();
} catch (Exception e) {
e.printStackTrace();
}
}

private static void transformFlyway() {
try {
ClassPool classPool = ClassPool.getDefault();
CtClass ctClass = classPool.get("org.flywaydb.core.internal.database.mysql.MySQLConnection");
CtMethod getIntVariableValue = ctClass.getDeclaredMethod("getIntVariableValue");
getIntVariableValue.setBody("return 0;");

CtMethod doRestoreOriginalState = ctClass.getDeclaredMethod("doRestoreOriginalState");
doRestoreOriginalState.setBody("return;");

CtMethod hasUserVariableResetCapability = ctClass.getDeclaredMethod("hasUserVariableResetCapability");
hasUserVariableResetCapability.setBody("{return false;}");
ctClass.toClass();
} catch (Exception e) {
e.printStackTrace();
}
}
}
17 changes: 17 additions & 0 deletions core/src/main/java/datart/core/common/DateUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

package datart.core.common;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;

import java.util.Date;

public class DateUtils {

private static final String[] FMT = {"y", "M", "d", "H", "m", "s", "S"};
Expand Down Expand Up @@ -46,4 +51,16 @@ public static String inferDateFormat(String src) {
return stringBuilder.toString();
}

public static boolean isDateFormat(String format) {
return StringUtils.isNotBlank(format) && "yyyy-MM-dd".equalsIgnoreCase(format.trim());
}

public static boolean isDateTimeFormat(String format) {
return StringUtils.isNotBlank(format) && "yyyy-MM-dd HH:mm:ss".equalsIgnoreCase(format.trim());
}

public static String withTimeString(String name) {
return name + DateFormatUtils.format(new Date(), DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS"));
}

}
Loading

0 comments on commit e2450b2

Please sign in to comment.