Skip to content
Snippets Groups Projects
Commit 47938bba authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FEAT #12471 TIME 0:15 prevent setting tag as parent or its children as parent

parent 062a67ae
No related branches found
No related tags found
No related merge requests found
......@@ -175,6 +175,20 @@ class TagController
return $response->withStatus(400)->withJson(['errors' => 'Parent tag does not exist']);
}
$parent = $parent['id'];
if ($parent == $args['id']) {
return $response->withStatus(400)->withJson(['errors' => 'Tag cannot be its own parent']);
}
$children = TagModel::get([
'select' => ['id'],
'where' => ['parent_id = ?'],
'data' => [$args['id']]
]);
$children = array_column($children, 'id');
if (in_array($parent, $children)) {
return $response->withStatus(400)->withJson(['errors' => 'Parent tag cannot also be a children']);
}
}
TagModel::update([
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment