Skip to content
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-4002: Allow User Who is Own Leave Approver Take Admin Actions on Own Requests #2792

Conversation

tunbola
Copy link
Contributor

@tunbola tunbola commented Jul 25, 2018

Overview

Sequel to #2780, which allows a user to be assigned as own leave approver irrespective of the role of the user, This PR makes some changes in the way a user interacts with own requests especially when such a user is its own leave approver.
These changes allow a user irrespective of the role to assume the role of a leave manager on own request when the user is own leave approver. For example a Staff that is own leave approver can now cancel, approve and perform the same actions a leave manager can on a leave request for own request.
The new changes are summarised as follows

  • An Admin can manage own requests irrespective of whether he is own leave approver or not
  • A Staff can manage own request only if the staff is own leave approver
  • A Manager can manage own request only if the manager is own leave approver

Before

  • A user cannot manage own requests, i.e the user is treated as a staff when dealing with own request (even if staff is Admin or Manager) and as such cannot perform admin actions, such as approving the request and moving the request to statuses that is allowed for a manger.

After

  • A user can now manage own requests when the user is own Leave approver, i.e the user can approve the request and move the request to statuses that a manager can move requests to.
    An Admin can manage own requests irrespective of whether he is own leave approver or not.

Technical Details

  • Once a current user is the leave contact, the getStatusMatrixForCurrentUser of the leave request class would always return a Staff status transition matrix for the user even if the user is an Admin, this method is modified such that it returns the Manager status transition matrix for an Admin and for a user that is the leave contact and is own leave approver instead of returning the Staff status transition matrix.
  private function getStatusMatrixForCurrentUser($leaveRequestContactID) {
    $currentUserID = CRM_Core_Session::getLoggedInContactID();
    $statusMatrix = [];

    if ($this->shouldUseManagerMatrixForCurrentUser($leaveRequestContactID)) {
      $statusMatrix = $this->getManagerStatusMatrix();
    } elseif ($currentUserID == $leaveRequestContactID) {
      $statusMatrix = $this->getStaffStatusMatrix();
    }

    return $statusMatrix;
  }

tunbola added 2 commits July 25, 2018 16:08
…when he is own leave approver or an Admin. Add tests. Remove un-used test.
…ns set in earlier tests, Fixed by setting permission to empty.
@tunbola tunbola force-pushed the PCHR-4002-leave-approver-admin-actions branch from da2c2cd to 2cf519c Compare July 25, 2018 15:09
@mickadoo
Copy link
Contributor

I think there might be a typo in

A Manager can manage own request only of the manager is own leave approver

Copy link
Contributor

@mickadoo mickadoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 small things

@@ -2962,6 +2962,7 @@ public function testLeaveRequestIsValidShouldReturnAnErrorWhenTheToilToAccrueDoe
}

public function testToilCanBeAccruedWhenToilIsInHoursAndToilToAccrueValueIsNotAValidToilAmountOptionValue() {
$this->setPermissions();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this added to tests in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some previous tests that ran set the permissions to that of an Admin. Also the same contact logged in is the leave contact for the test, so the test was assuming that the contact is an Admin that is trying to take actions on own request and an Admin cannot create a leave request with Awaiting approval status (status 3) based on the Manager status transition matrix. I simply set the permission to null which is what is needed when running the test for a staff for the purpose of this test.


$this->assertTrue($this->leaveRequestStatusMatrix->canTransitionTo($fromStatus, $toStatus, $adminID));
foreach($nonPossibleTransitions as $transition) {
$this->assertFalse($this->leaveRequestStatusMatrix->canTransitionTo($transition[0], $transition[1], $adminID));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few lines like this are pretty long, do you think you could split the arguments onto separate lines?

Copy link
Contributor

@mickadoo mickadoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good 🐧

@tunbola tunbola merged commit b8fe30f into PCHR-3997-allow-own-leave-approver Jul 25, 2018
@tunbola tunbola deleted the PCHR-4002-leave-approver-admin-actions branch July 25, 2018 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants