-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PCHR-4051: Allow Own Approver And Admin Cancel Own Leave Request Even When Absence Type Does Not Allow It #2805
PCHR-4051: Allow Own Approver And Admin Cancel Own Leave Request Even When Absence Type Does Not Allow It #2805
Conversation
…ts Service. Add tests.
…vice. Add tests. Remove validation for absence type cancellation in Leave Request BAO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly formatting stuff
$isCancelledStatus = $this->isCancelledStatus($params); | ||
|
||
if ($isCancelledStatus) { | ||
if(!$this->canCancelForAbsenceType($params)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space after if
|
||
$today = new DateTime('today'); | ||
|
||
if ($absenceType->allow_request_cancelation != AbsenceType::REQUEST_CANCELATION_NO && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit long, and also a bit confusing to read, do you think you can make
$absenceType->allow_request_cancelation != AbsenceType::REQUEST_CANCELATION_NO
into a descriptive variable?
} | ||
|
||
public function testCanCancelForAbsenceTypeReturnsTrueWhenAbsenceTypeAllowsCancellationForStaff() { | ||
$absenceType = AbsenceTypeFabricator::fabricate(['allow_request_cancelation' => AbsenceType::REQUEST_CANCELATION_ALWAYS]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation is a bit strange, maybe you could put the array on the next line?
@@ -499,6 +500,18 @@ private function getLeaveRequestService($isAdmin = false, $isManager = false, $a | |||
); | |||
} | |||
|
|||
private function getLeaveRequestServiceForWhenAbsenceTypeCannotBeCancelled($typeId, $contactID, $leaveFromDate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe put the arguments on separate lines since this is very long?
private function getLeaveRequestServiceForWhenAbsenceTypeCannotBeCancelled($typeId, $contactID, $leaveFromDate) { | ||
$leaveRightsService = $this->prophesize(LeaveRequestRightsService::class); | ||
$leaveRightsService->canCreateAndUpdateFor($contactID)->willReturn(TRUE); | ||
$leaveRightsService->canCancelForAbsenceType($typeId, $contactID, new DateTime($leaveFromDate))->willReturn(FALSE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long line, maybe split?
@@ -1116,7 +1129,8 @@ public function testGetBreakdownIncludeOnlyTheLeaveBalanceChangesOfTheLeaveReque | |||
public function testToilRequestWithPastDatesCanNotBeCancelledWhenUserIsLeaveContactAndAbsenceTypeDoesNotAllowPastAccrual() { | |||
$absenceType = AbsenceTypeFabricator::fabricate([ | |||
'allow_accruals_request' => true, | |||
'allow_accrue_in_the_past' => false | |||
'allow_accrue_in_the_past' => false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
boolean case (and more in this file) - I think maybe we skipped this before but it should be fixed for all bools in this file at some point
$leaveRequestService = $this->getLeaveRequestServiceForWhenAbsenceTypeCannotBeCancelled( | ||
$params['type_id'], $params['contact_id'], $params['from_date']); | ||
|
||
$this->setExpectedException(RuntimeException::class, 'You cannot cancel leave requests for this Absence type'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long line, and above on 1264
if ($absenceType->allow_request_cancelation != AbsenceType::REQUEST_CANCELATION_NO && | ||
$leaveFromDate > $today | ||
) { | ||
$absenceTypeRequestCancellationNotNo = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to be picky about this but NotNo
seems like it's possible to be improved, would it be possible to name this something like absenceTypeAllowsCancellation
?
85d88bf
to
38f1808
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
Overview
There are Absence type settings that determine whether a Leave request for that absence type can be cancelled or not. Currently the Admin and Leave manager can cancel leave requests irrespective of whether the Absence type allows it or not, however they cannot do so for their own requests. Other staff not Admin or Leave manager are bound by the
Can staff cancel requests for this leave type after they have been made?
setting of the Absence Type.This PR makes the changes needed to allow Admins and Leave managers who are their own leave approvers cancel own requests irrespective of whether the absence type allows it or not.
Before
After
Technical Details
validateAbsenceTypeAllowRequestCancellationForLeaveRequestCancellation
method of the LeaveRequest BAO is what determines who can cancel a leave request based on the Absence typeallow_request_cancelation
value. Since the checks will now involve roles and relationships, This method was removed and a new method that does similarly,canCancelForAbsenceType
was added in theLeaveRequestRights
service because this service allows checks for user roles and relationships.