mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-13 08:17:22 +00:00
Scope bulk delete to current company to prevent cross-company deletion
Filter customer IDs through whereCompany() before passing to deleteCustomers(), ensuring users cannot delete customers belonging to other companies via the bulk delete endpoint.
This commit is contained in:
@@ -92,7 +92,11 @@ class CustomersController extends Controller
|
||||
{
|
||||
$this->authorize('delete multiple customers');
|
||||
|
||||
Customer::deleteCustomers($request->ids);
|
||||
$ids = Customer::whereCompany()
|
||||
->whereIn('id', $request->ids)
|
||||
->pluck('id');
|
||||
|
||||
Customer::deleteCustomers($ids);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
|
||||
@@ -181,3 +181,17 @@ test('cannot update customer from another company', function () {
|
||||
])->assertForbidden();
|
||||
});
|
||||
|
||||
test('cannot bulk delete customer from another company', function () {
|
||||
$otherCompany = Company::factory()->create();
|
||||
$otherCustomer = Customer::factory()->create([
|
||||
'company_id' => $otherCompany->id,
|
||||
]);
|
||||
|
||||
postJson('api/v1/customers/delete', [
|
||||
'ids' => [$otherCustomer->id],
|
||||
])->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('customers', [
|
||||
'id' => $otherCustomer->id,
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user