Skip to content

A free open source IT asset/license management system

Maintenances: Fixed FD-56038 - gate for maintenance view

snipe69c50aa2aee2
diff --git a/app/Http/Controllers/MaintenancesController.php b/app/Http/Controllers/MaintenancesController.php
index 63b8dc1d74..4c255e32d1 100644
--- a/app/Http/Controllers/MaintenancesController.php
+++ b/app/Http/Controllers/MaintenancesController.php
@@ -305,6 +305,8 @@ class MaintenancesController extends Controller
*/
public function show(Maintenance $maintenance): View|RedirectResponse
{
+ $this->authorize('view', $maintenance->asset);
+
return view('maintenances.view')->with('maintenance', $maintenance);
}
}
diff --git a/tests/Feature/Maintenances/Ui/MaintenanceFileTest.php b/tests/Feature/Maintenances/Ui/MaintenanceFileTest.php
index 3add526ceb..a3cc091962 100644
--- a/tests/Feature/Maintenances/Ui/MaintenanceFileTest.php
+++ b/tests/Feature/Maintenances/Ui/MaintenanceFileTest.php
@@ -54,6 +54,7 @@ class MaintenanceFileTest extends TestCase
$company = Company::factory()->create();
$user = User::factory()
+ ->viewAssets()
->editAssets()
->create(['company_id' => $company->id]);
diff --git a/tests/Feature/Maintenances/Ui/ShowMaintenanceTest.php b/tests/Feature/Maintenances/Ui/ShowMaintenanceTest.php
index 2339bf9abc..00cc9fd082 100644
--- a/tests/Feature/Maintenances/Ui/ShowMaintenanceTest.php
+++ b/tests/Feature/Maintenances/Ui/ShowMaintenanceTest.php
@@ -27,6 +27,30 @@ class ShowMaintenanceTest extends TestCase
->assertSee(route('api.maintenances.history', $maintenance), false);
}
+ public function test_user_without_asset_view_permission_cannot_view_maintenance()
+ {
+ $maintenance = Maintenance::factory()->create();
+
+ $this->actingAs(User::factory()->create())
+ ->get(route('maintenances.show', $maintenance))
+ ->assertForbidden();
+ }
+
+ public function test_user_without_asset_view_permission_cannot_view_maintenance_for_another_company_when_fmcs_enabled()
+ {
+ $this->settings->enableMultipleFullCompanySupport();
+
+ [$companyA, $companyB] = Company::factory()->count(2)->create();
+
+ $userInCompanyA = $companyA->users()->save(User::factory()->create());
+ $maintenanceForCompanyB = Maintenance::factory()->create();
+ $maintenanceForCompanyB->asset->update(['company_id' => $companyB->id]);
+
+ $this->actingAs($userInCompanyA)
+ ->get(route('maintenances.show', $maintenanceForCompanyB))
+ ->assertRedirectToRoute('maintenances.index');
+ }
+
public function test_user_cannot_view_maintenance_for_another_company_when_fmcs_enabled()
{
$this->settings->enableMultipleFullCompanySupport();