Skip to content

Commit

Permalink
PCHR-3039: Allow admins to change Absence Type of open Leave Requests
Browse files Browse the repository at this point in the history
  • Loading branch information
davialexandre committed Oct 5, 2018
1 parent b435559 commit b469ab6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ public function canChangeDatesFor($contactID, $statusID, $requestType) {
*/
public function canChangeAbsenceTypeFor($contactID, $statusID) {
$isOpenLeaveRequest = in_array($statusID, LeaveRequest::getOpenStatuses());
$isLeaveContactOrAdmin = $this->currentUserIsLeaveContact($contactID) || $this->currentUserIsAdmin();

return $this->currentUserIsLeaveContact($contactID) && $isOpenLeaveRequest;
return $isLeaveContactOrAdmin && $isOpenLeaveRequest;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,24 +228,45 @@ public function testCanChangeAbsenceTypeForReturnsFalseWhenCurrentUserIsLeaveCon
}

/**
* @dataProvider leaveRequestStatusesDataProvider
* @dataProvider openLeaveRequestStatusesDataProvider
*/
public function testCanChangeAbsenceTypeForReturnsFalseWhenCurrentUserNotLeaveContactIrrespectiveOfStatusPassed($status) {
public function testCanChangeAbsenceTypeForReturnsTrueWhenCurrentUserIsAdminAndTheLeaveRequestIsOpen($status) {
$contactID = 2;

$this->assertFalse(
$this->getLeaveRequestRightsForLeaveManagerAsCurrentUser()->canChangeAbsenceTypeFor(
$this->assertTrue(
$this->getLeaveRequestRightsForAdminAsCurrentUser()->canChangeAbsenceTypeFor(
$contactID,
$status
)
);
}

/**
* @dataProvider closedLeaveRequestStatusesDataProvider
*/
public function testCanChangeAbsenceTypeForReturnsFalseWhenCurrentUserIsAdminAndTheLeaveRequestIsClosed($status) {
$contactID = 2;

$this->assertFalse(
$this->getLeaveRequestRightsForAdminAsCurrentUser()->canChangeAbsenceTypeFor(
$contactID,
$status
)
);
}

/**
* @dataProvider leaveRequestStatusesDataProvider
*/
public function testCanChangeAbsenceTypeForReturnsFalseWhenCurrentUserNotLeaveContactIrrespectiveOfStatusPassed($status) {
$contactID = 2;

$this->assertFalse(
$this->getLeaveRequestRightsForLeaveManagerAsCurrentUser()->canChangeAbsenceTypeFor(
$contactID,
$status
)
);

$this->assertFalse(
$this->getLeaveRightsService()->canChangeAbsenceTypeFor(
Expand Down

0 comments on commit b469ab6

Please sign in to comment.