diff --git a/app/Policies/VacationRequestPolicy.php b/app/Policies/VacationRequestPolicy.php index 0cdaad92..75691afd 100644 --- a/app/Policies/VacationRequestPolicy.php +++ b/app/Policies/VacationRequestPolicy.php @@ -48,7 +48,8 @@ public function cancel(User $user, VacationRequest $vacationRequest): bool return true; } - return $user->hasPermissionTo("manageRequestsAsAdministrativeApprover"); + return $user->hasPermissionTo("manageRequestsAsAdministrativeApprover") + || $user->hasPermissionTo("cancelRequestsAsTechnicalApprover"); } public function show(User $user, VacationRequest $vacationRequest): bool diff --git a/config/permission.php b/config/permission.php index 3320ec6b..93a159ea 100644 --- a/config/permission.php +++ b/config/permission.php @@ -48,6 +48,7 @@ "manageVacationLimits", "manageRequestsAsAdministrativeApprover", "manageRequestsAsTechnicalApprover", + "cancelRequestsAsTechnicalApprover", "createRequestsOnBehalfOfEmployee", "manageOvertimeAsAdministrativeApprover", "manageOvertimeAsTechnicalApprover", @@ -76,6 +77,7 @@ "manageVacationLimits", "manageRequestsAsAdministrativeApprover", "manageRequestsAsTechnicalApprover", + "cancelRequestsAsTechnicalApprover", "manageOvertimeAsAdministrativeApprover", "manageOvertimeAsTechnicalApprover", "listAllOvertimeRequests", @@ -117,6 +119,7 @@ "manageTechnologies", "manageResumes", "manageRequestsAsTechnicalApprover", + "cancelRequestsAsTechnicalApprover", "manageOvertimeAsTechnicalApprover", "listAllOvertimeRequests", "listAllRequests", diff --git a/resources/js/Composables/permissionInfo.js b/resources/js/Composables/permissionInfo.js index 64fe9274..73f12b19 100644 --- a/resources/js/Composables/permissionInfo.js +++ b/resources/js/Composables/permissionInfo.js @@ -59,6 +59,11 @@ const permissionsInfo = [ 'value': 'manageRequestsAsTechnicalApprover', 'section': 'Urlopy', }, + { + 'name': 'Anulowanie wniosków jako przełożony techniczny', + 'value': 'cancelRequestsAsTechnicalApprover', + 'section': 'Urlopy', + }, { 'name': 'Tworzenie wniosków w imieniu pracownika', 'value': 'createRequestsOnBehalfOfEmployee', diff --git a/tests/Feature/PermissionTest.php b/tests/Feature/PermissionTest.php index d16409c9..86aaf7fd 100644 --- a/tests/Feature/PermissionTest.php +++ b/tests/Feature/PermissionTest.php @@ -40,6 +40,7 @@ public function testAdminCanSeeEditEmployeePermissionsForm(): void ->where("manageOvertimeAsAdministrativeApprover", false) ->where("manageOvertimeAsTechnicalApprover", false) ->where("createRequestsOnBehalfOfEmployee", false) + ->where("cancelRequestsAsTechnicalApprover", false) ->where("listMonthlyUsage", false) ->where("listAllRequests", false) ->where("listAllOvertimeRequests", false) @@ -80,6 +81,7 @@ public function testAdminCanSeeEditTechnicalApproverPermissionsForm(): void ->where("manageVacationLimits", false) ->where("manageRequestsAsAdministrativeApprover", false) ->where("manageRequestsAsTechnicalApprover", true) + ->where("cancelRequestsAsTechnicalApprover", true) ->where("manageOvertimeAsAdministrativeApprover", false) ->where("manageOvertimeAsTechnicalApprover", true) ->where("createRequestsOnBehalfOfEmployee", false) @@ -125,6 +127,7 @@ public function testAdminCanSeeEditAdministrativeApproverPermissionsForm(): void ->where("manageRequestsAsTechnicalApprover", false) ->where("manageOvertimeAsAdministrativeApprover", true) ->where("manageOvertimeAsTechnicalApprover", false) + ->where("cancelRequestsAsTechnicalApprover", false) ->where("createRequestsOnBehalfOfEmployee", true) ->where("listMonthlyUsage", true) ->where("listAllRequests", true) diff --git a/tests/Feature/VacationRequestTest.php b/tests/Feature/VacationRequestTest.php index 01531a97..722ea00d 100644 --- a/tests/Feature/VacationRequestTest.php +++ b/tests/Feature/VacationRequestTest.php @@ -602,6 +602,36 @@ public function testEmployeeCannotCancelVacationRequestWithApprovedStatus(): voi ->assertForbidden(); } + public function testTechnicalApproverCanCancelVacationRequestWithApprovedStatus(): void + { + $user = User::factory()->technicalApprover()->create(); + $currentYearPeriod = YearPeriod::current(); + + VacationLimit::factory([ + "days" => 20, + ]) + ->for($user) + ->for($currentYearPeriod) + ->create(); + + /** @var VacationRequest $vacationRequest */ + $vacationRequest = VacationRequest::factory([ + "state" => Approved::class, + "type" => VacationType::Vacation, + ]) + ->for($user) + ->for($currentYearPeriod) + ->create(); + + $this->actingAs($user) + ->post("/vacation/requests/{$vacationRequest->id}/cancel") + ->assertRedirect(); + + $vacationRequest->refresh(); + + $this->assertTrue($vacationRequest->state->equals(Cancelled::class)); + } + public function testEmployeeCanCancelRemoteWorkEvenWithApprovedStatus(): void { $user = User::factory()->create();