diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java index 3dc79a6a5f..67cbeb81a8 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/python/PythonGateway.java @@ -537,7 +537,7 @@ public class PythonGateway { public Map queryResourcesFileInfo(String userName, String fullName) { Map result = new HashMap<>(); User user = usersService.queryUser(userName); - Result resourceResponse = resourceService.queryResource(user, fullName, null, ResourceType.FILE); + Result resourceResponse = resourceService.queryResource(fullName, null, ResourceType.FILE); if (resourceResponse.getCode() != Status.SUCCESS.getCode()) { String msg = String.format("Can not find valid resource by name %s", fullName); logger.error(msg); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/QueueServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/QueueServiceImpl.java index bce236250e..435f3875e2 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/QueueServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/QueueServiceImpl.java @@ -17,17 +17,12 @@ package org.apache.dolphinscheduler.api.service.impl; -import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.YARN_QUEUE_CREATE; -import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.YARN_QUEUE_UPDATE; - import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.exceptions.ServiceException; import org.apache.dolphinscheduler.api.service.QueueService; import org.apache.dolphinscheduler.api.utils.PageInfo; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; -import org.apache.dolphinscheduler.common.enums.AuthorizationType; -import org.apache.dolphinscheduler.common.enums.UserType; import org.apache.dolphinscheduler.dao.entity.Queue; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.QueueMapper; @@ -35,20 +30,15 @@ import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.apache.commons.lang3.StringUtils; -import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -181,7 +171,6 @@ public class QueueServiceImpl extends BaseServiceImpl implements QueueService { result.put(Constants.DATA_LIST, queueObj); putMsg(result, Status.SUCCESS); - permissionPostHandle(AuthorizationType.QUEUE, loginUser.getId(), Collections.singletonList(queueObj.getId()), logger); return result; } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java index cc93f5a77b..312bb014d4 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ResourcesServiceImpl.java @@ -341,7 +341,7 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe return result; } - if (!PropertyUtils.getResUploadStartupState()){ + if (!PropertyUtils.getResUploadStartupState()) { putMsg(result, Status.STORAGE_NOT_STARTUP); return result; } @@ -1068,7 +1068,7 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe public Result onlineCreateOrUpdateResourceWithDir(User loginUser, String fileFullName, String desc, String content) { if (checkResourceExists(fileFullName, ResourceType.FILE.ordinal())) { Resource resource = resourcesMapper.queryResource(fileFullName, ResourceType.FILE.ordinal()).get(0); - Result result = this.updateResourceContent(loginUser, resource.getId(), content); + Result result = this.updateResourceContent(resource.getId(), content); if (result.getCode() == Status.SUCCESS.getCode()) { resource.setDescription(desc); Map resultMap = new HashMap<>(); @@ -1143,11 +1143,6 @@ public class ResourcesServiceImpl extends BaseServiceImpl implements ResourcesSe } } - private void permissionPostHandle(ResourceType resourceType, User loginUser, Integer resourceId) { - AuthorizationType authorizationType = resourceType.equals(ResourceType.FILE) ? AuthorizationType.RESOURCE_FILE_ID : AuthorizationType.UDF_FILE; - permissionPostHandle(authorizationType, loginUser.getId(), Collections.singletonList(resourceId), logger); - } - private Result checkResourceUploadStartupState() { Result result = new Result<>(); putMsg(result, Status.SUCCESS); diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java index f07966af76..559df56dca 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java @@ -29,7 +29,6 @@ import org.apache.dolphinscheduler.api.utils.PageInfo; import org.apache.dolphinscheduler.api.utils.RegexUtils; import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.common.Constants; -import org.apache.dolphinscheduler.common.enums.AuthorizationType; import org.apache.dolphinscheduler.common.storage.StorageOperate; import org.apache.dolphinscheduler.common.utils.PropertyUtils; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; @@ -47,16 +46,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; -import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.*; import static org.apache.dolphinscheduler.common.Constants.TENANT_FULL_NAME_MAX_LENGTH; /** @@ -143,8 +137,8 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService String desc) throws Exception { Map result = new HashMap<>(); result.put(Constants.STATUS, false); - if (!canOperatorPermissions(loginUser,null, AuthorizationType.TENANT, TENANT_CREATE)) { - throw new ServiceException(Status.USER_NO_OPERATION_PERM); + if (isNotAdmin(loginUser, result)) { + return result; } Tenant tenant = new Tenant(tenantCode, desc, queueId); @@ -155,7 +149,6 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService if (PropertyUtils.getResUploadStartupState()) { storageOperate.createTenantDirIfNotExists(tenantCode); } - permissionPostHandle(AuthorizationType.TENANT, loginUser.getId(), Collections.singletonList(tenant.getId()), logger); result.put(Constants.DATA_LIST, tenant); putMsg(result, Status.SUCCESS); return result; @@ -174,18 +167,15 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService public Result queryTenantList(User loginUser, String searchVal, Integer pageNo, Integer pageSize) { Result result = new Result<>(); - PageInfo pageInfo = new PageInfo<>(pageNo, pageSize); - Set ids = resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.TENANT, loginUser.getId(), logger); - if (ids.isEmpty()) { - result.setData(pageInfo); - putMsg(result, Status.SUCCESS); - return result; + if (!isAdmin(loginUser)) { + putMsg(result, Status.USER_NO_OPERATION_PERM); } Page page = new Page<>(pageNo, pageSize); - IPage tenantPage = tenantMapper.queryTenantPaging(page, new ArrayList<>(ids), searchVal); + IPage tenantIPage = tenantMapper.queryTenantPaging(page, searchVal); + PageInfo pageInfo = new PageInfo<>(pageNo, pageSize); + pageInfo.setTotal((int) tenantIPage.getTotal()); + pageInfo.setTotalList(tenantIPage.getRecords()); - pageInfo.setTotal((int) tenantPage.getTotal()); - pageInfo.setTotalList(tenantPage.getRecords()); result.setData(pageInfo); putMsg(result, Status.SUCCESS); return result; @@ -207,9 +197,10 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService String desc) throws Exception { Map result = new HashMap<>(); + result.put(Constants.STATUS, false); - if (!canOperatorPermissions(loginUser,null, AuthorizationType.TENANT,TENANT_UPDATE)) { - throw new ServiceException(Status.USER_NO_OPERATION_PERM); + if (isNotAdmin(loginUser, result)) { + return result; } Tenant updateTenant = new Tenant(id, tenantCode, desc, queueId); @@ -242,8 +233,8 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService public Map deleteTenantById(User loginUser, int id) throws Exception { Map result = new HashMap<>(); - if (!canOperatorPermissions(loginUser,null, AuthorizationType.TENANT,TENANT_DELETE)) { - throw new ServiceException(Status.USER_NO_OPERATION_PERM); + if (isNotAdmin(loginUser, result)) { + return result; } Tenant tenant = tenantMapper.queryById(id); @@ -293,13 +284,7 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService public Map queryTenantList(User loginUser) { Map result = new HashMap<>(); - Set ids = resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.TENANT, loginUser.getId(), logger); - if (ids.isEmpty()) { - result.put(Constants.DATA_LIST, Collections.emptyList()); - putMsg(result, Status.SUCCESS); - return result; - } - List resourceList = tenantMapper.selectBatchIds(ids); + List resourceList = tenantMapper.selectList(null); result.put(Constants.DATA_LIST, resourceList); putMsg(result, Status.SUCCESS); return result; diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/python/PythonGatewayTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/python/PythonGatewayTest.java index 022eb344a5..a2c63a49f3 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/python/PythonGatewayTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/python/PythonGatewayTest.java @@ -126,7 +126,7 @@ public class PythonGatewayTest { mockResult.setCode(Status.SUCCESS.getCode()); Resource resource = getTestResource(); mockResult.setData(resource); - Mockito.when(resourcesService.queryResource(user, resource.getFullName(), null, ResourceType.FILE)).thenReturn(mockResult); + Mockito.when(resourcesService.queryResource(resource.getFullName(), null, ResourceType.FILE)).thenReturn(mockResult); Map result = pythonGateway.queryResourcesFileInfo(user.getUserName(), resource.getFullName()); Assert.assertEquals((int) result.get("id"), resource.getId()); diff --git a/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py b/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py index dd18dafa0f..63e080899d 100644 --- a/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py +++ b/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/core/process_definition.py @@ -411,7 +411,6 @@ class ProcessDefinition(Base): json.dumps(self.task_relation_json), json.dumps(self.task_definition_json), None, - None, ) if len(self.resource_list) > 0: for res in self.resource_list: