Skip to content

Commit

Permalink
[Bug] [dinky-web] Task naming rule restrictions.
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhang2.zhang committed Dec 1, 2024
1 parent 0ee8278 commit 8b8bfd4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ public Result<List<TreeVo>> getCatalogueSortType() {
dataTypeClass = CatalogueTaskDTO.class)
@CheckTaskOwner(checkParam = TaskId.class, checkInterface = TaskService.class)
public Result<Catalogue> createTask(@RequestBody CatalogueTaskDTO catalogueTaskDTO) {
if (!catalogueService.isValidTaskName(catalogueTaskDTO.getName())) {
return Result.failed(Status.TASK_NAME_INVALID);
}
if (catalogueService.checkCatalogueTaskNameIsExistById(catalogueTaskDTO.getName(), catalogueTaskDTO.getId())) {
return Result.failed(Status.TASK_IS_EXIST);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ public interface CatalogueService extends ISuperService<Catalogue> {
*/
boolean checkCatalogueTaskNameIsExistById(String name, Integer id);

boolean isValidTaskName(String name);

/**
* Check task operate permission.
* Contains reflection invocation. Please do not delete.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -263,6 +265,23 @@ public boolean checkCatalogueTaskNameIsExistById(String name, Integer id) {
.ne(id != null, Catalogue::getId, id));
}

/**
* check catalogue task name is valid
*
* @param taskName taskName
* @return true if valid , otherwise false
*/
@Override
public boolean isValidTaskName(String taskName) {
String TASK_NAME_PATTERN = "^[a-z0-9][a-z0-9.-]*[a-z0-9]$";
Pattern pattern = Pattern.compile(TASK_NAME_PATTERN);
if (StringUtils.isBlank(taskName)) {
return false;
}
Matcher matcher = pattern.matcher(taskName);
return matcher.matches();
}

/**
* init some value
*
Expand Down
4 changes: 4 additions & 0 deletions dinky-common/src/main/java/org/dinky/data/enums/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ public enum Status {
CATALOGUE_NOT_EXIST(12017, "catalogue.not.exist"),
CATALOGUE_IS_EXIST(12018, "catalogue.is.exist"),
TASK_NAME_NOT_MATCH_CATALOGUE_NAME(12019, "task.name.not.match.catalogue.name"),
TASK_NAME_INVALID(
12020,
"The task name must consist of lowercase letters, numbers, '-', or '.', "
+ "and it must start and end with a letter or number."),

/**
* alert instance
Expand Down

0 comments on commit 8b8bfd4

Please sign in to comment.