Skip to content

A free open source IT asset/license management system

WIP: add type to templates

Marcus Moore912ccead3912
diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php
index 5f9de2a015..20cd0a81ba 100644
--- a/app/Http/Controllers/ReportsController.php
+++ b/app/Http/Controllers/ReportsController.php
@@ -414,7 +414,7 @@ class ReportsController extends Controller
{
$this->authorize('reports.view');
$customfields = CustomField::get();
- $report_templates = ReportTemplate::orderBy('name')->get();
+ $report_templates = ReportTemplate::where('type', 'asset')->orderBy('name')->get();
// The view needs a template to render correctly, even if it is empty...
$template = new ReportTemplate;
diff --git a/database/factories/ReportTemplateFactory.php b/database/factories/ReportTemplateFactory.php
index e28f1475fd..b8078b7abe 100644
--- a/database/factories/ReportTemplateFactory.php
+++ b/database/factories/ReportTemplateFactory.php
@@ -15,6 +15,7 @@ class ReportTemplateFactory extends Factory
public function definition()
{
return [
+ 'type' => 'asset',
'name' => $this->faker->word(),
'options' => [
'id' => '1',
diff --git a/database/migrations/2026_04_28_001156_add_type_column_to_report_templates_table.php b/database/migrations/2026_04_28_001156_add_type_column_to_report_templates_table.php
new file mode 100644
index 0000000000..b184c8067e
--- /dev/null
+++ b/database/migrations/2026_04_28_001156_add_type_column_to_report_templates_table.php
@@ -0,0 +1,28 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ */
+ public function up(): void
+ {
+ Schema::table('report_templates', function (Blueprint $table) {
+ $table->string('type')->default('asset')->after('created_by');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::table('report_templates', function (Blueprint $table) {
+ $table->dropColumn('type');
+ });
+ }
+};
diff --git a/tests/Feature/Reporting/Custom/CustomAccessoryReportTest.php b/tests/Feature/Reporting/Custom/CustomAccessoryReportTest.php
index c6906e2d28..011618c0af 100644
--- a/tests/Feature/Reporting/Custom/CustomAccessoryReportTest.php
+++ b/tests/Feature/Reporting/Custom/CustomAccessoryReportTest.php
@@ -23,7 +23,9 @@ class CustomAccessoryReportTest extends TestCase
public function test_can_load_custom_report_page()
{
- $this->markTestIncomplete();
+ $this->actingAs(User::factory()->canViewReports()->create())
+ ->get(route('reports.custom.accessory'))
+ ->assertOk();
}
public function test_saved_templates_on_page_are_scoped_to_the_user_and_type()
diff --git a/tests/Feature/Reporting/Custom/CustomAssetReportTest.php b/tests/Feature/Reporting/Custom/CustomAssetReportTest.php
index 7d8836e228..56863edb30 100644
--- a/tests/Feature/Reporting/Custom/CustomAssetReportTest.php
+++ b/tests/Feature/Reporting/Custom/CustomAssetReportTest.php
@@ -7,17 +7,15 @@ use App\Models\Company;
use App\Models\CustomField;
use App\Models\ReportTemplate;
use App\Models\User;
-use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Testing\TestResponse;
use League\Csv\Reader;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\Attributes\Group;
-use Tests\Concerns\TestsPermissionsRequirement;
use Tests\TestCase;
#[Group('custom-reporting')]
-class CustomAssetReportTest extends TestCase implements TestsPermissionsRequirement
+class CustomAssetReportTest extends TestCase
{
protected function setUp(): void
{
@@ -77,24 +75,25 @@ class CustomAssetReportTest extends TestCase implements TestsPermissionsRequirem
public function test_saved_templates_on_page_are_scoped_to_the_user_and_type()
{
- $this->markTestIncomplete('Add {type} check');
+ // 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']);
- // Given there is a saved template for one user
- ReportTemplate::factory()->create(['name' => 'Report A']);
-
- // When loading reports/custom while acting as another user that also has a saved template
+ // When loading reports/custom while acting as another user that also has saved templates
$user = User::factory()->canViewReports()
- ->has(ReportTemplate::factory(['name' => 'Report B']))
+ ->has(ReportTemplate::factory(['type' => 'asset', 'name' => 'User: Asset']))
+ ->has(ReportTemplate::factory(['type' => 'accessory', 'name' => 'User: Accessory']))
->create();
- // The user should not see the other user's template (in view as 'report_templates')
- $this->actingAs($user)
- ->get(route('reports/custom'))
- ->assertViewHas([
- 'report_templates' => function (Collection $reports) {
- return $reports->pluck('name')->doesntContain('Report A');
- },
- ]);
+ $response = $this->actingAs($user)->get(route('reports/custom'));
+
+ $viewTemplateNames = $response->viewData('report_templates')->pluck('name');
+
+ // The user should only see their asset template
+ $this->assertTrue($viewTemplateNames->contains('User: Asset'));
+ $this->assertTrue($viewTemplateNames->doesntContain('User: Accessory'));
+ $this->assertTrue($viewTemplateNames->doesntContain('Another User: Asset'));
+ $this->assertTrue($viewTemplateNames->doesntContain('Another User: Accessory'));
}
public function test_custom_asset_report()