From df158f06f24f78aa2ba4d5307ca1fd6689bacae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Ga=C5=A1pari=C4=87?= Date: Tue, 15 Oct 2024 13:22:10 +0200 Subject: [PATCH] Prevent delete all (#55) * Forbid delete all search parameter must be defined config :: forbid_delete_all (true) * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot --- config/asseco-search.php | 2 ++ src/App/Models/Search.php | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/config/asseco-search.php b/config/asseco-search.php index 28b5e90..1283246 100644 --- a/config/asseco-search.php +++ b/config/asseco-search.php @@ -72,4 +72,6 @@ * limit is higher, it will automatically be set to this value. Leave the value as null if you don't want to use this feature. */ 'default_limit' => null, + + 'forbid_delete_all' => true, ]; diff --git a/src/App/Models/Search.php b/src/App/Models/Search.php index 47d48f1..45b7674 100644 --- a/src/App/Models/Search.php +++ b/src/App/Models/Search.php @@ -131,6 +131,10 @@ public static function delete(SearchRequest $request, string $modelName): void */ public static function deleteBySearch(array $search, string $modelName): void { + if (config('asseco-search.forbid_delete_all') && empty($search['search'])) { + throw new Exception('Missing search parameter', 400); + } + $model = self::extractModelClass($modelName); $foundModels = $model->jsonSearch($search)->get();