Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 32 additions & 0 deletions tests/Feature/VacationRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
]);
}
}