mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-13 05:39:33 +00:00
fix typo and cleanup
This commit is contained in:
parent
2e15f87f6e
commit
c86f04a50a
1 changed files with 7 additions and 9 deletions
|
|
@ -69,13 +69,11 @@ final class PartsTableActionHandler
|
|||
*/
|
||||
public function handleAction(string $action, array $selected_parts, ?string $target_id, ?string $redirect_url = null, array &$errors = []): ?RedirectResponse
|
||||
{
|
||||
// sanitize target_id
|
||||
if (!str_contains($action, 'tag') && $target_id !== null)
|
||||
{
|
||||
if (!is_numeric($target_id)
|
||||
// validate target_id
|
||||
if (!str_contains($action, 'tag') && $target_id !== null && !is_numeric($target_id))
|
||||
throw new InvalidArgumentException('$target_id must be an integer for action'. $action.'!');
|
||||
}
|
||||
|
||||
|
||||
if ($action === 'add_to_project') {
|
||||
return new RedirectResponse(
|
||||
$this->urlGenerator->generate('project_add_parts', [
|
||||
|
|
@ -145,10 +143,10 @@ implode(',', array_map(static fn (PartLot $lot) => $lot->getID(), $part->getPart
|
|||
break;
|
||||
case "remove_tag":
|
||||
$this->denyAccessUnlessGranted('edit', $part);
|
||||
// remove tag at start or end
|
||||
$tags = preg_replace("/(^".$target_id.",|,".$target_id."$)/", '', $part->getTags());
|
||||
// remove tag in the middle, retaining one comma
|
||||
$tags = str_replace(','.$target_id.',', ',' $tags);
|
||||
// remove any matching tag at start or end
|
||||
$tags = preg_replace('/(^'.$target_id.',|,'.$target_id.'$)/', '', $part->getTags());
|
||||
// remove any matching tags in the middle, retaining one comma, and commit
|
||||
$part->setTags(str_replace(','.$target_id.',', ',' $tags);
|
||||
break;
|
||||
case 'favorite':
|
||||
$this->denyAccessUnlessGranted('change_favorite', $part);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue