This is an automated email from the ASF dual-hosted git repository.

journey pushed a commit to branch 1.3.2-release
in repository https://gitbox.apache.org/repos/asf/incubator-dolphinscheduler.git


The following commit(s) were added to refs/heads/1.3.2-release by this push:
     new a409306  [Fix-3462][api]If login user is admin,need list all udfs 
(#3465)
a409306 is described below

commit a409306601891c08d76f7bbfdc842012db1af537
Author: lgcareer <18610854...@163.com>
AuthorDate: Wed Aug 12 14:59:38 2020 +0800

    [Fix-3462][api]If login user is admin,need list all udfs (#3465)
    
    * [Fix-3462][api]If login user is admin,need list all udfs
    
    * [Fix-3462][api]add the test on the method of QueryUdfFuncList
    
    * [Fix-3462][api]fix the code smell
    
    * [Fix-3462][api]fix the code smell
    
    * [Fix-3462][api]fix the code smell
---
 .../api/controller/ResourcesController.java                | 14 ++++++++------
 .../dolphinscheduler/api/service/UdfFuncService.java       | 14 +++++++++-----
 .../dolphinscheduler/api/service/UdfFuncServiceTest.java   |  8 +++++---
 3 files changed, 22 insertions(+), 14 deletions(-)

diff --git 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java
 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java
index 2af8ccd..2f2cb9c 100644
--- 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java
+++ 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java
@@ -564,7 +564,7 @@ public class ResourcesController extends BaseController {
     @GetMapping(value = "/udf-func/list-paging")
     @ResponseStatus(HttpStatus.OK)
     @ApiException(QUERY_UDF_FUNCTION_LIST_PAGING_ERROR)
-    public Result queryUdfFuncList(@ApiIgnore @RequestAttribute(value = 
Constants.SESSION_USER) User loginUser,
+    public Result<Object> queryUdfFuncListPaging(@ApiIgnore 
@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                    @RequestParam("pageNo") Integer pageNo,
                                    @RequestParam(value = "searchVal", required 
= false) String searchVal,
                                    @RequestParam("pageSize") Integer pageSize
@@ -581,23 +581,25 @@ public class ResourcesController extends BaseController {
     }
 
     /**
-     * query resource list by type
+     * query udf func list by type
      *
      * @param loginUser login user
      * @param type      resource type
      * @return resource list
      */
-    @ApiOperation(value = "queryResourceList", notes = 
"QUERY_RESOURCE_LIST_NOTES")
+    @ApiOperation(value = "queryUdfFuncList", notes = 
"QUERY_UDF_FUNC_LIST_NOTES")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "type", value = "UDF_TYPE", required = 
true, dataType = "UdfType")
     })
     @GetMapping(value = "/udf-func/list")
     @ResponseStatus(HttpStatus.OK)
     @ApiException(QUERY_DATASOURCE_BY_TYPE_ERROR)
-    public Result queryResourceList(@ApiIgnore @RequestAttribute(value = 
Constants.SESSION_USER) User loginUser,
+    public Result<Object> queryUdfFuncList(@ApiIgnore @RequestAttribute(value 
= Constants.SESSION_USER) User loginUser,
                                     @RequestParam("type") UdfType type) {
-        logger.info("query datasource list, user:{}, type:{}", 
loginUser.getUserName(), type);
-        Map<String, Object> result = 
udfFuncService.queryResourceList(loginUser, type.ordinal());
+        String userName = loginUser.getUserName();
+        userName = userName.replaceAll("[\n|\r|\t]", "_");
+        logger.info("query udf func list, user:{}, type:{}", userName, type);
+        Map<String, Object> result = 
udfFuncService.queryUdfFuncList(loginUser, type.ordinal());
         return returnDataList(result);
     }
 
diff --git 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UdfFuncService.java
 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UdfFuncService.java
index 8a0bf74..4d4aec7 100644
--- 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UdfFuncService.java
+++ 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/UdfFuncService.java
@@ -279,15 +279,19 @@ public class UdfFuncService extends BaseService{
     }
 
     /**
-     * query data resource by type
+     * query udf list
      *
      * @param loginUser login user
-     * @param type  resource type
-     * @return resource list
+     * @param type  udf type
+     * @return udf func list
      */
-    public Map<String, Object> queryResourceList(User loginUser, Integer type) 
{
+    public Map<String, Object> queryUdfFuncList(User loginUser, Integer type) {
         Map<String, Object> result = new HashMap<>(5);
-        List<UdfFunc> udfFuncList = 
udfFuncMapper.getUdfFuncByType(loginUser.getId(), type);
+        int userId = loginUser.getId();
+        if (isAdmin(loginUser)) {
+            userId = 0;
+        }
+        List<UdfFunc> udfFuncList = udfFuncMapper.getUdfFuncByType(userId, 
type);
 
         result.put(Constants.DATA_LIST, udfFuncList);
         putMsg(result, Status.SUCCESS);
diff --git 
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UdfFuncServiceTest.java
 
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UdfFuncServiceTest.java
index 9ec24bb..884e9b6 100644
--- 
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UdfFuncServiceTest.java
+++ 
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UdfFuncServiceTest.java
@@ -149,9 +149,11 @@ public class UdfFuncServiceTest {
     }
 
     @Test
-    public  void testQueryResourceList(){
-        Mockito.when(udfFuncMapper.getUdfFuncByType(1, 
1)).thenReturn(getList());
-        Map<String, Object> result = 
udfFuncService.queryResourceList(getLoginUser(),1);
+    public  void testQueryUdfFuncList(){
+        User user = getLoginUser();
+        user.setUserType(UserType.GENERAL_USER);
+        Mockito.when(udfFuncMapper.getUdfFuncByType(user.getId(), 
UdfType.HIVE.ordinal())).thenReturn(getList());
+        Map<String, Object> result = 
udfFuncService.queryUdfFuncList(user,UdfType.HIVE.ordinal());
         logger.info(result.toString());
         Assert.assertEquals(Status.SUCCESS,result.get(Constants.STATUS));
         List<UdfFunc> udfFuncList = (List<UdfFunc>) 
result.get(Constants.DATA_LIST);

Reply via email to