From 95c119226ba8998f778ad33c5ccf836ce4bee1e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A9=E4=BB=87?= <532066967@qq.com> Date: Mon, 21 Feb 2022 23:28:31 +0800 Subject: [PATCH] [Feature-8386][Server] Custom timezone - Add timezone into user info (#8457) * [Feature-8386][Server] Custom timezone - Add timezone into user info 1. Add column `time_zone varchar(32) default null` in table `t_ds_user` 2. Add system default timezone like `GMT+08:00` when create user 3. Add timeZone property when update user info This completes #8386 * [Feature-8386][Server] Custom timezone - Add timezone into user info 1. Add column `time_zone varchar(32) default null` in table `t_ds_user` 2. Add system default timezone like `GMT+08:00` when create user 3. Add timeZone property when update user info 4. add ddl sql in update sql script This completes #8386 * [Feature-8386][Server] Custom timezone - Add timezone into user info 1. Add column `time_zone varchar(32) default null` in table `t_ds_user` 2. Set timeZone null when create user 3. Add timeZone property when update user info This completes #8386 * [Feature-8386][Server] Custom timezone - Add timezone into user info 1. Add column `time_zone varchar(32) default null` in table `t_ds_user` 2. Set timeZone null when create user 3. Add timeZone property when update user info This completes #8386 * [Feature-8386][Server] Custom timezone - Add timezone into user info 1. Add column `time_zone varchar(32) default null` in table `t_ds_user` 2. Set timeZone null when create user 3. Add timeZone property when update user info This completes #8386 * [Feature-8386][Server] Custom timezone - Add timezone into user info 1. Add column `time_zone varchar(32) default null` in table `t_ds_user` 2. Set timeZone null when create user 3. Add timeZone property when update user info This completes #8386 * [Feature-8386][Server] Custom timezone - Add timezone into user info 1. Add column `time_zone varchar(32) default null` in table `t_ds_user` 2. Set timeZone null when create user 3. Add timeZone property when update user info This completes #8386 --- .../api/controller/UsersController.java | 5 +++-- .../dolphinscheduler/api/enums/Status.java | 1 + .../api/service/UsersService.java | 2 +- .../api/service/impl/UsersServiceImpl.java | 13 ++++++++++++- .../dolphinscheduler/api/utils/CheckUtils.java | 15 +++++++++++++++ .../api/service/UsersServiceTest.java | 4 ++-- .../apache/dolphinscheduler/dao/entity/User.java | 16 +++++++++++++++- .../dolphinscheduler/dao/mapper/UserMapper.xml | 4 ++-- .../main/resources/sql/dolphinscheduler_h2.sql | 3 ++- .../resources/sql/dolphinscheduler_mysql.sql | 3 ++- .../sql/dolphinscheduler_postgresql.sql | 5 +++-- .../2.0.4_schema/mysql/dolphinscheduler_ddl.sql | 2 +- .../2.1.0_schema/mysql/dolphinscheduler_ddl.sql | 2 ++ .../postgresql/dolphinscheduler_ddl.sql | 2 ++ 14 files changed, 63 insertions(+), 14 deletions(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UsersController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UsersController.java index a79e5f709a..da48ca763f 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UsersController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UsersController.java @@ -185,8 +185,9 @@ public class UsersController extends BaseController { @RequestParam(value = "email") String email, @RequestParam(value = "tenantId") int tenantId, @RequestParam(value = "phone", required = false) String phone, - @RequestParam(value = "state", required = false) int state) throws Exception { - Map result = usersService.updateUser(loginUser, id, userName, userPassword, email, tenantId, phone, queue, state); + @RequestParam(value = "state", required = false) int state, + @RequestParam(value = "timeZone", required = false) String timeZone) throws Exception { + Map result = usersService.updateUser(loginUser, id, userName, userPassword, email, tenantId, phone, queue, state, timeZone); return returnDataList(result); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java index 1f6add9b64..729ed8080b 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java @@ -380,6 +380,7 @@ public enum Status { TASK_GROUP_STATUS_OPENED(130019,"The task group has been opened.","任务组已经被开启"), NOT_ALLOW_TO_DISABLE_OWN_ACCOUNT(130020, "Not allow to disable your own account", "不能停用自己的账号"), NOT_ALLOW_TO_DELETE_DEFAULT_ALARM_GROUP(130030, "Not allow to delete the default alarm group ", "不能删除默认告警组"), + TIME_ZONE_ILLEGAL(130031, "time zone [{0}] is illegal", "时区参数 [{0}] 不合法"), QUERY_K8S_NAMESPACE_LIST_PAGING_ERROR(1300001, "login user query k8s namespace list paging error", "分页查询k8s名称空间列表错误"), K8S_NAMESPACE_EXIST(1300002, "k8s namespace {0} already exists", "k8s命名空间[{0}]已存在"), diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java index 485702a0e8..b303abc856 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java @@ -130,7 +130,7 @@ public interface UsersService { * @throws Exception exception */ Map updateUser(User loginUser, int userId, String userName, String userPassword, String email, - int tenantId, String phone, String queue, int state) throws IOException; + int tenantId, String phone, String queue, int state, String timeZone) throws IOException; /** * delete user diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java index b057bae81d..b6ec2c3239 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java @@ -349,6 +349,8 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService { * @param tenantId tenant id * @param phone phone * @param queue queue + * @param state state + * @param timeZone timeZone * @return update result code * @throws Exception exception */ @@ -360,7 +362,8 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService { int tenantId, String phone, String queue, - int state) throws IOException { + int state, + String timeZone) throws IOException { Map result = new HashMap<>(); result.put(Constants.STATUS, false); @@ -413,6 +416,14 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService { return result; } + if (StringUtils.isNotEmpty(timeZone)) { + if (!CheckUtils.checkTimeZone(timeZone)) { + putMsg(result, Status.TIME_ZONE_ILLEGAL, timeZone); + return result; + } + user.setTimeZone(timeZone); + } + user.setPhone(phone); user.setQueue(queue); user.setState(state); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/CheckUtils.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/CheckUtils.java index 3891087440..2e84a14680 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/CheckUtils.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/CheckUtils.java @@ -29,6 +29,7 @@ import org.apache.commons.lang.StringUtils; import org.hibernate.validator.internal.constraintvalidators.bv.EmailValidator; import java.text.MessageFormat; +import java.time.ZoneId; import java.util.HashMap; import java.util.Map; import java.util.regex.Pattern; @@ -121,6 +122,20 @@ public class CheckUtils { return StringUtils.isEmpty(phone) || phone.length() == 11; } + /** + * check time zone parameter + * @param timeZone timeZone + * @return true if timeZone is valid, otherwise return false + */ + public static boolean checkTimeZone(String timeZone) { + try { + ZoneId.of(timeZone); + return true; + } catch (Exception e) { + return false; + } + } + /** * check task node parameter * diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java index 36a313bedc..53612053fe 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java @@ -269,13 +269,13 @@ public class UsersServiceTest { String userPassword = "userTest0001"; try { //user not exist - Map result = usersService.updateUser(getLoginUser(), 0, userName, userPassword, "3443@qq.com", 1, "13457864543", "queue", 1); + Map result = usersService.updateUser(getLoginUser(), 0, userName, userPassword, "3443@qq.com", 1, "13457864543", "queue", 1, "Asia/Shanghai"); Assert.assertEquals(Status.USER_NOT_EXIST, result.get(Constants.STATUS)); logger.info(result.toString()); //success when(userMapper.selectById(1)).thenReturn(getUser()); - result = usersService.updateUser(getLoginUser(), 1, userName, userPassword, "32222s@qq.com", 1, "13457864543", "queue", 1); + result = usersService.updateUser(getLoginUser(), 1, userName, userPassword, "32222s@qq.com", 1, "13457864543", "queue", 1, "Asia/Shanghai"); logger.info(result.toString()); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); } catch (Exception e) { diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/User.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/User.java index 2110fe2021..a7445ed2ae 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/User.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/User.java @@ -96,6 +96,11 @@ public class User { */ private String queue; + /** + * time zone + */ + private String timeZone; + /** * create time */ @@ -221,6 +226,14 @@ public class User { this.state = state; } + public String getTimeZone() { + return timeZone; + } + + public void setTimeZone(String timeZone) { + this.timeZone = timeZone; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -260,7 +273,8 @@ public class User { ", tenantCode='" + tenantCode + '\'' + ", queueName='" + queueName + '\'' + ", alertGroup='" + alertGroup + '\'' + - ", queue='" + queue + '\'' + + ", queue='" + queue + '\'' + + ", timeZone='" + timeZone + '\'' + ", createTime=" + createTime + ", updateTime=" + updateTime + '}'; diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UserMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UserMapper.xml index 570e395ffb..b105679970 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UserMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UserMapper.xml @@ -19,11 +19,11 @@ - id, user_name, user_password, user_type, email, phone, tenant_id, create_time, update_time, queue, state + id, user_name, user_password, user_type, email, phone, tenant_id, create_time, update_time, queue, state, time_zone ${alias}.id, ${alias}.user_name, ${alias}.user_password, ${alias}.user_type, ${alias}.email, ${alias}.phone, ${alias}.tenant_id, - ${alias}.create_time, ${alias}.update_time, ${alias}.queue, ${alias}.state + ${alias}.create_time, ${alias}.update_time, ${alias}.queue, ${alias}.state, ${alias}.time_zone