mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-22 12:20:56 -04:00
Implement Bulk actions for designs
This commit is contained in:
parent
66fe5aa4ee
commit
666a2395d1
@ -31,7 +31,6 @@ use Illuminate\Support\Facades\Cache;
|
|||||||
/**
|
/**
|
||||||
* Class DesignController
|
* Class DesignController
|
||||||
* @package App\Http\Controllers
|
* @package App\Http\Controllers
|
||||||
* @covers App\Http\Controllers\DesignController
|
|
||||||
*/
|
*/
|
||||||
class DesignController extends BaseController
|
class DesignController extends BaseController
|
||||||
{
|
{
|
||||||
@ -480,11 +479,12 @@ class DesignController extends BaseController
|
|||||||
$action = request()->input('action');
|
$action = request()->input('action');
|
||||||
|
|
||||||
$ids = request()->input('ids');
|
$ids = request()->input('ids');
|
||||||
|
info($ids);
|
||||||
$designs = Design::withTrashed()->find($this->transformKeys($ids));
|
$designs = Design::withTrashed()->find($this->transformKeys($ids));
|
||||||
|
|
||||||
info($designs);
|
info($designs);
|
||||||
info(auth()->user()->id);
|
info("user id = ".auth()->user()->id);
|
||||||
info(auth()->user()->getCompany()->id);
|
info("company id = ".auth()->user()->getCompany()->id);
|
||||||
|
|
||||||
$designs->each(function ($design, $key) use ($action) {
|
$designs->each(function ($design, $key) use ($action) {
|
||||||
if (auth()->user()->can('edit', $design)) {
|
if (auth()->user()->can('edit', $design)) {
|
||||||
|
@ -132,4 +132,80 @@ class DesignApiTest extends TestCase
|
|||||||
$this->assertTrue((bool)$design->is_deleted);
|
$this->assertTrue((bool)$design->is_deleted);
|
||||||
$this->assertGreaterThan(0, $design->deleted_at);
|
$this->assertGreaterThan(0, $design->deleted_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testDesignArchive()
|
||||||
|
{
|
||||||
|
$design = [
|
||||||
|
'body' => 'body',
|
||||||
|
'includes' => 'includes',
|
||||||
|
'product' => 'product',
|
||||||
|
'task' => 'task',
|
||||||
|
'footer' => 'footer',
|
||||||
|
'header' => 'header'
|
||||||
|
];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => $this->faker->firstName,
|
||||||
|
'design' => $design
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token
|
||||||
|
])->post('/api/v1/designs', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
$arr = $response->json();
|
||||||
|
|
||||||
|
$this->id = $arr['data']['id'];
|
||||||
|
|
||||||
|
$data['ids'][] = $arr['data']['id'];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token
|
||||||
|
])->post('/api/v1/designs/bulk?action=archive', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
$design = Design::where('id', $this->decodePrimaryKey($arr['data']['id']))->withTrashed()->first();
|
||||||
|
|
||||||
|
$this->assertNotNull($design->deleted_at);
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token
|
||||||
|
])->post('/api/v1/designs/bulk?action=restore', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
$design = Design::where('id', $this->decodePrimaryKey($arr['data']['id']))->withTrashed()->first();
|
||||||
|
|
||||||
|
$this->assertNull($design->deleted_at);
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token
|
||||||
|
])->post('/api/v1/designs/bulk?action=delete', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
$design = Design::where('id', $this->decodePrimaryKey($arr['data']['id']))->withTrashed()->first();
|
||||||
|
|
||||||
|
$this->assertTrue((bool)$design->is_deleted);
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token
|
||||||
|
])->post('/api/v1/designs/bulk?action=restore', $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
$design = Design::where('id', $this->decodePrimaryKey($arr['data']['id']))->withTrashed()->first();
|
||||||
|
|
||||||
|
$this->assertFalse((bool)$design->is_deleted);
|
||||||
|
$this->assertNull($design->deleted_at);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user