Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions SPECIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1318,8 +1318,10 @@ All four channels are required.
new request (→ manager), decision made (→ employee), escalation (→ HR),
reminder (→ manager), withdrawal request (→ the manager who can decide it and is not away today, else
HR; one the manager leaves unanswered for the escalation window reaches HR once), **comment added**
(→ the employee and their manager, plus HR once the request has been escalated;
never back to the comment's own author), **replacement assigned**
(→ the employee and their manager, plus HR once the request has been escalated:
the HR members who took it up by deciding or commenting, all of HR while nobody
has; on a confidential absence HR only, by the same rule; never back to the
comment's own author), **replacement assigned**
(→ replacement, on approval) and **replacement cancelled** (→ replacement, when
approved leave is cancelled) — §5.1, and **absence recorded by HR** (→ the
employee's line manager, dates only, no leave type and no reason; §5.6). These are pushed (a standard NC notification is
Expand Down
18 changes: 16 additions & 2 deletions lib/Service/RequestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1418,15 +1418,29 @@ private function commentRecipients(LeaveRequest $request): array {
// hides comments from the employee and manager, so their content must not be
// pushed out by notification/email either. Only HR hears about it.
if ($this->permission->isHrOnlyRequest($request)) {
return array_values(array_unique(array_filter($this->permission->getHrUids())));
return $this->involvedHr($request);
}
$recipients = [$request->getEmployeeUid(), (string)$this->managerResolver->getManagerUid($request->getEmployeeUid())];
if ($request->getEscalated()) {
$recipients = [...$recipients, ...$this->permission->getHrUids()];
$recipients = [...$recipients, ...$this->involvedHr($request)];
}
return array_values(array_unique(array_filter($recipients)));
}

/**
* The HR members who took the request up, by deciding it or commenting on it;
* all of HR while nobody has, as somebody still has to.
*
* @return list<string>
*/
private function involvedHr(LeaveRequest $request): array {
$hr = array_values(array_unique(array_filter($this->permission->getHrUids())));
$involved = array_map(static fn (RequestComment $comment): string => $comment->getAuthorUid(), $this->commentMapper->findForRequest((int)$request->getId()));
$involved[] = (string)$request->getDecidedBy();
$taken = array_values(array_intersect($hr, $involved));
return $taken === [] ? $hr : $taken;
}

// --------------------------------------------------------------- helpers ----

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/Unit/Service/RequestServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,25 @@ public function testAddCommentOnAnEscalatedRequestAlsoReachesHr(): void {
$this->service->addComment('emp', 5, 'Any news on this?');
}

public function testOnceSomebodyInHrTookAnEscalatedRequestUpOnlyTheyHearOfComments(): void {
$request = $this->pendingOwnRequest();
$request->setManagerUid('boss');
$request->setEscalated(true);
$this->managerResolver->method('getManagerUid')->with('emp')->willReturn('boss');
$this->requestMapper->method('find')->with(5)->willReturn($request);
$this->permission->method('canView')->willReturn(true);
$this->permission->method('getHrUids')->willReturn(['hr1', 'hr2', 'hr3']);
$this->commentMapper->method('insert')->willReturnArgument(0);
$asked = new RequestComment();
$asked->setAuthorUid('hr2');
$this->commentMapper->method('findForRequest')->willReturn([$asked]);

$this->notifications->expects(self::once())->method('notifyComment')
->with($request, self::anything(), ['emp', 'boss', 'hr2']);

$this->service->addComment('emp', 5, 'Here is the certificate.');
}

public function testDecliningAWithdrawalPassesTheReasonToTheEmployee(): void {
// The reason is recorded as a comment, not in decision_comment, so unless it
// travels with the notification the employee is told "declined" and nothing more.
Expand Down
Loading