mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-13 06:32:40 +01:00
Add form request for client bulk actions
This commit is contained in:
parent
daa21c19aa
commit
ec1d4392bd
@ -16,6 +16,7 @@ use App\Events\Client\ClientWasUpdated;
|
|||||||
use App\Factory\ClientFactory;
|
use App\Factory\ClientFactory;
|
||||||
use App\Filters\ClientFilters;
|
use App\Filters\ClientFilters;
|
||||||
use App\Http\Requests\Client\AdjustClientLedgerRequest;
|
use App\Http\Requests\Client\AdjustClientLedgerRequest;
|
||||||
|
use App\Http\Requests\Client\BulkClientRequest;
|
||||||
use App\Http\Requests\Client\CreateClientRequest;
|
use App\Http\Requests\Client\CreateClientRequest;
|
||||||
use App\Http\Requests\Client\DestroyClientRequest;
|
use App\Http\Requests\Client\DestroyClientRequest;
|
||||||
use App\Http\Requests\Client\EditClientRequest;
|
use App\Http\Requests\Client\EditClientRequest;
|
||||||
@ -494,16 +495,12 @@ class ClientController extends BaseController
|
|||||||
* ),
|
* ),
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
public function bulk()
|
public function bulk(BulkClientRequest $request)
|
||||||
{
|
{
|
||||||
$action = request()->input('action');
|
|
||||||
|
|
||||||
$ids = request()->input('ids');
|
$ids = request()->input('ids');
|
||||||
$clients = Client::withTrashed()->whereIn('id', $this->transformKeys($ids))->cursor();
|
$clients = Client::withTrashed()->whereIn('id', $this->transformKeys($ids))->cursor();
|
||||||
|
$action = $request->action;
|
||||||
if (! in_array($action, ['restore', 'archive', 'delete'])) {
|
|
||||||
return response()->json(['message' => 'That action is not available.'], 400);
|
|
||||||
}
|
|
||||||
|
|
||||||
$clients->each(function ($client, $key) use ($action) {
|
$clients->each(function ($client, $key) use ($action) {
|
||||||
if (auth()->user()->can('edit', $client)) {
|
if (auth()->user()->can('edit', $client)) {
|
||||||
|
37
app/Http/Requests/Client/BulkClientRequest.php
Normal file
37
app/Http/Requests/Client/BulkClientRequest.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Client;
|
||||||
|
|
||||||
|
use App\Http\Requests\Request;
|
||||||
|
|
||||||
|
class BulkClientRequest extends Request
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize() : bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
|
||||||
|
return [
|
||||||
|
'ids' => 'required|bail|array',
|
||||||
|
'action' => 'in:archive,restore,delete'
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -15,7 +15,6 @@ use App\DataMapper\ClientSettings;
|
|||||||
use App\Factory\ClientFactory;
|
use App\Factory\ClientFactory;
|
||||||
use App\Http\Requests\Client\StoreClientRequest;
|
use App\Http\Requests\Client\StoreClientRequest;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\Country;
|
|
||||||
use App\Repositories\ClientContactRepository;
|
use App\Repositories\ClientContactRepository;
|
||||||
use App\Repositories\ClientRepository;
|
use App\Repositories\ClientRepository;
|
||||||
use App\Utils\Number;
|
use App\Utils\Number;
|
||||||
@ -51,6 +50,48 @@ class ClientApiTest extends TestCase
|
|||||||
$this->faker = \Faker\Factory::create();
|
$this->faker = \Faker\Factory::create();
|
||||||
|
|
||||||
Model::reguard();
|
Model::reguard();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testClientBulkActionValidation()
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'action' => 'muppet',
|
||||||
|
'ids' => [
|
||||||
|
$this->client->hashed_id
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$rules = [
|
||||||
|
'ids' => 'required|bail|array',
|
||||||
|
'action' => 'in:archive,restore,delete'
|
||||||
|
];
|
||||||
|
|
||||||
|
$v = $this->app['validator']->make($data, $rules);
|
||||||
|
$this->assertFalse($v->passes());
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'action' => 'archive',
|
||||||
|
'ids' => [
|
||||||
|
$this->client->hashed_id
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$v = $this->app['validator']->make($data, $rules);
|
||||||
|
$this->assertTrue($v->passes());
|
||||||
|
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'action' => 'archive',
|
||||||
|
'ids' =>
|
||||||
|
$this->client->hashed_id
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
$v = $this->app['validator']->make($data, $rules);
|
||||||
|
$this->assertFalse($v->passes());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testClientStatement()
|
public function testClientStatement()
|
||||||
|
Loading…
Reference in New Issue
Block a user