mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Bulk action request for company gateways
This commit is contained in:
parent
9628580be0
commit
7bd5a73d70
@ -14,6 +14,7 @@ namespace App\Http\Controllers;
|
||||
use App\DataMapper\FeesAndLimits;
|
||||
use App\Factory\CompanyGatewayFactory;
|
||||
use App\Filters\CompanyGatewayFilters;
|
||||
use App\Http\Requests\CompanyGateway\BulkCompanyGatewayRequest;
|
||||
use App\Http\Requests\CompanyGateway\CreateCompanyGatewayRequest;
|
||||
use App\Http\Requests\CompanyGateway\DestroyCompanyGatewayRequest;
|
||||
use App\Http\Requests\CompanyGateway\EditCompanyGatewayRequest;
|
||||
@ -496,19 +497,18 @@ class CompanyGatewayController extends BaseController
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
public function bulk()
|
||||
public function bulk(BulkCompanyGatewayRequest $request)
|
||||
{
|
||||
$action = request()->input('action');
|
||||
$action = $request->input('action');
|
||||
|
||||
$ids = request()->input('ids');
|
||||
$ids = $request->input('ids');
|
||||
|
||||
$company_gateways = CompanyGateway::withTrashed()->find($this->transformKeys($ids));
|
||||
|
||||
$company_gateways->each(function ($company_gateway, $key) use ($action) {
|
||||
if (auth()->user()->can('edit', $company_gateway)) {
|
||||
$this->company_repo->{$action}($company_gateway);
|
||||
}
|
||||
});
|
||||
$company_gateways = CompanyGateway::withTrashed()
|
||||
->whereIn('id',$this->transformKeys($ids))
|
||||
->cursor()
|
||||
->each(function ($company_gateway, $key) use ($action) {
|
||||
$this->company_repo->{$action}($company_gateway);
|
||||
});
|
||||
|
||||
return $this->listResponse(CompanyGateway::withTrashed()->whereIn('id', $this->transformKeys($ids)));
|
||||
}
|
||||
|
@ -0,0 +1,45 @@
|
||||
<?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\CompanyGateway;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Http\ValidationRules\ValidCompanyGatewayFeesAndLimitsRule;
|
||||
use App\Models\Gateway;
|
||||
use App\Utils\Traits\CompanyGatewayFeesAndLimitsSaver;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class BulkCompanyGatewayRequest extends Request
|
||||
|
||||
{
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize() : bool
|
||||
{
|
||||
return auth()->user()->isAdmin();
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
|
||||
return [
|
||||
'ids' => 'required|bail|array',
|
||||
'action' => 'in:archive,restore,delete'
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -76,7 +76,6 @@ class BankTransactionRuleTest extends TestCase
|
||||
])->post('/api/v1/bank_transaction_rules/bulk', $data)
|
||||
->assertStatus(200);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function testValidationContainsRule()
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\DataMapper\FeesAndLimits;
|
||||
use App\Factory\CompanyGatewayFactory;
|
||||
use App\Models\CompanyGateway;
|
||||
use App\Models\GatewayType;
|
||||
use App\Utils\Traits\CompanyGatewayFeesAndLimitsSaver;
|
||||
@ -46,6 +47,49 @@ class CompanyGatewayApiTest extends TestCase
|
||||
Model::reguard();
|
||||
}
|
||||
|
||||
public function testBulkActions()
|
||||
{
|
||||
$cg = CompanyGatewayFactory::create($this->company->id, $this->user->id);
|
||||
$cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
|
||||
$cg->save();
|
||||
|
||||
$data = [
|
||||
'action' => 'archive',
|
||||
'ids' => [$cg->hashed_id]
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/company_gateways/bulk', $data)
|
||||
->assertStatus(200);
|
||||
|
||||
|
||||
$data = [
|
||||
'ids' => [$cg->hashed_id],
|
||||
'action' => 'restore'
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/company_gateways/bulk', $data)
|
||||
->assertStatus(200);
|
||||
|
||||
$data = [
|
||||
'ids' => [$cg->hashed_id],
|
||||
'action' => 'delete'
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/company_gateways/bulk', $data)
|
||||
->assertStatus(200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testCompanyGatewayEndPointsWithIncorrectFields()
|
||||
{
|
||||
$data = [
|
||||
|
Loading…
x
Reference in New Issue
Block a user