From b94dd37e153de1c07958e28929fba7a8e60f77b6 Mon Sep 17 00:00:00 2001 From: lgcareer <18610854716@163.com> Date: Thu, 24 Oct 2019 10:51:15 +0800 Subject: [PATCH] change method check (#1086) * rename from DatasourceUserMapper to DataSourceUserMapper * add unit test in UserMapper and WorkerGroupMapper * change cn.escheduler to org.apache.dolphinscheduler * add unit test in UdfFuncMapperTest * add unit test in UdfFuncMapperTest * remove DatabaseConfiguration * add ConnectionFactoryTest * cal duration in processInstancesList * change desc to description * change table name in mysql ddl * change table name in mysql ddl * change escheduler to dolphinscheduler * change escheduler to dolphinscheduler * change escheduler to dolphinscheduler * remove log4j-1.2-api and modify AlertMapperTest * remove log4j-1.2-api * Add alertDao to spring management * Add alertDao to spring management * get SqlSessionFactory from MybatisSqlSessionFactoryBean * get processDao by DaoFactory * read druid properties in ConneciontFactory * read druid properties in ConneciontFactory * change get alertDao by spring to DaoFactory * add log4j to resolve #967 * resole verify udf name error and delete udf error * Determine if principal is empty * Determine whether the logon user has the right to delete the project * Fixed an issue that produced attatch file named such as ATT00002.bin * fix too many connection in upgrade or create * fix NEED_FAULT_TOLERANCE and WAITTING_THREAD count fail * Added a judgment on whether the currently login user is an administrator * fix update udf database not change and create time is changed * add enterprise.wechat.enable to decide whether to send enterprise WeChat * change method check --- .../api/service/UsersService.java | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) 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 9ebfa6fd58..6cd997d642 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 @@ -98,11 +98,11 @@ public class UsersService extends BaseService { if (result.get(Constants.STATUS) != Status.SUCCESS) { return result; } - if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM, Constants.STATUS)) { + if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) { return result; } - if (check(result, checkTenant(tenantId), Status.TENANT_NOT_EXIST, Constants.STATUS)) { + if (check(result, checkTenant(tenantId), Status.TENANT_NOT_EXIST)) { return result; } @@ -176,7 +176,7 @@ public class UsersService extends BaseService { public Map queryUserList(User loginUser, String searchVal, Integer pageNo, Integer pageSize) { Map result = new HashMap<>(5); - if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM, Constants.STATUS)) { + if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) { return result; } @@ -352,14 +352,14 @@ public class UsersService extends BaseService { result.put(Constants.STATUS, false); //only admin can operate - if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM, Constants.STATUS)) { + if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) { return result; } //if the selected projectIds are empty, delete all items associated with the user projectUserMapper.deleteProjectRelation(0, userId); - if (check(result, StringUtils.isEmpty(projectIds), Status.SUCCESS, Constants.MSG)) { + if (check(result, StringUtils.isEmpty(projectIds), Status.SUCCESS)) { return result; } @@ -393,7 +393,7 @@ public class UsersService extends BaseService { public Map grantResources(User loginUser, int userId, String resourceIds) { Map result = new HashMap<>(5); //only admin can operate - if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM, Constants.STATUS)) { + if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) { return result; } User user = userMapper.selectById(userId); @@ -404,7 +404,7 @@ public class UsersService extends BaseService { resourcesUserMapper.deleteResourceUser(userId, 0); - if (check(result, StringUtils.isEmpty(resourceIds), Status.SUCCESS, Constants.MSG)) { + if (check(result, StringUtils.isEmpty(resourceIds), Status.SUCCESS)) { return result; } @@ -439,13 +439,13 @@ public class UsersService extends BaseService { Map result = new HashMap<>(5); //only admin can operate - if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM, Constants.STATUS)) { + if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) { return result; } udfUserMapper.deleteByUserId(userId); - if (check(result, StringUtils.isEmpty(udfIds), Status.SUCCESS, Constants.MSG)) { + if (check(result, StringUtils.isEmpty(udfIds), Status.SUCCESS)) { return result; } @@ -481,13 +481,13 @@ public class UsersService extends BaseService { result.put(Constants.STATUS, false); //only admin can operate - if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM, Constants.STATUS)) { + if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) { return result; } datasourceUserMapper.deleteByUserId(userId); - if (check(result, StringUtils.isEmpty(datasourceIds), Status.SUCCESS, Constants.MSG)) { + if (check(result, StringUtils.isEmpty(datasourceIds), Status.SUCCESS)) { return result; } @@ -554,7 +554,7 @@ public class UsersService extends BaseService { public Map queryAllGeneralUsers(User loginUser) { Map result = new HashMap<>(5); //only admin can operate - if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM, Constants.STATUS)) { + if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) { return result; } @@ -575,7 +575,7 @@ public class UsersService extends BaseService { public Map queryUserList(User loginUser) { Map result = new HashMap<>(5); //only admin can operate - if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM, Constants.STATUS)) { + if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) { return result; } @@ -619,7 +619,7 @@ public class UsersService extends BaseService { Map result = new HashMap<>(5); //only admin can operate - if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM, Constants.STATUS)) { + if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) { return result; } @@ -655,7 +655,7 @@ public class UsersService extends BaseService { public Map authorizedUser(User loginUser, Integer alertgroupId) { Map result = new HashMap<>(5); //only admin can operate - if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM, Constants.STATUS)) { + if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM)) { return result; } List userList = userMapper.queryUserListByAlertGroupId(alertgroupId); @@ -671,14 +671,13 @@ public class UsersService extends BaseService { * @param result * @param bool * @param userNoOperationPerm - * @param status * @return */ - private boolean check(Map result, boolean bool, Status userNoOperationPerm, String status) { + private boolean check(Map result, boolean bool, Status userNoOperationPerm) { //only admin can operate if (bool) { result.put(Constants.STATUS, userNoOperationPerm); - result.put(status, userNoOperationPerm.getMsg()); + result.put(Constants.MSG, userNoOperationPerm.getMsg()); return true; } return false;