Skip to content

Commit

Permalink
#481 - feat: added possibility of cancelling requests for technical a…
Browse files Browse the repository at this point in the history
…pprover
  • Loading branch information
kamilpiech97 committed Aug 6, 2024
1 parent 73b6266 commit d181c79
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/Policies/VacationRequestPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions config/permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"manageVacationLimits",
"manageRequestsAsAdministrativeApprover",
"manageRequestsAsTechnicalApprover",
"cancelRequestsAsTechnicalApprover",
"createRequestsOnBehalfOfEmployee",
"manageOvertimeAsAdministrativeApprover",
"manageOvertimeAsTechnicalApprover",
Expand Down Expand Up @@ -76,6 +77,7 @@
"manageVacationLimits",
"manageRequestsAsAdministrativeApprover",
"manageRequestsAsTechnicalApprover",
"cancelRequestsAsTechnicalApprover",
"manageOvertimeAsAdministrativeApprover",
"manageOvertimeAsTechnicalApprover",
"listAllOvertimeRequests",
Expand Down Expand Up @@ -117,6 +119,7 @@
"manageTechnologies",
"manageResumes",
"manageRequestsAsTechnicalApprover",
"cancelRequestsAsTechnicalApprover",
"manageOvertimeAsTechnicalApprover",
"listAllOvertimeRequests",
"listAllRequests",
Expand Down
5 changes: 5 additions & 0 deletions resources/js/Composables/permissionInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions tests/Feature/PermissionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
30 changes: 30 additions & 0 deletions tests/Feature/VacationRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit d181c79

Please sign in to comment.