mirror of
https://github.com/Athou/commafeed.git
synced 2026-11-02 10:24:48 +00:00
prevent moving a category into one of its own descendants (#2355)
This commit is contained in:
@@ -435,6 +435,19 @@ public class CategoryREST {
|
||||
&& !Strings.CS.equals(req.getParentId(), String.valueOf(req.getId()))) {
|
||||
parent = feedCategoryDAO.findById(user, Long.valueOf(req.getParentId()));
|
||||
}
|
||||
if (parent != null) {
|
||||
Long parentId = parent.getId();
|
||||
List<FeedCategory> descendants =
|
||||
feedCategoryDAO.findAllChildrenCategories(user, category);
|
||||
boolean parentIsDescendant =
|
||||
descendants.stream().anyMatch(c -> c.getId().equals(parentId));
|
||||
if (parentIsDescendant) {
|
||||
return Response.status(Status.BAD_REQUEST)
|
||||
.entity(
|
||||
"<message>cannot set a category's own descendant as its parent</message>")
|
||||
.build();
|
||||
}
|
||||
}
|
||||
category.setParent(parent);
|
||||
|
||||
if (req.getPosition() != null) {
|
||||
|
||||
Reference in New Issue
Block a user