Browse Source

[DS-7896][fix] Fixed when a non-admin user creates a udf function, resources other than .jar will be displayed in the UDF resource (#8458)

This closes #7892
3.0.0/version-upgrade
Sunny Lei 3 years ago committed by GitHub
parent
commit
1ffb5d6e8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java
  2. 27
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ResourcesServiceTest.java

5
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java

@ -1346,9 +1346,12 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe
// query resource relation // query resource relation
relationResources = queryResourceList(userId, 0); relationResources = queryResourceList(userId, 0);
} }
// filter by resource type
List<Resource> relationTypeResources =
relationResources.stream().filter(rs -> rs.getType() == type).collect(Collectors.toList());
List<Resource> ownResourceList = resourcesMapper.queryResourceListAuthored(userId, type.ordinal()); List<Resource> ownResourceList = resourcesMapper.queryResourceListAuthored(userId, type.ordinal());
ownResourceList.addAll(relationResources); ownResourceList.addAll(relationTypeResources);
return ownResourceList; return ownResourceList;
} }

27
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ResourcesServiceTest.java

@ -42,6 +42,7 @@ import org.apache.commons.collections.CollectionUtils;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -293,6 +294,19 @@ public class ResourcesServiceTest {
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
List<Resource> resourceList = (List<Resource>) result.get(Constants.DATA_LIST); List<Resource> resourceList = (List<Resource>) result.get(Constants.DATA_LIST);
Assert.assertTrue(CollectionUtils.isNotEmpty(resourceList)); Assert.assertTrue(CollectionUtils.isNotEmpty(resourceList));
// test udf
loginUser.setUserType(UserType.GENERAL_USER);
Mockito.when(resourceUserMapper.queryResourcesIdListByUserIdAndPerm(0, 0))
.thenReturn(Arrays.asList(Integer.valueOf(10), Integer.valueOf(11)));
Mockito.when(resourcesMapper.queryResourceListById(Arrays.asList(Integer.valueOf(10), Integer.valueOf(11))))
.thenReturn(Arrays.asList(getResource(10, ResourceType.FILE), getResource(11, ResourceType.UDF)));
Mockito.when(resourcesMapper.queryResourceListAuthored(0, 1)).thenReturn(getResourceList());
result = resourcesService.queryResourceList(loginUser, ResourceType.UDF);
logger.info(result.toString());
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
resourceList = (List<Resource>) result.get(Constants.DATA_LIST);
Assert.assertTrue(resourceList.size() == 4);
} }
@Test @Test
@ -755,6 +769,19 @@ public class ResourcesServiceTest {
return resource; return resource;
} }
private Resource getResource(int resourceId,ResourceType type) {
Resource resource = new Resource();
resource.setId(resourceId);
resource.setPid(-1);
resource.setUserId(1);
resource.setDescription("ResourcesServiceTest.jar");
resource.setAlias("ResourcesServiceTest.jar");
resource.setFullName("/ResourcesServiceTest.jar");
resource.setType(type);
return resource;
}
private Resource getUdfResource() { private Resource getUdfResource() {
Resource resource = new Resource(); Resource resource = new Resource();

Loading…
Cancel
Save