From 2a2a8a778b67539de2d86dfad4d6496335006167 Mon Sep 17 00:00:00 2001 From: qiaozhanwei Date: Wed, 24 Apr 2019 11:23:03 +0800 Subject: [PATCH 1/3] api token update --- .../api/service/AccessTokenService.java | 17 +++++++++-------- .../dao/mapper/AccessTokenMapper.java | 6 ++++-- .../dao/mapper/AccessTokenMapperProvider.java | 6 ++++++ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/escheduler-api/src/main/java/cn/escheduler/api/service/AccessTokenService.java b/escheduler-api/src/main/java/cn/escheduler/api/service/AccessTokenService.java index 4adde8ad60..df7990149a 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/service/AccessTokenService.java +++ b/escheduler-api/src/main/java/cn/escheduler/api/service/AccessTokenService.java @@ -58,15 +58,16 @@ public class AccessTokenService extends BaseService { public Map queryAccessTokenList(User loginUser, String searchVal, Integer pageNo, Integer pageSize) { Map result = new HashMap<>(5); - if (check(result, !isAdmin(loginUser), Status.USER_NO_OPERATION_PERM, Constants.STATUS)) { - return result; - } - - Integer count = accessTokenMapper.countAccessTokenPaging(searchVal); - PageInfo pageInfo = new PageInfo<>(pageNo, pageSize); - - List accessTokenList = accessTokenMapper.queryAccessTokenPaging(searchVal, pageInfo.getStart(), pageSize); + Integer count; + List accessTokenList; + if (loginUser.getUserType() == UserType.ADMIN_USER){ + count = accessTokenMapper.countAccessTokenPaging(0,searchVal); + accessTokenList = accessTokenMapper.queryAccessTokenPaging(0,searchVal, pageInfo.getStart(), pageSize); + }else { + count = accessTokenMapper.countAccessTokenPaging(loginUser.getId(),searchVal); + accessTokenList = accessTokenMapper.queryAccessTokenPaging(loginUser.getId(),searchVal, pageInfo.getStart(), pageSize); + } pageInfo.setTotalCount(count); pageInfo.setLists(accessTokenList); diff --git a/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/AccessTokenMapper.java b/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/AccessTokenMapper.java index aa196561b5..a9a17b8b7d 100644 --- a/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/AccessTokenMapper.java +++ b/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/AccessTokenMapper.java @@ -74,7 +74,8 @@ public interface AccessTokenMapper { @Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE) }) @SelectProvider(type = AccessTokenMapperProvider.class, method = "queryAccessTokenPaging") - List queryAccessTokenPaging(@Param("searchVal") String searchVal, + List queryAccessTokenPaging(@Param("userId") Integer userId, + @Param("searchVal") String searchVal, @Param("offset") Integer offset, @Param("pageSize") Integer pageSize); @@ -84,5 +85,6 @@ public interface AccessTokenMapper { * @return */ @SelectProvider(type = AccessTokenMapperProvider.class, method = "countAccessTokenPaging") - Integer countAccessTokenPaging(@Param("searchVal") String searchVal); + Integer countAccessTokenPaging(@Param("userId") Integer userId + ,@Param("searchVal") String searchVal); } diff --git a/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/AccessTokenMapperProvider.java b/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/AccessTokenMapperProvider.java index 2e4f92f79b..7aa8e61b70 100644 --- a/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/AccessTokenMapperProvider.java +++ b/escheduler-dao/src/main/java/cn/escheduler/dao/mapper/AccessTokenMapperProvider.java @@ -97,6 +97,9 @@ public class AccessTokenMapperProvider { FROM(TABLE_NAME + " t,t_escheduler_user u"); Object searchVal = parameter.get("searchVal"); WHERE("u.id = t.user_id"); + if(parameter.get("userId") != null && (int)parameter.get("userId") != 0){ + WHERE(" u.id = #{userId}"); + } if(searchVal != null && StringUtils.isNotEmpty(searchVal.toString())){ WHERE(" u.user_name like concat('%', #{searchVal}, '%')"); } @@ -115,6 +118,9 @@ public class AccessTokenMapperProvider { FROM(TABLE_NAME + " t,t_escheduler_user u"); Object searchVal = parameter.get("searchVal"); WHERE("u.id = t.user_id"); + if(parameter.get("userId") != null && (int)parameter.get("userId") != 0){ + WHERE(" u.id = #{userId}"); + } if(searchVal != null && StringUtils.isNotEmpty(searchVal.toString())){ WHERE(" u.user_name like concat('%', #{searchVal}, '%') "); } From 07c5df928e21a48a2383b4a5a5860ae309732c11 Mon Sep 17 00:00:00 2001 From: qiaozhanwei Date: Wed, 24 Apr 2019 11:25:44 +0800 Subject: [PATCH 2/3] api access token update --- .../java/cn/escheduler/dao/mapper/AccessTokenMapperTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/escheduler-dao/src/test/java/cn/escheduler/dao/mapper/AccessTokenMapperTest.java b/escheduler-dao/src/test/java/cn/escheduler/dao/mapper/AccessTokenMapperTest.java index d5dfdcb1ec..7b1be50dfe 100644 --- a/escheduler-dao/src/test/java/cn/escheduler/dao/mapper/AccessTokenMapperTest.java +++ b/escheduler-dao/src/test/java/cn/escheduler/dao/mapper/AccessTokenMapperTest.java @@ -51,10 +51,10 @@ public class AccessTokenMapperTest { @Test public void testListPaging(){ - Integer count = accessTokenMapper.countAccessTokenPaging(""); + Integer count = accessTokenMapper.countAccessTokenPaging(1,""); Assert.assertEquals(count, (Integer) 5); - List accessTokenList = accessTokenMapper.queryAccessTokenPaging("", 0, 2); + List accessTokenList = accessTokenMapper.queryAccessTokenPaging(1,"", 0, 2); Assert.assertEquals(accessTokenList.size(), 5); } From 3a0ca2a93446e31eca9d684ab5f6cb3656ae8dd5 Mon Sep 17 00:00:00 2001 From: qiaozhanwei Date: Wed, 24 Apr 2019 15:47:23 +0800 Subject: [PATCH 3/3] add tenant code check --- .../main/java/cn/escheduler/api/service/TenantService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/escheduler-api/src/main/java/cn/escheduler/api/service/TenantService.java b/escheduler-api/src/main/java/cn/escheduler/api/service/TenantService.java index 8fc49d379a..91b7f7b133 100644 --- a/escheduler-api/src/main/java/cn/escheduler/api/service/TenantService.java +++ b/escheduler-api/src/main/java/cn/escheduler/api/service/TenantService.java @@ -80,6 +80,10 @@ public class TenantService extends BaseService{ Tenant tenant = new Tenant(); Date now = new Date(); + if (!tenantCode.matches("^[0-9a-zA-Z_.]{1,}$") || tenantCode.startsWith("-")){ + putMsg(result, Status.VERIFY_TENANT_CODE_ERROR); + return result; + } tenant.setTenantCode(tenantCode); tenant.setTenantName(tenantName); tenant.setQueueId(queueId);