Skip to content

Commit

Permalink
Prevent delete all (#55)
Browse files Browse the repository at this point in the history
* Forbid delete all

search parameter must be defined

config :: forbid_delete_all (true)

* Apply fixes from StyleCI

---------

Co-authored-by: StyleCI Bot <bot@styleci.io>
  • Loading branch information
ngaspari and StyleCIBot authored Oct 15, 2024
1 parent 7ee8bfa commit df158f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/asseco-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
4 changes: 4 additions & 0 deletions src/App/Models/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit df158f0

Please sign in to comment.