diff --git a/app/Http/Controllers/Frontdesk/HostPortalController.php b/app/Http/Controllers/Frontdesk/HostPortalController.php index 1d3f59a..f791099 100644 --- a/app/Http/Controllers/Frontdesk/HostPortalController.php +++ b/app/Http/Controllers/Frontdesk/HostPortalController.php @@ -6,10 +6,10 @@ use App\Http\Controllers\Controller; use App\Http\Controllers\Frontdesk\Concerns\ScopesToAccount; use App\Models\Host; use App\Models\Visit; -use App\Services\Frontdesk\FrontdeskPermissions; use App\Services\Frontdesk\OrganizationResolver; use App\Services\Frontdesk\VisitLifecycleService; use App\Services\Frontdesk\VisitScheduleService; +use Illuminate\Http\Exceptions\HttpResponseException; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\View\View; @@ -114,17 +114,15 @@ class HostPortalController extends Controller protected function resolveLinkedHost(Request $request): Host { - $permissions = app(FrontdeskPermissions::class); - $member = $this->member($request); - - abort_unless( - $permissions->can($member, 'host.portal') || app(OrganizationResolver::class)->hostFor($request->user()) !== null, - 403, - ); - $host = app(OrganizationResolver::class)->hostFor($request->user()); - abort_unless($host, 403, 'No host profile linked to your account.'); + if (! $host) { + throw new HttpResponseException( + redirect() + ->route('frontdesk.dashboard') + ->with('error', 'No host profile is linked to your account. Ask an administrator to link your Ladill user on the Hosts screen.'), + ); + } $this->authorizeOwner($request, $host); diff --git a/resources/views/partials/sidebar.blade.php b/resources/views/partials/sidebar.blade.php index e553a91..943433c 100644 --- a/resources/views/partials/sidebar.blade.php +++ b/resources/views/partials/sidebar.blade.php @@ -32,7 +32,7 @@ 'icon' => ''], ]; - if ($permissions->can($member, 'host.portal') || $linkedHost) { + if ($linkedHost) { $nav[] = ['name' => 'Host portal', 'route' => route('frontdesk.host.index'), 'active' => request()->routeIs('frontdesk.host.*'), 'icon' => '']; } diff --git a/tests/Feature/FrontdeskPhase6Test.php b/tests/Feature/FrontdeskPhase6Test.php index 9ea05bc..d19ba41 100644 --- a/tests/Feature/FrontdeskPhase6Test.php +++ b/tests/Feature/FrontdeskPhase6Test.php @@ -81,6 +81,32 @@ class FrontdeskPhase6Test extends TestCase ->assertSee('Phase6 Host'); } + public function test_org_admin_without_linked_host_cannot_access_host_portal(): void + { + $admin = User::create([ + 'public_id' => 'phase6-admin-001', + 'name' => 'Org Admin', + 'email' => 'admin@example.com', + ]); + + Member::create([ + 'owner_ref' => $this->user->public_id, + 'organization_id' => $this->organization->id, + 'user_ref' => $admin->public_id, + 'role' => 'org_admin', + ]); + + $this->actingAs($admin) + ->get(route('frontdesk.dashboard')) + ->assertOk() + ->assertDontSee('Host portal', false); + + $this->actingAs($admin) + ->get(route('frontdesk.host.index')) + ->assertRedirect(route('frontdesk.dashboard')) + ->assertSessionHas('error'); + } + public function test_host_can_pre_register_visitor(): void { $this->actingAs($this->user)