-
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-3820: Add Leave Request ACL Rules to LeaveRequest.getAttachments API #2682
Conversation
@@ -4370,24 +4370,40 @@ public function testGetAttachmentsShouldThrowAnExceptionIfLeaveRequestIDIsMissin | |||
} | |||
|
|||
public function testGetAttachments() { |
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.
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?
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.
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?
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 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 []; | ||
} |
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.
Please also write tests for this method
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.
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?
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.
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']); |
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.
I believe this should actually be $staff2Attachment
, right?
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.
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); |
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 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)
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
After