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-3820: Add Leave Request ACL Rules to LeaveRequest.getAttachments API #2682

Merged
merged 6 commits into from
Jun 14, 2018

Conversation

tunbola
Copy link
Contributor

@tunbola tunbola commented Jun 12, 2018

Overview

Currently the LeaveRequest.getAttachments API allows a staff to view leave attachments for another staff. This PR incorporates the Leave ACL rules into this API, basically, A staff should only be able to view own attachments, A manager should be able to view attachments for managees only while Admin can view leave attachments for all contacts leave requests.

Before

  • The LeaveRequest.getAttachments API does not return results based on Leave Request ACL rules

After

  • The LeaveRequest.getAttachments API returns results based on Leave Request ACL rules

@tunbola tunbola changed the title PCHR-3820: Add Leave Request ACL Rules to LeaveRequest.getAttchments API PCHR-3820: Add Leave Request ACL Rules to LeaveRequest.getAattchments API Jun 12, 2018
@tunbola tunbola changed the title PCHR-3820: Add Leave Request ACL Rules to LeaveRequest.getAattchments API PCHR-3820: Add Leave Request ACL Rules to LeaveRequest.getAttachments API Jun 12, 2018
@@ -4370,24 +4370,40 @@ public function testGetAttachmentsShouldThrowAnExceptionIfLeaveRequestIDIsMissin
}

public function testGetAttachments() {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we still need this test if with all new ones you've added. What does it have that the others don't?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tbh, I wanted to remove it but the reason I left i was because the test checks for all the expected fields that the API is expected to return which the others don't. I could remove it though. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe then it would make more sense to rename this method to better clarify that it is more about the fields? Or create some custom assert method that checks all the fields, reuse it in the other tests and delete this one.

}

return [];
}
Copy link
Member

Choose a reason for hiding this comment

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

Please also write tests for this method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking it will be a duplication of the tests for the LeaveRequest.getAttachments API, since this API uses this method directly.

I could modify this method to accept params and also the LeaveRequestRights service so that I can mock that and pass it in the function but I would still have to create leave requests and all. What do you suggest?

Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately, because of how the API works, there's no way to avoid this duplication. The tests wouldn't be completely duplicated though, since, as you said, you can mock a few things. In this case it's better to have some duplication than not having tests for this method

$this->assertEquals($staff1Attachment['values'][0]['id'], $attachment1['id']);
$this->assertEquals($staff1Attachment['values'][0]['name'], $attachment1['name']);

$this->assertCount(1, $staff1Attachment['values']);
Copy link
Member

Choose a reason for hiding this comment

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

I believe this should actually be $staff2Attachment, right?

Copy link
Contributor Author

@tunbola tunbola Jun 13, 2018

Choose a reason for hiding this comment

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

Yes, Good catch

CRM_Core_Config::singleton()->userPermissionClass->permissions = ['administer leave and absences'];
$leaveManagerService = $this->getLeaveManagerServiceWhenUserIsAdmin();
$leaveRequestRights = new LeaveRightsService($leaveManagerService);
$leaveRequestAttachmentService = new LeaveRequestAttachmentService($leaveRequestRights, $leaveManagerService);
Copy link
Member

Choose a reason for hiding this comment

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

This instantiation code is duplicated in a few places. What do you think of moving it to a createLeaveRequestAttachmentsServiceWhenUserIsAdmin() (I know, a bit too long, but quite descriptive and still shorter than 3 lines of code)

@tunbola tunbola merged commit 2708605 into staging Jun 14, 2018
@tunbola tunbola deleted the PCHR-3820-leave-attachments-acl-fix branch June 14, 2018 17:17
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