Browse Source

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
lgcareer 5 years ago
parent
commit
b94dd37e15

+ 17 - 18
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<String, Object> queryUserList(User loginUser, String searchVal, Integer pageNo, Integer pageSize) {
         Map<String, Object> 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<String, Object> grantResources(User loginUser, int userId, String resourceIds) {
         Map<String, Object> 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<String, Object> 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<String, Object> queryAllGeneralUsers(User loginUser) {
         Map<String, Object> 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<String, Object> queryUserList(User loginUser) {
         Map<String, Object> 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<String, Object> 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<String, Object> authorizedUser(User loginUser, Integer alertgroupId) {
         Map<String, Object> 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<User> 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<String, Object> result, boolean bool, Status userNoOperationPerm, String status) {
+    private boolean check(Map<String, Object> 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;