Browse Source

[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
3.0.0/version-upgrade
天仇 3 years ago committed by GitHub
parent
commit
95c119226b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UsersController.java
  2. 1
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java
  3. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java
  4. 13
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/UsersServiceImpl.java
  5. 15
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/CheckUtils.java
  6. 4
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java
  7. 16
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/User.java
  8. 4
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UserMapper.xml
  9. 3
      dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql
  10. 3
      dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql
  11. 5
      dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql
  12. 2
      dolphinscheduler-dao/src/main/resources/sql/upgrade/2.0.4_schema/mysql/dolphinscheduler_ddl.sql
  13. 2
      dolphinscheduler-dao/src/main/resources/sql/upgrade/2.1.0_schema/mysql/dolphinscheduler_ddl.sql
  14. 2
      dolphinscheduler-dao/src/main/resources/sql/upgrade/2.1.0_schema/postgresql/dolphinscheduler_ddl.sql

5
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<String, Object> 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<String, Object> result = usersService.updateUser(loginUser, id, userName, userPassword, email, tenantId, phone, queue, state, timeZone);
return returnDataList(result);
}

1
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}]已存在"),

2
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UsersService.java

@ -130,7 +130,7 @@ public interface UsersService {
* @throws Exception exception
*/
Map<String, Object> 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

13
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<String, Object> 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);

15
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
*

4
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<String, Object> result = usersService.updateUser(getLoginUser(), 0, userName, userPassword, "3443@qq.com", 1, "13457864543", "queue", 1);
Map<String, Object> 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) {

16
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 +
'}';

4
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UserMapper.xml

@ -19,11 +19,11 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.UserMapper">
<sql id="baseSql">
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
</sql>
<sql id="baseSqlV2">
${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
</sql>
<select id="queryAllGeneralUser" resultType="org.apache.dolphinscheduler.dao.entity.User">
select

3
dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql

@ -921,6 +921,7 @@ CREATE TABLE t_ds_user
update_time datetime DEFAULT NULL,
queue varchar(64) DEFAULT NULL,
state int(1) DEFAULT 1,
time_zone varchar(32) DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE KEY user_name_unique (user_name)
);
@ -979,7 +980,7 @@ VALUES ('1,2', 1, 'default admin warning group', 'default admin warning group',
-- ----------------------------
INSERT INTO t_ds_user
VALUES ('1', 'admin', '7ad2410b2f4c074479a8937a28a22b8f', '0', 'xxx@qq.com', '', '0', '2018-03-27 15:48:50',
'2018-10-24 17:40:22', null, 1);
'2018-10-24 17:40:22', null, 1, null);
-- ----------------------------
-- Table structure for t_ds_plugin_define

3
dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql

@ -911,6 +911,7 @@ CREATE TABLE `t_ds_user` (
`update_time` datetime DEFAULT NULL COMMENT 'update time',
`queue` varchar(64) DEFAULT NULL COMMENT 'queue',
`state` tinyint(4) DEFAULT '1' COMMENT 'state 0:disable 1:enable',
`time_zone` varchar(32) DEFAULT NULL COMMENT 'time zone',
PRIMARY KEY (`id`),
UNIQUE KEY `user_name_unique` (`user_name`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
@ -964,7 +965,7 @@ VALUES ("1,2", 1, 'default admin warning group', 'default admin warning group',
-- Records of t_ds_user
-- ----------------------------
INSERT INTO `t_ds_user`
VALUES ('1', 'admin', '7ad2410b2f4c074479a8937a28a22b8f', '0', 'xxx@qq.com', '', '0', '2018-03-27 15:48:50', '2018-10-24 17:40:22', null, 1);
VALUES ('1', 'admin', '7ad2410b2f4c074479a8937a28a22b8f', '0', 'xxx@qq.com', '', '0', '2018-03-27 15:48:50', '2018-10-24 17:40:22', null, 1, null);
-- ----------------------------
-- Table structure for t_ds_plugin_define

5
dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql

@ -805,6 +805,7 @@ CREATE TABLE t_ds_user (
update_time timestamp DEFAULT NULL ,
queue varchar(64) DEFAULT NULL ,
state int DEFAULT 1 ,
time_zone varchar(32) DEFAULT NULL,
PRIMARY KEY (id)
);
comment on column t_ds_user.state is 'state 0:disable 1:enable';
@ -947,8 +948,8 @@ ALTER TABLE t_ds_worker_server ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_worker_
-- Records of t_ds_user?user : admin , password : dolphinscheduler123
INSERT INTO t_ds_user(user_name, user_password, user_type, email, phone, tenant_id, state, create_time, update_time)
VALUES ('admin', '7ad2410b2f4c074479a8937a28a22b8f', '0', 'xxx@qq.com', '', '0', 1, '2018-03-27 15:48:50', '2018-10-24 17:40:22');
INSERT INTO t_ds_user(user_name, user_password, user_type, email, phone, tenant_id, state, create_time, update_time, time_zone)
VALUES ('admin', '7ad2410b2f4c074479a8937a28a22b8f', '0', 'xxx@qq.com', '', '0', 1, '2018-03-27 15:48:50', '2018-10-24 17:40:22', 'Asia/Shanghai');
-- Records of t_ds_alertgroup, default admin warning group
INSERT INTO t_ds_alertgroup(alert_instance_ids, create_user_id, group_name, description, create_time, update_time)

2
dolphinscheduler-dao/src/main/resources/sql/upgrade/2.0.4_schema/mysql/dolphinscheduler_ddl.sql

@ -13,4 +13,4 @@
* 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.
*/
*/

2
dolphinscheduler-dao/src/main/resources/sql/upgrade/2.1.0_schema/mysql/dolphinscheduler_ddl.sql

@ -27,6 +27,8 @@ alter table t_ds_task_definition_log add `task_group_priority` int(11) DEFAULT N
alter table t_ds_task_definition add `task_group_id` int(11) DEFAULT NULL COMMENT 'task group id' AFTER `resource_ids`;
alter table t_ds_task_definition add `task_group_priority` int(11) DEFAULT '0' COMMENT 'task group id' AFTER `task_group_id`;
ALTER TABLE `t_ds_user` ADD COLUMN `time_zone` varchar(32) DEFAULT NULL COMMENT 'time zone';
--
-- Table structure for table `t_ds_dq_comparison_type`
--

2
dolphinscheduler-dao/src/main/resources/sql/upgrade/2.1.0_schema/postgresql/dolphinscheduler_ddl.sql

@ -38,6 +38,8 @@ EXECUTE 'CREATE INDEX IF NOT EXISTS process_task_relation_log_idx_project_code_p
EXECUTE 'DROP INDEX IF EXISTS "idx_task_definition_log_code_version"';
EXECUTE 'CREATE INDEX IF NOT EXISTS idx_task_definition_log_code_version ON ' || quote_ident(v_schema) ||'.t_ds_task_definition_log USING Btree("code","version")';
EXECUTE 'ALTER TABLE ' || quote_ident(v_schema) ||'.t_ds_user ADD COLUMN IF NOT EXISTS "time_zone" varchar(32) DEFAULT NULL';
EXECUTE 'CREATE TABLE IF NOT EXISTS' || quote_ident(v_schema) ||'."t_ds_dq_comparison_type" (
id serial NOT NULL,
"type" varchar NOT NULL,

Loading…
Cancel
Save