From 93149388d3569e2c0b0348163b0786511d7391ef Mon Sep 17 00:00:00 2001 From: benjobs Date: Mon, 12 Aug 2024 14:27:35 +0800 Subject: [PATCH] [Improve] open API minor improvement --- .../console/core/aspect/StreamParkAspect.java | 4 ++-- .../core/controller/FlinkSqlController.java | 2 +- .../core/controller/OpenAPIController.java | 14 ++------------ .../core/service/impl/ProxyServiceImpl.java | 2 +- .../system/controller/MemberController.java | 9 +-------- .../console/system/service/MemberService.java | 4 +--- .../system/service/impl/MemberServiceImpl.java | 17 +---------------- .../src/api/system/member.ts | 11 +---------- 8 files changed, 10 insertions(+), 53 deletions(-) diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/aspect/StreamParkAspect.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/aspect/StreamParkAspect.java index d681e9ea78..40e30dfb19 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/aspect/StreamParkAspect.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/aspect/StreamParkAspect.java @@ -187,7 +187,7 @@ public RestResponse permissionAction(ProceedingJoinPoint joinPoint) throws Throw // 2) check team Long teamId = getId(joinPoint, methodSignature, permissionScope.team()); if (teamId != null) { - Member member = memberService.findByUserName(teamId, currentUser.getUsername()); + Member member = memberService.findByUserId(teamId, currentUser.getUserId()); ApiAlertException.throwIfTrue( member == null, "Permission denied, only members of this team can access this permission"); @@ -199,7 +199,7 @@ public RestResponse permissionAction(ProceedingJoinPoint joinPoint) throws Throw Application app = applicationService.getById(appId); ApiAlertException.throwIfTrue(app == null, "Invalid operation, application is null"); if (!currentUser.getUserId().equals(app.getUserId())) { - Member member = memberService.findByUserName(app.getTeamId(), currentUser.getUsername()); + Member member = memberService.findByUserId(app.getTeamId(), currentUser.getUserId()); ApiAlertException.throwIfTrue( member == null, "Permission denied, this job not created by the current user, And the job cannot be found in the current user's team."); diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/FlinkSqlController.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/FlinkSqlController.java index ee2a18d338..a3586a445c 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/FlinkSqlController.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/FlinkSqlController.java @@ -97,7 +97,7 @@ public RestResponse delete(FlinkSql flinkSql) { } @PostMapping("get") - @PermissionScope(app = "#appId", team = "#teamId") + @PermissionScope(app = "#appId") public RestResponse get(Long appId, Long teamId, String id) throws InternalException { ApiAlertException.throwIfTrue( appId == null || teamId == null, "Permission denied, appId and teamId cannot be null"); diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/OpenAPIController.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/OpenAPIController.java index 235a1c0193..ab4de4af3c 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/OpenAPIController.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/OpenAPIController.java @@ -61,11 +61,6 @@ public class OpenAPIController { required = true, type = Long.class, bindFor = "appId"), - @OpenAPI.Param( - name = "teamId", - description = "current user teamId", - required = true, - type = Long.class), @OpenAPI.Param( name = "argument", description = "flink program run argument", @@ -91,7 +86,7 @@ public class OpenAPIController { type = Boolean.class, defaultValue = "false"), }) - @PermissionScope(app = "#app.appId", team = "#app.teamId") + @PermissionScope(app = "#app.appId") @PostMapping("app/start") @RequiresPermissions("app:start") public RestResponse flinkStart(Application app) throws Exception { @@ -115,11 +110,6 @@ public RestResponse flinkStart(Application app) throws Exception { required = true, type = Long.class, bindFor = "appId"), - @OpenAPI.Param( - name = "teamId", - description = "current user teamId", - required = true, - type = Long.class), @OpenAPI.Param( name = "triggerSavepoint", description = "trigger savepoint before taking stopping", @@ -139,7 +129,7 @@ public RestResponse flinkStart(Application app) throws Exception { type = Boolean.class, defaultValue = "false"), }) - @PermissionScope(app = "#app.appId", team = "#app.teamId") + @PermissionScope(app = "#app.appId") @PostMapping("app/cancel") @RequiresPermissions("app:cancel") public RestResponse flinkCancel(Application app) throws Exception { diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProxyServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProxyServiceImpl.java index 93a929673b..bc6d712e71 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProxyServiceImpl.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ProxyServiceImpl.java @@ -99,7 +99,7 @@ public ResponseEntity proxyFlinkUI(HttpServletRequest request, Long appId) th return builder.body("Invalid operation, appId is invalid."); } if (!currentUser.getUserId().equals(app.getUserId())) { - Member member = memberService.findByUserName(app.getTeamId(), currentUser.getUsername()); + Member member = memberService.findByUserId(app.getTeamId(), currentUser.getUserId()); if (member == null) { return builder.body( "Permission denied, this job not created by the current user, And the job cannot be found in the current user's team."); diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/MemberController.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/MemberController.java index 6ef6bf654c..140d058603 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/MemberController.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/MemberController.java @@ -38,7 +38,6 @@ import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid; -import javax.validation.constraints.NotBlank; import java.util.List; @@ -57,7 +56,7 @@ public RestResponse memberList(RestRequest restRequest, Member member) { return RestResponse.success(userList); } - @PostMapping("candidateUsers") + @PostMapping("candidate_users") @RequiresPermissions("member:add") public RestResponse candidateUsers(Long teamId) { List userList = memberService.findCandidateUsers(teamId); @@ -70,12 +69,6 @@ public RestResponse listTeams(Long userId) { return RestResponse.success(teamList); } - @PostMapping("check/user") - public RestResponse check(@NotBlank(message = "{required}") Long teamId, String userName) { - Member result = this.memberService.findByUserName(teamId, userName); - return RestResponse.success(result == null); - } - @PermissionScope(team = "#member.teamId") @PostMapping("post") @RequiresPermissions("member:add") diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/MemberService.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/MemberService.java index d8f06cb5ab..1491b520c5 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/MemberService.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/MemberService.java @@ -29,8 +29,6 @@ public interface MemberService extends IService { - void deleteByRoleIds(String[] roleIds); - void deleteByUserId(Long userId); void deleteByTeamId(Long teamId); @@ -41,7 +39,7 @@ public interface MemberService extends IService { List findUserTeams(Long userId); - Member findByUserName(Long teamId, String userName); + Member findByUserId(Long teamId, Long userId); List findUserIdsByRoleId(Long roleId); diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/MemberServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/MemberServiceImpl.java index ad0b542b3a..3e95f7e5ed 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/MemberServiceImpl.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/MemberServiceImpl.java @@ -41,7 +41,6 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; -import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Optional; @@ -58,12 +57,6 @@ public class MemberServiceImpl extends ServiceImpl impleme @Autowired private TeamService teamService; @Autowired private ServiceHelper serviceHelper; - @Override - @Transactional - public void deleteByRoleIds(String[] roleIds) { - Arrays.stream(roleIds).forEach(id -> baseMapper.deleteByRoleId(Long.valueOf(id))); - } - @Override @Transactional public void deleteByUserId(Long userId) { @@ -95,15 +88,7 @@ public List findUserTeams(Long userId) { } @Override - public Member findByUserName(Long teamId, String userName) { - User user = userService.findByName(userName); - if (user == null) { - return null; - } - return findByUserId(teamId, user.getUserId()); - } - - private Member findByUserId(Long teamId, Long userId) { + public Member findByUserId(Long teamId, Long userId) { ApiAlertException.throwIfNull(teamId, "The team id is required."); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() diff --git a/streampark-console/streampark-console-webapp/src/api/system/member.ts b/streampark-console/streampark-console-webapp/src/api/system/member.ts index 9cb2dd7c21..821b480d6f 100644 --- a/streampark-console/streampark-console-webapp/src/api/system/member.ts +++ b/streampark-console/streampark-console-webapp/src/api/system/member.ts @@ -26,9 +26,8 @@ enum MEMBER_API { UPDATE = '/member/update', LIST = '/member/list', TEAMS = '/member/teams', - CHECK_NAME = '/user/check/name', DELETE = '/member/delete', - CANDIDATE_USERS = '/member/candidateUsers', + CANDIDATE_USERS = '/member/candidate_users', } /** @@ -78,14 +77,6 @@ export function fetchUserTeam(data: { }): Promise> { return defHttp.post({ url: MEMBER_API.TEAMS, data }); } -/** - * name check - * @param {Object} data username - * @returns {Promise} - */ -export function fetchCheckUserName(data: { username: string }): Promise { - return defHttp.post({ url: MEMBER_API.CHECK_NAME, data }); -} /** * delete