diff --git a/app/Http/Controllers/Api/GetAvailableVacationTypesController.php b/app/Http/Controllers/Api/GetAvailableVacationTypesController.php index 5fb7ff10..c646a7a1 100644 --- a/app/Http/Controllers/Api/GetAvailableVacationTypesController.php +++ b/app/Http/Controllers/Api/GetAvailableVacationTypesController.php @@ -19,10 +19,17 @@ public function __invoke( ): JsonResponse { /** @var User $user */ $user = User::query()->find($request->get("user")); + $currentUser = $request->user(); $types = VacationType::all() - ->filter(fn(VacationType $type): bool => $configRetriever->isAvailableFor($type, $user->profile->employment_form)) - ->filter(fn(VacationType $type): bool => $configRetriever->isRequestAllowedFor($type, $request->user()->role)) + ->filter(function (VacationType $type) use ($configRetriever, $user, $currentUser): bool { + if ($currentUser->can("createRequestsOnBehalfOfEmployee")) { + return $configRetriever->isAvailableFor($type, $user->profile->employment_form); + } + + return $configRetriever->isRequestAllowedFor($type, $currentUser->role) + && $configRetriever->isAvailableFor($type, $user->profile->employment_form); + }) ->map(fn(VacationType $type): array => [ "label" => $type->label(), "value" => $type->value, diff --git a/tests/Feature/VacationRequestTest.php b/tests/Feature/VacationRequestTest.php index 5426c665..a3801351 100644 --- a/tests/Feature/VacationRequestTest.php +++ b/tests/Feature/VacationRequestTest.php @@ -994,4 +994,36 @@ public function testCorrectVacationTypesAreAvailableForBoardMemberContract(): vo ["label" => "Nieobecność", "value" => "absence"], ]); } + + public function testEmployeeWithPermissionToCreateOnBehalfSeesAllVacationTypesForEmployee(): void + { + $employeeWithPermission = User::factory() + ->has(Profile::factory(["employment_form" => EmploymentForm::EmploymentContract])) + ->create(); + + $employeeWithPermission->givePermissionTo("createRequestsOnBehalfOfEmployee"); + + $targetEmployee = User::factory() + ->has(Profile::factory(["employment_form" => EmploymentForm::EmploymentContract])) + ->create(); + + $this->actingAs($employeeWithPermission) + ->post("/api/vacation/get-available-vacation-types", [ + "user" => $targetEmployee->id, + ]) + ->assertOk() + ->assertJson([ + ["label" => "Praca zdalna", "value" => "remote_work"], + ["label" => "Urlop wypoczynkowy", "value" => "vacation"], + ["label" => "Zwolnienie lekarskie", "value" => "sick_vacation"], + ["label" => "Urlop okolicznościowy", "value" => "special_vacation"], + ["label" => "Delegacja", "value" => "delegation"], + ["label" => "Odbiór za święto", "value" => "time_in_lieu"], + ["label" => "Urlop bezpłatny", "value" => "unpaid_vacation"], + ["label" => "Urlop na żądanie", "value" => "vacation_on_request"], + ["label" => "Urlop szkoleniowy", "value" => "training_vacation"], + ["label" => "Opieka nad dzieckiem (art. 188 kp)", "value" => "childcare_vacation"], + ["label" => "Wolontariat", "value" => "volunteering_vacation"], + ]); + } }