From fa0af2031fef358563eaeddf4e91a9ca819d9c86 Mon Sep 17 00:00:00 2001 From: jefftlin Date: Thu, 12 Sep 2024 21:33:06 +0800 Subject: [PATCH] Delete user group when delete project --- .../ExchangisDataSourceModelController.java | 22 ++++++++++++++++--- .../service/impl/ProjectServiceImpl.java | 6 ++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/exchangis-datasource/exchangis-datasource-server/src/main/java/com/webank/wedatasphere/exchangis/datasource/server/restful/api/ExchangisDataSourceModelController.java b/exchangis-datasource/exchangis-datasource-server/src/main/java/com/webank/wedatasphere/exchangis/datasource/server/restful/api/ExchangisDataSourceModelController.java index 50f8fbf41..ca5214e93 100644 --- a/exchangis-datasource/exchangis-datasource-server/src/main/java/com/webank/wedatasphere/exchangis/datasource/server/restful/api/ExchangisDataSourceModelController.java +++ b/exchangis-datasource/exchangis-datasource-server/src/main/java/com/webank/wedatasphere/exchangis/datasource/server/restful/api/ExchangisDataSourceModelController.java @@ -72,6 +72,7 @@ public Message add(@Valid @RequestBody DataSourceModel model, HttpServletRequest @RequestMapping(value = "/{id}", method = RequestMethod.PUT) public Message update(@PathVariable Long id, @Valid @RequestBody DataSourceModel model, HttpServletRequest request) { + String username = UserUtils.getLoginUser(request); if (id <= 0) { Message.error("Error dataSource model"); } @@ -81,12 +82,17 @@ public Message update(@PathVariable Long id, @Valid @RequestBody DataSourceModel if (StringUtils.isBlank(model.getModifyUser())) { model.setModifyUser(operator); } - // TODO authority ? - // TODO model name unique ? try { // Check if the parameter is updated? DataSourceModel before = this.dataSourceModelService.get(id); - // TODO check if not exists ? + if (Objects.isNull(before)) { + Message.error("The model is not exist, please check it"); + } + if (!GlobalConfiguration.isAdminUser(username) && + !StringUtils.equals(username, before.getCreateUser())) { + String msg = String.format("User %s has no permission to operate it!", username); + return Message.error(msg); + } if (Objects.equals(before.getParameter(), model.getParameter())){ dataSourceModelService.update(model); } else { @@ -129,10 +135,20 @@ public Message update(@PathVariable Long id, @Valid @RequestBody DataSourceModel @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) public Message delete(@PathVariable Long id, HttpServletRequest request) { + String username = UserUtils.getLoginUser(request); DataSourceModelQuery query = new DataSourceModelQuery(); query.setModelId(id); boolean result = false; try { + DataSourceModel before = this.dataSourceModelService.get(id); + if (Objects.isNull(before)) { + Message.error("The model is not exist, please check it"); + } + if (!GlobalConfiguration.isAdminUser(username) && + !StringUtils.equals(username, before.getCreateUser())) { + String msg = String.format("User %s has no permission to operate it!", username); + return Message.error(msg); + } result = dataSourceModelService.delete(id); } catch (DataSourceModelOperateException | RateLimitOperationException e) { return Message.error("Failed to delete the dataSource model, cause by : " + e.getMessage()); diff --git a/exchangis-project/exchangis-project-server/src/main/java/com/webank/wedatasphere/exchangis/project/server/service/impl/ProjectServiceImpl.java b/exchangis-project/exchangis-project-server/src/main/java/com/webank/wedatasphere/exchangis/project/server/service/impl/ProjectServiceImpl.java index f997d58fc..6a287acef 100644 --- a/exchangis-project/exchangis-project-server/src/main/java/com/webank/wedatasphere/exchangis/project/server/service/impl/ProjectServiceImpl.java +++ b/exchangis-project/exchangis-project-server/src/main/java/com/webank/wedatasphere/exchangis/project/server/service/impl/ProjectServiceImpl.java @@ -309,7 +309,11 @@ public void deleteProject(Long projectId) throws ExchangisJobException { public void deleteProjectByName(String name) throws ExchangisJobException { // First to delete the project to lock the record ExchangisProject project = this.projectMapper.selectByName(name); - this.projectMapper.deleteByName(name); + // Delete project and user group + if (Objects.nonNull(project)) { + this.projectMapper.deleteByName(name); + this.projectDsRelationMapper.deleteByProject(project.getId()); + } } @Override public ExchangisProjectInfo getProjectDetailById(Long projectId) {