diff --git a/app/Http/Controllers/Care/CareUnitController.php b/app/Http/Controllers/Care/CareUnitController.php index 5d16cf0..5bcef28 100644 --- a/app/Http/Controllers/Care/CareUnitController.php +++ b/app/Http/Controllers/Care/CareUnitController.php @@ -20,9 +20,11 @@ class CareUnitController extends Controller public function index(Request $request): View { - $this->authorizeCareUnitView($request); + $this->authorizeAbility($request, 'admin.departments.view'); $organization = $this->organization($request); $owner = $this->ownerRef($request); + $member = $this->member($request); + $permissions = app(CarePermissions::class); $units = CareUnit::owned($owner) ->where('organization_id', $organization->id) @@ -43,6 +45,7 @@ class CareUnitController extends Controller 'organization' => $organization, 'kinds' => config('care.care_unit_kinds'), 'heroStats' => $heroStats, + 'canManage' => $permissions->can($member, 'admin.departments.manage'), ]); } diff --git a/app/Http/Controllers/Care/DepartmentController.php b/app/Http/Controllers/Care/DepartmentController.php index 0409961..a6eafc6 100644 --- a/app/Http/Controllers/Care/DepartmentController.php +++ b/app/Http/Controllers/Care/DepartmentController.php @@ -7,6 +7,7 @@ use App\Http\Controllers\Care\Concerns\ScopesToAccount; use App\Models\Branch; use App\Models\Department; use App\Services\Care\AuditLogger; +use App\Services\Care\CarePermissions; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\View\View; @@ -20,6 +21,8 @@ class DepartmentController extends Controller $this->authorizeAbility($request, 'admin.departments.view'); $organization = $this->organization($request); $owner = $this->ownerRef($request); + $member = $this->member($request); + $permissions = app(CarePermissions::class); $departments = Department::owned($owner) ->whereHas('branch', fn ($q) => $q->where('organization_id', $organization->id)) @@ -38,6 +41,7 @@ class DepartmentController extends Controller 'organization' => $organization, 'types' => config('care.department_types'), 'heroStats' => $heroStats, + 'canManage' => $permissions->can($member, 'admin.departments.manage'), ]); } diff --git a/resources/views/care/admin/care-units/index.blade.php b/resources/views/care/admin/care-units/index.blade.php index 6bff097..5dedc10 100644 --- a/resources/views/care/admin/care-units/index.blade.php +++ b/resources/views/care/admin/care-units/index.blade.php @@ -11,7 +11,9 @@ ['value' => number_format($heroStats['active']), 'label' => 'Active'], ]"> - Add care unit + @if ($canManage ?? false) + Add care unit + @endif diff --git a/resources/views/care/admin/departments/index.blade.php b/resources/views/care/admin/departments/index.blade.php index 3729cb8..ab5df91 100644 --- a/resources/views/care/admin/departments/index.blade.php +++ b/resources/views/care/admin/departments/index.blade.php @@ -11,7 +11,9 @@ ]"> Care units - Add department + @if ($canManage ?? false) + Add department + @endif @@ -27,7 +29,9 @@ {{ $types[$department->type] ?? $department->type }} {{ $department->branch?->name }} - Edit + @if ($canManage ?? false) + Edit + @endif @empty diff --git a/resources/views/care/nursing/services-hub.blade.php b/resources/views/care/nursing/services-hub.blade.php index ce39bb2..5c68c01 100644 --- a/resources/views/care/nursing/services-hub.blade.php +++ b/resources/views/care/nursing/services-hub.blade.php @@ -127,7 +127,7 @@ @empty -

No care units yet — create units under Care units.

+

No care units yet — ask an administrator to set them up.

@endforelse diff --git a/resources/views/partials/sidebar.blade.php b/resources/views/partials/sidebar.blade.php index 75b2d7a..7b8bf8c 100644 --- a/resources/views/partials/sidebar.blade.php +++ b/resources/views/partials/sidebar.blade.php @@ -132,9 +132,6 @@ if ($permissions->can($member, 'admin.departments.view')) { $adminNav[] = ['name' => 'Care units', 'route' => route('care.care-units.index'), 'active' => request()->routeIs('care.care-units.*'), 'icon' => '']; - } elseif ($permissions->can($member, 'nursing.services.view') && $permissions->can($member, 'inpatient.placement.view')) { - $adminNav[] = ['name' => 'Care units', 'route' => route('care.care-units.index'), 'active' => request()->routeIs('care.care-units.*'), - 'icon' => '']; } if ($permissions->can($member, 'nursing.services.view')) { $adminNav[] = ['name' => 'Nursing Services', 'route' => route('care.nursing.services'), 'active' => request()->routeIs('care.nursing.*') || request()->routeIs('care.shifts.*'), diff --git a/tests/Feature/CareMyShiftsAndNavPermissionsTest.php b/tests/Feature/CareMyShiftsAndNavPermissionsTest.php index 9a71027..2c0a076 100644 --- a/tests/Feature/CareMyShiftsAndNavPermissionsTest.php +++ b/tests/Feature/CareMyShiftsAndNavPermissionsTest.php @@ -156,15 +156,50 @@ class CareMyShiftsAndNavPermissionsTest extends TestCase public function test_nurse_still_gets_nursing_services_access(): void { + $user = User::create([ + 'public_id' => 'nurse-hub', + 'name' => 'Ward Nurse', + 'email' => 'nurse-hub@example.com', + ]); $member = Member::create([ 'owner_ref' => $this->owner->public_id, 'organization_id' => $this->organization->id, - 'user_ref' => 'nurse-hub', + 'user_ref' => $user->public_id, 'role' => 'nurse', + 'branch_id' => $this->branch->id, ]); $permissions = app(CarePermissions::class); $this->assertTrue($permissions->can($member, 'nursing.services.view')); $this->assertTrue($permissions->can($member, 'inpatient.placement.view')); + $this->assertFalse($permissions->can($member, 'admin.departments.view')); + $this->assertFalse($permissions->can($member, 'admin.departments.manage')); + + $this->actingAs($user) + ->get(route('care.care-units.index')) + ->assertForbidden(); + + $this->actingAs($user) + ->get(route('care.care-units.create')) + ->assertForbidden(); + + $this->actingAs($user) + ->get(route('care.departments.index')) + ->assertForbidden(); + + $this->actingAs($user) + ->get(route('care.departments.create')) + ->assertForbidden(); + + $this->actingAs($user) + ->get(route('care.nursing.services')) + ->assertOk(); + + $this->actingAs($user) + ->get(route('care.dashboard')) + ->assertOk() + ->assertDontSee('>Care units<', false) + ->assertDontSee('>Departments<', false) + ->assertSee('>Nursing Services<', false); } }