Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] [dinky-web] Task naming rule restrictions. #3991

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,13 @@ public interface CatalogueService extends ISuperService<Catalogue> {
*/
boolean checkCatalogueTaskNameIsExistById(String name, Integer id);

/**
* Check if the catalogue task name is valid
* @param name catalogue task name
* @return true if the catalogue task name is valid
*/
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
Loading