Skip to content

Commit

Permalink
Delete user group when delete project
Browse files Browse the repository at this point in the history
  • Loading branch information
jefftlin committed Sep 12, 2024
1 parent 9e041e5 commit fa0af20
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit fa0af20

Please sign in to comment.