A free open source IT asset/license management system
WIP: Component report scaffolding
Marcus Moore60b7ea11e2d9
diff --git a/app/Http/Controllers/Reports/CustomAccessoryReportController.php b/app/Http/Controllers/Reports/CustomAccessoryReportController.phpindex 3c336ef1d4..542d822caf 100644--- a/app/Http/Controllers/Reports/CustomAccessoryReportController.php+++ b/app/Http/Controllers/Reports/CustomAccessoryReportController.php@@ -32,9 +32,10 @@ class CustomAccessoryReportController extends Controllerpublic function run(){- ini_set('max_execution_time', env('REPORT_TIME_LIMIT', 12000)); // 12000 seconds = 200 minutes$this->authorize('reports.view');+ ini_set('max_execution_time', env('REPORT_TIME_LIMIT', 12000)); // 12000 seconds = 200 minutes+$this->disableDebugbar();}diff --git a/app/Http/Controllers/Reports/CustomComponentReportController.php b/app/Http/Controllers/Reports/CustomComponentReportController.phpnew file mode 100644index 0000000000..6b90341877--- /dev/null+++ b/app/Http/Controllers/Reports/CustomComponentReportController.php@@ -0,0 +1,41 @@+<?php++namespace App\Http\Controllers\Reports;++use App\Http\Controllers\Controller;+use App\Models\ReportTemplate;+use Illuminate\Http\Request;++class CustomComponentReportController extends Controller+{+ public function show(Request $request)+ {+ $this->authorize('reports.view');++ $report_templates = ReportTemplate::where('type', 'component')->orderBy('name')->get();++ // The view needs a template to render correctly, even if it is empty...+ $template = new ReportTemplate;++ // Set the report's input values in the cases we were redirected back+ // with validation errors so the report is populated as expected.+ if ($request->old()) {+ $template->name = $request->old('name');+ $template->options = $request->old();+ }++ return view('reports.custom.component', [+ 'report_templates' => $report_templates,+ 'template' => $template,+ ]);+ }++ public function run(Request $request)+ {+ $this->authorize('reports.view');++ ini_set('max_execution_time', env('REPORT_TIME_LIMIT', 12000)); // 12000 seconds = 200 minutes++ $this->disableDebugbar();+ }+}diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.phpindex fd3320a3fa..ddcfab082d 100644--- a/resources/views/layouts/default.blade.php+++ b/resources/views/layouts/default.blade.php@@ -1843,6 +1843,11 @@Custom Accessory Report</a></li>+ <li {{!! (request()->is('reports.custom.component') ? ' class="active"' : '') !!}}>+ <a href="{{ route('reports.custom.component') }}">+ Custom Component Report+ </a>+ </li><li {{!! (request()->is('reports/audit') ? ' class="active"' : '') !!}}><a href="{{ route('reports.audit') }}">{{ trans('general.audit_report') }}</a>diff --git a/resources/views/reports/custom/component.blade.php b/resources/views/reports/custom/component.blade.phpnew file mode 100644index 0000000000..e69de29bb2diff --git a/routes/web.php b/routes/web.phpindex a2f4da9806..0fd7cddd89 100644--- a/routes/web.php+++ b/routes/web.php@@ -22,6 +22,7 @@ use App\Http\Controllers\ModalController;use App\Http\Controllers\NotesController;use App\Http\Controllers\ProfileController;use App\Http\Controllers\Reports\CustomAccessoryReportController;+use App\Http\Controllers\Reports\CustomComponentReportController;use App\Http\Controllers\ReportsController;use App\Http\Controllers\ReportTemplatesController;use App\Http\Controllers\SettingsController;@@ -518,6 +519,14 @@ Route::group(['prefix' => 'reports', 'middleware' => ['auth']], function () {Route::post('accessory', [CustomAccessoryReportController::class, 'run'])->name('reports.custom.accessory.run');++ Route::get('component', [CustomComponentReportController::class, 'show'])+ ->name('reports.custom.component')+ ->breadcrumbs(fn (Trail $trail) => $trail->parent('home')+ ->push('Custom Component Report', route('reports.custom.component')));++ Route::post('component', [CustomComponentReportController::class, 'run'])+ ->name('reports.custom.component.run');});Route::prefix('templates')diff --git a/tests/Feature/Reporting/Custom/CustomAccessoryReportTest.php b/tests/Feature/Reporting/Custom/CustomAccessoryReportTest.phpindex 1cf55cbc8d..caad3094cb 100644--- a/tests/Feature/Reporting/Custom/CustomAccessoryReportTest.php+++ b/tests/Feature/Reporting/Custom/CustomAccessoryReportTest.php@@ -40,11 +40,13 @@ class CustomAccessoryReportTest extends TestCase// Given there are saved templates for one userReportTemplate::factory()->create(['type' => 'asset', 'name' => 'Another User: Asset']);ReportTemplate::factory()->create(['type' => 'accessory', 'name' => 'Another User: Accessory']);+ ReportTemplate::factory()->create(['type' => 'component', 'name' => 'Another User: Component']);// When loading reports.custom.accessory while acting as another user that also has saved templates$user = User::factory()->canViewReports()->has(ReportTemplate::factory(['type' => 'asset', 'name' => 'User: Asset']))->has(ReportTemplate::factory(['type' => 'accessory', 'name' => 'User: Accessory']))+ ->has(ReportTemplate::factory(['type' => 'component', 'name' => 'User: Component']))->create();$response = $this->actingAs($user)->get(route('reports.custom.accessory'));@@ -54,8 +56,10 @@ class CustomAccessoryReportTest extends TestCase// The user should only see their accessory template$this->assertTrue($viewTemplateNames->contains('User: Accessory'));$this->assertTrue($viewTemplateNames->doesntContain('User: Asset'));+ $this->assertTrue($viewTemplateNames->doesntContain('User: Component'));$this->assertTrue($viewTemplateNames->doesntContain('Another User: Asset'));$this->assertTrue($viewTemplateNames->doesntContain('Another User: Accessory'));+ $this->assertTrue($viewTemplateNames->doesntContain('Another User: Component'));}public function test_custom_accessory_report()diff --git a/tests/Feature/Reporting/Custom/CustomComponentReportTest.php b/tests/Feature/Reporting/Custom/CustomComponentReportTest.phpindex 923043103a..3b7cc047dd 100644--- a/tests/Feature/Reporting/Custom/CustomComponentReportTest.php+++ b/tests/Feature/Reporting/Custom/CustomComponentReportTest.php@@ -2,51 +2,85 @@namespace Tests\Feature\Reporting\Custom;+use App\Models\ReportTemplate;+use App\Models\User;+use PHPUnit\Framework\Attributes\Group;use Tests\TestCase;+#[Group('custom-reporting')]class CustomComponentReportTest extends TestCase{public function test_requires_permission_to_view_page(){- $this->markTestIncomplete();+ $this->actingAs(User::factory()->create())+ ->get(route('reports.custom.component'))+ ->assertForbidden();}public function test_requires_permission_to_run_report(){- $this->markTestIncomplete();+ $this->actingAs(User::factory()->create())+ ->post(route('reports.custom.component.run'), [+ //+ ])+ ->assertForbidden();}public function test_can_load_custom_report_page(){- $this->markTestIncomplete();+ $this->actingAs(User::factory()->canViewReports()->create())+ ->get(route('reports.custom.component'))+ ->assertOk();}public function test_saved_templates_on_page_are_scoped_to_the_user_and_type(){- $this->markTestIncomplete();+ // Given there are saved templates for one user+ ReportTemplate::factory()->create(['type' => 'asset', 'name' => 'Another User: Asset']);+ ReportTemplate::factory()->create(['type' => 'accessory', 'name' => 'Another User: Accessory']);+ ReportTemplate::factory()->create(['type' => 'component', 'name' => 'Another User: Component']);++ // When loading reports.custom.component while acting as another user that also has saved templates+ $user = User::factory()->canViewReports()+ ->has(ReportTemplate::factory(['type' => 'asset', 'name' => 'User: Asset']))+ ->has(ReportTemplate::factory(['type' => 'accessory', 'name' => 'User: Accessory']))+ ->has(ReportTemplate::factory(['type' => 'component', 'name' => 'User: Component']))+ ->create();++ $response = $this->actingAs($user)->get(route('reports.custom.component'));++ $viewTemplateNames = $response->viewData('report_templates')->pluck('name');++ // The user should only see their component template+ $this->assertTrue($viewTemplateNames->contains('User: Component'));+ $this->assertTrue($viewTemplateNames->doesntContain('User: Accessory'));+ $this->assertTrue($viewTemplateNames->doesntContain('User: Asset'));+ $this->assertTrue($viewTemplateNames->doesntContain('Another User: Asset'));+ $this->assertTrue($viewTemplateNames->doesntContain('Another User: Accessory'));+ $this->assertTrue($viewTemplateNames->doesntContain('Another User: Component'));}- public function test_custom_accessory_report()+ public function test_custom_component_report(){$this->markTestIncomplete();}- public function test_custom_accessory_report_headers()+ public function test_custom_component_report_headers(){$this->markTestIncomplete();}- public function test_custom_accessory_report_content()+ public function test_custom_component_report_content(){$this->markTestIncomplete();}- public function test_custom_accessory_report_exclude_deleted()+ public function test_custom_component_report_exclude_deleted(){$this->markTestIncomplete();}- public function test_custom_accessory_report_adheres_to_company_scoping()+ public function test_custom_component_report_adheres_to_company_scoping(){$this->markTestIncomplete();}