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

dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git


The following commit(s) were added to refs/heads/master by this push:
     new 2090dcd0fa [INLONG-8438][Manager] Removes the restriction that only 
the admin user can create DataNodes by openAPI (#8439)
2090dcd0fa is described below

commit 2090dcd0fa447667f59dd0fc1d8e5fc986cc6541
Author: fuweng11 <[email protected]>
AuthorDate: Thu Jul 6 15:17:36 2023 +0800

    [INLONG-8438][Manager] Removes the restriction that only the admin user can 
create DataNodes by openAPI (#8439)
---
 .../inlong/manager/service/node/DataNodeServiceImpl.java     | 12 ------------
 .../web/controller/openapi/OpenDataNodeController.java       |  6 ++++++
 2 files changed, 6 insertions(+), 12 deletions(-)

diff --git 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/node/DataNodeServiceImpl.java
 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/node/DataNodeServiceImpl.java
index 26de8453c4..145435fef1 100644
--- 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/node/DataNodeServiceImpl.java
+++ 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/node/DataNodeServiceImpl.java
@@ -93,10 +93,6 @@ public class DataNodeServiceImpl implements DataNodeService {
             request.setName(name);
         }
 
-        // only the person in charges can query
-        if 
(!opInfo.getAccountType().equals(TenantUserTypeEnum.TENANT_ADMIN.getCode())) {
-            throw new BusinessException(ErrorCodeEnum.PERMISSION_REQUIRED);
-        }
         // check if data node already exist
         DataNodeEntity existEntity =
                 dataNodeMapper.selectByUniqueKey(request.getName(), 
request.getType());
@@ -222,10 +218,6 @@ public class DataNodeServiceImpl implements 
DataNodeService {
     @Override
     @Transactional(rollbackFor = Throwable.class)
     public Boolean update(DataNodeRequest request, UserInfo opInfo) {
-        // only the person in charges can query
-        if 
(!opInfo.getAccountType().equals(TenantUserTypeEnum.TENANT_ADMIN.getCode())) {
-            throw new BusinessException(ErrorCodeEnum.PERMISSION_REQUIRED);
-        }
         // check the record existed
         DataNodeEntity curEntity = dataNodeMapper.selectById(request.getId());
         if (curEntity == null) {
@@ -290,10 +282,6 @@ public class DataNodeServiceImpl implements 
DataNodeService {
 
     @Override
     public Boolean delete(Integer id, UserInfo opInfo) {
-        // only the person in charges can query
-        if 
(!opInfo.getAccountType().equals(TenantUserTypeEnum.TENANT_ADMIN.getCode())) {
-            throw new BusinessException(ErrorCodeEnum.PERMISSION_REQUIRED);
-        }
         DataNodeEntity entity = dataNodeMapper.selectById(id);
         Preconditions.expectNotNull(entity, ErrorCodeEnum.DATA_NODE_NOT_FOUND,
                 ErrorCodeEnum.DATA_NODE_NOT_FOUND.getMessage());
diff --git 
a/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/openapi/OpenDataNodeController.java
 
b/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/openapi/OpenDataNodeController.java
index 833580edc3..e42da8452a 100644
--- 
a/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/openapi/OpenDataNodeController.java
+++ 
b/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/openapi/OpenDataNodeController.java
@@ -27,12 +27,15 @@ import org.apache.inlong.manager.pojo.node.DataNodeInfo;
 import org.apache.inlong.manager.pojo.node.DataNodePageRequest;
 import org.apache.inlong.manager.pojo.node.DataNodeRequest;
 import org.apache.inlong.manager.pojo.user.LoginUserUtils;
+import org.apache.inlong.manager.pojo.user.UserRoleCode;
 import org.apache.inlong.manager.service.node.DataNodeService;
 import org.apache.inlong.manager.service.operationlog.OperationLog;
 
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiOperation;
+import org.apache.shiro.authz.annotation.Logical;
+import org.apache.shiro.authz.annotation.RequiresRoles;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.DeleteMapping;
@@ -76,6 +79,7 @@ public class OpenDataNodeController {
     @PostMapping(value = "/node/save")
     @ApiOperation(value = "Save node")
     @OperationLog(operation = OperationType.CREATE)
+    @RequiresRoles(logical = Logical.OR, value = {UserRoleCode.TENANT_ADMIN, 
UserRoleCode.INLONG_ADMIN})
     public Response<Integer> save(@Validated(SaveValidation.class) 
@RequestBody DataNodeRequest request) {
         Preconditions.expectNotNull(request, ErrorCodeEnum.INVALID_PARAMETER, 
"request cannot be null");
         Preconditions.expectNotNull(LoginUserUtils.getLoginUser(), 
ErrorCodeEnum.LOGIN_USER_EMPTY);
@@ -85,6 +89,7 @@ public class OpenDataNodeController {
     @PostMapping(value = "/node/update")
     @ApiOperation(value = "Update data node")
     @OperationLog(operation = OperationType.UPDATE)
+    @RequiresRoles(logical = Logical.OR, value = {UserRoleCode.TENANT_ADMIN, 
UserRoleCode.INLONG_ADMIN})
     public Response<Boolean> update(@Validated(UpdateByIdValidation.class) 
@RequestBody DataNodeRequest request) {
         Preconditions.expectNotNull(request, ErrorCodeEnum.REQUEST_IS_EMPTY);
         Preconditions.expectNotNull(LoginUserUtils.getLoginUser(), 
ErrorCodeEnum.LOGIN_USER_EMPTY);
@@ -95,6 +100,7 @@ public class OpenDataNodeController {
     @ApiOperation(value = "Delete data node by id")
     @OperationLog(operation = OperationType.DELETE)
     @ApiImplicitParam(name = "id", value = "Data node ID", dataTypeClass = 
Integer.class, required = true)
+    @RequiresRoles(logical = Logical.OR, value = {UserRoleCode.TENANT_ADMIN, 
UserRoleCode.INLONG_ADMIN})
     public Response<Boolean> delete(@PathVariable Integer id) {
         Preconditions.expectNotNull(id, ErrorCodeEnum.INVALID_PARAMETER, "data 
node id cannot be null");
         Preconditions.expectNotNull(LoginUserUtils.getLoginUser(), 
ErrorCodeEnum.LOGIN_USER_EMPTY);

Reply via email to