From 5b16c10960469f7e1bfb3b0d0df67feab2241ffa Mon Sep 17 00:00:00 2001 From: hechao Date: Fri, 9 Aug 2024 10:21:37 +0800 Subject: [PATCH 1/3] set default team member --- .../streampark/console/base/domain/Constant.java | 2 ++ .../console/system/service/RoleService.java | 6 ++++++ .../system/service/impl/RoleServiceImpl.java | 5 +++++ .../system/service/impl/UserServiceImpl.java | 14 ++++++++++++++ 4 files changed, 27 insertions(+) diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/Constant.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/Constant.java index 03a211c640..2231f7062a 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/Constant.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/domain/Constant.java @@ -32,4 +32,6 @@ public class Constant { public static final String APP_DETAIL_MENU_ID = "100018"; public static final Long DEFAULT_TEAM_ID = 100000L; + + public static final Long DEFAULT_ROLE_ID = 100001L; } diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/RoleService.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/RoleService.java index 0a9e5f3316..1ad8eca0b0 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/RoleService.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/RoleService.java @@ -62,4 +62,10 @@ public interface RoleService extends IService { * @param role Role */ void updateRole(Role role); + + /** + * Get the Default Role + * + */ + Role getSysDefaultRole(); } diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/RoleServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/RoleServiceImpl.java index d4c2af83bd..659777d4cb 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/RoleServiceImpl.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/RoleServiceImpl.java @@ -123,4 +123,9 @@ private void updateRoleMenus(Role role, String[] menuIds) { } roleMenuService.saveBatch(roleMenus); } + + @Override + public Role getSysDefaultRole() { + return baseMapper.selectOne(new LambdaQueryWrapper().eq(Role::getRoleId, Constant.DEFAULT_ROLE_ID)); + } } diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/UserServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/UserServiceImpl.java index 3e03e23d43..d5c6542641 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/UserServiceImpl.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/UserServiceImpl.java @@ -31,10 +31,13 @@ import org.apache.streampark.console.core.service.application.ApplicationManageService; import org.apache.streampark.console.system.authentication.JWTToken; import org.apache.streampark.console.system.authentication.JWTUtil; +import org.apache.streampark.console.system.entity.Member; +import org.apache.streampark.console.system.entity.Role; import org.apache.streampark.console.system.entity.User; import org.apache.streampark.console.system.mapper.UserMapper; import org.apache.streampark.console.system.service.MemberService; import org.apache.streampark.console.system.service.MenuService; +import org.apache.streampark.console.system.service.RoleService; import org.apache.streampark.console.system.service.TeamService; import org.apache.streampark.console.system.service.UserService; @@ -85,6 +88,9 @@ public class UserServiceImpl extends ServiceImpl implements Us @Autowired private TeamService teamService; + @Autowired + private RoleService roleService; + @Override public User getByUsername(String username) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper().eq(User::getUsername, username); @@ -121,6 +127,14 @@ public void createUser(User user) { user.setPassword(password); } save(user); + // set team member + Member member = new Member(); + member.setUserName(user.getUsername()); + member.setTeamId(user.getLastTeamId()); + Role role = roleService.getSysDefaultRole(); + member.setRoleId(role.getRoleId()); + member.setRoleName(role.getRoleName()); + memberService.createMember(member); } @Override From 7b371e6d472588f98b607544516423996328fda5 Mon Sep 17 00:00:00 2001 From: hechao Date: Fri, 9 Aug 2024 11:39:43 +0800 Subject: [PATCH 2/3] getTeamId from teamService --- .../streampark/console/system/service/impl/UserServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/UserServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/UserServiceImpl.java index d5c6542641..471cbbb1c8 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/UserServiceImpl.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/service/impl/UserServiceImpl.java @@ -130,7 +130,7 @@ public void createUser(User user) { // set team member Member member = new Member(); member.setUserName(user.getUsername()); - member.setTeamId(user.getLastTeamId()); + member.setTeamId(teamService.getSysDefaultTeam().getId()); Role role = roleService.getSysDefaultRole(); member.setRoleId(role.getRoleId()); member.setRoleName(role.getRoleName()); From b20f47ad781317a115e687ec4ce12ac1a8a8efc7 Mon Sep 17 00:00:00 2001 From: ShawHee Date: Mon, 2 Sep 2024 18:12:47 +0800 Subject: [PATCH 3/3] bugfix: permissionAction check --- .../console/core/aspect/PermissionAspect.java | 15 ++++++++++++++- .../core/controller/ApplicationController.java | 10 +++++----- .../src/api/flink/app.ts | 4 ++-- .../flink/app/components/AppDetail/DetailTab.vue | 2 +- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/aspect/PermissionAspect.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/aspect/PermissionAspect.java index add5f5e012..e7190b0432 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/aspect/PermissionAspect.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/aspect/PermissionAspect.java @@ -40,6 +40,7 @@ import org.springframework.core.DefaultParameterNameDiscoverer; import org.springframework.expression.EvaluationContext; import org.springframework.expression.Expression; +import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.stereotype.Component; @@ -77,7 +78,19 @@ public RestResponse permissionAction(ProceedingJoinPoint joinPoint) throws Throw "Permission denied, operations can only be performed with the permissions of the currently logged-in user."); // 2) check team - Long teamId = getId(joinPoint, methodSignature, permission.team()); + Long teamId = null; + try { + teamId = getId(joinPoint, methodSignature, permission.team()); + } catch (SpelEvaluationException e) { + try { + Long appId = getId(joinPoint, methodSignature, permission.app()); + Application app = applicationManageService.getById(appId); + teamId = app.getTeamId(); + } catch (SpelEvaluationException e1) { + log.error( + "Failed to get teamId from permission annotation, please check the annotation configuration."); + } + } if (teamId != null) { Member member = memberService.getByTeamIdUserName(teamId, currentUser.getUsername()); ApiAlertException.throwIfTrue( diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/ApplicationController.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/ApplicationController.java index 6159063e70..a3b159f9ab 100644 --- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/ApplicationController.java +++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/ApplicationController.java @@ -202,8 +202,8 @@ public RestResponse readConf(Application app) throws IOException { @PostMapping("main") @Permission(app = "#app.id", team = "#app.teamId") - public RestResponse getMain(Application application) { - String mainClass = applicationInfoService.getMain(application); + public RestResponse getMain(Application app) { + String mainClass = applicationInfoService.getMain(app); return RestResponse.success(mainClass); } @@ -215,16 +215,16 @@ public RestResponse backups(ApplicationBackUp backUp, RestRequest request) { } @PostMapping("opt_log") - @Permission(app = "#log.appId", team = "#log.teamId") + @Permission(app = "#applicationLog.appId") public RestResponse log(ApplicationLog applicationLog, RestRequest request) { IPage applicationList = applicationLogService.getPage(applicationLog, request); return RestResponse.success(applicationList); } - @Permission(app = "#log.appId", team = "#log.teamId") + @Permission(app = "#appId") @PostMapping("delete/opt_log") @RequiresPermissions("app:delete") - public RestResponse deleteLog(Long id) { + public RestResponse deleteLog(Long id, Long appId) { Boolean deleted = applicationLogService.removeById(id); return RestResponse.success(deleted); } diff --git a/streampark-console/streampark-console-webapp/src/api/flink/app.ts b/streampark-console/streampark-console-webapp/src/api/flink/app.ts index 1d034b3a39..74eb61d883 100644 --- a/streampark-console/streampark-console-webapp/src/api/flink/app.ts +++ b/streampark-console/streampark-console-webapp/src/api/flink/app.ts @@ -158,8 +158,8 @@ export function fetchOptionLog(data) { return defHttp.post({ url: APP_API.OPTION_LOG, data }); } -export function fetchDeleteOperationLog(id: string) { - return defHttp.post({ url: APP_API.DELETE_LOG, data: { id } }); +export function fetchDeleteOperationLog(appId: string, id: string) { + return defHttp.post({ url: APP_API.DELETE_LOG, data: { appId, id } }); } /** diff --git a/streampark-console/streampark-console-webapp/src/views/flink/app/components/AppDetail/DetailTab.vue b/streampark-console/streampark-console-webapp/src/views/flink/app/components/AppDetail/DetailTab.vue index 0d3300c6a3..97876987f9 100644 --- a/streampark-console/streampark-console-webapp/src/views/flink/app/components/AppDetail/DetailTab.vue +++ b/streampark-console/streampark-console-webapp/src/views/flink/app/components/AppDetail/DetailTab.vue @@ -355,7 +355,7 @@ } async function handleDeleteOperationLog(record: Recordable) { - await fetchDeleteOperationLog(record.id); + await fetchDeleteOperationLog(record.appId, record.id); await reloadOperationLog(); }