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

healchow 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 6af10aeef1 [INLONG-8394][Manager] Support fuzzy match for the 
TenantRole list interface (#8395)
6af10aeef1 is described below

commit 6af10aeef1ebed72cd5329cbc1d5ed85bab5615f
Author: vernedeng <[email protected]>
AuthorDate: Mon Jul 3 16:47:49 2023 +0800

    [INLONG-8394][Manager] Support fuzzy match for the TenantRole list 
interface (#8395)
---
 .../apache/inlong/manager/common/enums/TenantUserTypeEnum.java   | 4 ++--
 .../src/main/resources/mappers/TenantUserRoleEntityMapper.xml    | 6 ++++--
 .../apache/inlong/manager/pojo/user/TenantRolePageRequest.java   | 4 ++--
 .../inlong/manager/service/user/TenantRoleServiceTest.java       | 2 +-
 .../inlong/manager/web/controller/InlongRoleController.java      | 4 +++-
 .../inlong/manager/web/controller/InlongTenantController.java    | 9 +++++++++
 .../manager/web/controller/InlongTenantRoleController.java       | 7 ++++---
 7 files changed, 25 insertions(+), 11 deletions(-)

diff --git 
a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/enums/TenantUserTypeEnum.java
 
b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/enums/TenantUserTypeEnum.java
index 97bd836b32..89c4d1782e 100644
--- 
a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/enums/TenantUserTypeEnum.java
+++ 
b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/enums/TenantUserTypeEnum.java
@@ -30,11 +30,11 @@ import java.util.stream.Collectors;
 public enum TenantUserTypeEnum implements IntListValuable {
 
     /**
-     * Has all privilege
+     * Has all privilege of specific tenant
      */
     TENANT_ADMIN(0),
     /**
-     * No privilege to manage the system
+     * No privilege to do update/save/delete
      */
     TENANT_OPERATOR(1),
     ;
diff --git 
a/inlong-manager/manager-dao/src/main/resources/mappers/TenantUserRoleEntityMapper.xml
 
b/inlong-manager/manager-dao/src/main/resources/mappers/TenantUserRoleEntityMapper.xml
index 9cee1fe945..d9d3fbbcc0 100644
--- 
a/inlong-manager/manager-dao/src/main/resources/mappers/TenantUserRoleEntityMapper.xml
+++ 
b/inlong-manager/manager-dao/src/main/resources/mappers/TenantUserRoleEntityMapper.xml
@@ -64,8 +64,10 @@
         <if test="roleCode != null and roleCode != ''">
             and role_code = #{roleCode,jdbcType=VARCHAR}
         </if>
-        <if test="tenant != null and tenant != ''">
-            and tenant = #{tenant, jdbcType=VARCHAR}
+        <if test="keyword != null and keyword != ''">
+            and (
+            tenant like CONCAT('%', #{keyword}, '%')
+            )
         </if>
         <if test="disabled != null">
             and disabled = #{disabled, jdbcType=SMALLINT}
diff --git 
a/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/user/TenantRolePageRequest.java
 
b/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/user/TenantRolePageRequest.java
index cb980b3520..fb3176247a 100644
--- 
a/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/user/TenantRolePageRequest.java
+++ 
b/inlong-manager/manager-pojo/src/main/java/org/apache/inlong/manager/pojo/user/TenantRolePageRequest.java
@@ -38,8 +38,8 @@ public class TenantRolePageRequest extends PageRequest {
     @ApiModelProperty(value = "Role code")
     private String roleCode;
 
-    @ApiModelProperty(value = "Tenant")
-    private String tenant;
+    @ApiModelProperty(value = "keyword of tenant")
+    private String keyword;
 
     @ApiModelProperty(value = "If disabled")
     private Integer disabled;
diff --git 
a/inlong-manager/manager-service/src/test/java/org/apache/inlong/manager/service/user/TenantRoleServiceTest.java
 
b/inlong-manager/manager-service/src/test/java/org/apache/inlong/manager/service/user/TenantRoleServiceTest.java
index ee38eece31..2c6c25d995 100644
--- 
a/inlong-manager/manager-service/src/test/java/org/apache/inlong/manager/service/user/TenantRoleServiceTest.java
+++ 
b/inlong-manager/manager-service/src/test/java/org/apache/inlong/manager/service/user/TenantRoleServiceTest.java
@@ -105,7 +105,7 @@ public class TenantRoleServiceTest extends ServiceBaseTest {
             service.save(request, LoginUserUtils.getLoginUser().getName());
         }
         TenantRolePageRequest pageRequest = new TenantRolePageRequest();
-        pageRequest.setTenant("public");
+        pageRequest.setKeyword("pub");
         PageInfo<TenantRoleInfo> infos = service.listByCondition(pageRequest);
         Assertions.assertEquals(max, infos.getSize());
     }
diff --git 
a/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongRoleController.java
 
b/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongRoleController.java
index a764935b89..dc8ea9fe7e 100644
--- 
a/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongRoleController.java
+++ 
b/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongRoleController.java
@@ -31,6 +31,7 @@ import com.github.pagehelper.PageInfo;
 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;
@@ -50,7 +51,7 @@ public class InlongRoleController {
 
     @RequestMapping(value = "/role/inlong/get/{id}", method = 
RequestMethod.GET)
     @ApiOperation(value = "Get inlong role by ID")
-    @RequiresRoles(value = UserRoleCode.INLONG_ADMIN)
+    @RequiresRoles(logical = Logical.OR, value = {UserRoleCode.INLONG_ADMIN, 
UserRoleCode.INLONG_OPERATOR})
     @ApiImplicitParam(name = "id", dataTypeClass = Integer.class, required = 
true)
     public Response<InlongRoleInfo> get(@PathVariable int id) {
         return Response.success(inlongRoleService.get(id));
@@ -76,6 +77,7 @@ public class InlongRoleController {
 
     @RequestMapping(value = "/role/inlong/list", method = RequestMethod.POST)
     @ApiOperation(value = "List inlong roles by paginating")
+    @RequiresRoles(logical = Logical.OR, value = {UserRoleCode.INLONG_ADMIN, 
UserRoleCode.INLONG_OPERATOR})
     public Response<PageInfo<InlongRoleInfo>> listByCondition(@RequestBody 
InlongRolePageRequest request) {
         return Response.success(inlongRoleService.listByCondition(request));
     }
diff --git 
a/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongTenantController.java
 
b/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongTenantController.java
index e844e70b1a..c5dc2e42b2 100644
--- 
a/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongTenantController.java
+++ 
b/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongTenantController.java
@@ -30,6 +30,8 @@ import 
org.apache.inlong.manager.service.tenant.InlongTenantService;
 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.PathVariable;
@@ -38,6 +40,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
+import static org.apache.inlong.manager.pojo.user.UserRoleCode.INLONG_ADMIN;
+import static org.apache.inlong.manager.pojo.user.UserRoleCode.INLONG_OPERATOR;
+
 @RestController
 @RequestMapping("/api")
 @Api(tags = "Tenant-API")
@@ -49,6 +54,7 @@ public class InlongTenantController {
     @RequestMapping(value = "/tenant/get/{name}", method = RequestMethod.GET)
     @ApiOperation(value = "Get inlong tenant by name")
     @ApiImplicitParam(name = "name", dataTypeClass = String.class, required = 
true)
+    @RequiresRoles(logical = Logical.OR, value = {INLONG_ADMIN, 
INLONG_OPERATOR})
     public Response<InlongTenantInfo> get(@PathVariable String name) {
         return Response.success(tenantService.getByName(name));
     }
@@ -56,12 +62,14 @@ public class InlongTenantController {
     @RequestMapping(value = "/tenant/save", method = RequestMethod.POST)
     @OperationLog(operation = OperationType.CREATE)
     @ApiOperation(value = "Save inlong tenant")
+    @RequiresRoles(logical = Logical.OR, value = {INLONG_ADMIN})
     public Response<Integer> save(@Validated @RequestBody InlongTenantRequest 
request) {
         return Response.success(tenantService.save(request));
     }
 
     @RequestMapping(value = "/tenant/list", method = RequestMethod.POST)
     @ApiOperation(value = "List tenant by paginating")
+    @RequiresRoles(logical = Logical.OR, value = {INLONG_ADMIN, 
INLONG_OPERATOR})
     public Response<PageResult<InlongTenantInfo>> listByCondition(@RequestBody 
InlongTenantPageRequest request) {
         return Response.success(tenantService.listByCondition(request));
     }
@@ -69,6 +77,7 @@ public class InlongTenantController {
     @RequestMapping(value = "/tenant/update", method = RequestMethod.POST)
     @OperationLog(operation = OperationType.UPDATE)
     @ApiOperation(value = "Update inlong tenant")
+    @RequiresRoles(logical = Logical.OR, value = {INLONG_ADMIN})
     public Response<Boolean> update(@Validated(UpdateByIdValidation.class) 
@RequestBody InlongTenantRequest request) {
         return Response.success(tenantService.update(request));
     }
diff --git 
a/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongTenantRoleController.java
 
b/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongTenantRoleController.java
index 4974e8daeb..020d8721e0 100644
--- 
a/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongTenantRoleController.java
+++ 
b/inlong-manager/manager-web/src/main/java/org/apache/inlong/manager/web/controller/InlongTenantRoleController.java
@@ -31,6 +31,7 @@ import com.github.pagehelper.PageInfo;
 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;
@@ -51,7 +52,7 @@ public class InlongTenantRoleController {
     @RequestMapping(value = "/role/tenant/get/{id}", method = 
RequestMethod.GET)
     @ApiOperation(value = "Get tenant role by ID")
     @ApiImplicitParam(name = "id", dataTypeClass = Integer.class, required = 
true)
-    @RequiresRoles(value = UserRoleCode.TENANT_ADMIN)
+    @RequiresRoles(logical = Logical.OR, value = {UserRoleCode.TENANT_ADMIN, 
UserRoleCode.TENANT_OPERATOR})
     public Response<TenantRoleInfo> get(@PathVariable int id) {
         return Response.success(tenantRoleService.get(id));
     }
@@ -59,7 +60,7 @@ public class InlongTenantRoleController {
     @RequestMapping(value = "/role/tenant/save", method = RequestMethod.POST)
     @OperationLog(operation = OperationType.CREATE)
     @ApiOperation(value = "Save tenant role")
-    @RequiresRoles(value = UserRoleCode.TENANT_ADMIN)
+    @RequiresRoles(logical = Logical.OR, value = {UserRoleCode.TENANT_ADMIN, 
UserRoleCode.INLONG_ADMIN})
     public Response<Integer> save(@Validated @RequestBody TenantRoleRequest 
request) {
         String operator = LoginUserUtils.getLoginUser().getName();
         return Response.success(tenantRoleService.save(request, operator));
@@ -68,7 +69,7 @@ public class InlongTenantRoleController {
     @RequestMapping(value = "/role/tenant/update", method = RequestMethod.POST)
     @OperationLog(operation = OperationType.CREATE)
     @ApiOperation(value = "Update tenant role")
-    @RequiresRoles(value = UserRoleCode.TENANT_ADMIN)
+    @RequiresRoles(logical = Logical.OR, value = {UserRoleCode.TENANT_ADMIN, 
UserRoleCode.INLONG_ADMIN})
     public Response<Boolean> update(@Validated @RequestBody TenantRoleRequest 
request) {
         String operator = LoginUserUtils.getLoginUser().getName();
         return Response.success(tenantRoleService.update(request, operator));

Reply via email to