From eaa6dbfa86566271ab26690b98dd40e0adad3d1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= <14975046+skjnldsv@users.noreply.github.com> Date: Thu, 3 Dec 2026 12:38:14 +0100 Subject: [PATCH] fix(notifications): comments reach the HR members who took the request up MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Once a request was escalated, every later comment notified and mailed the whole HR team, also after one of them had answered or decided. Comments now go to the HR members who took the request up, by deciding or commenting, and to all of HR only while nobody has. The same holds for confidential absences, where the thread is HR's alone. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: John Molakvoæ <14975046+skjnldsv@users.noreply.github.com> --- SPECIFICATION.md | 6 ++++-- lib/Service/RequestService.php | 18 ++++++++++++++++-- tests/Unit/Service/RequestServiceTest.php | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/SPECIFICATION.md b/SPECIFICATION.md index 3e80c07..a20adff 100644 --- a/SPECIFICATION.md +++ b/SPECIFICATION.md @@ -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 diff --git a/lib/Service/RequestService.php b/lib/Service/RequestService.php index ca8cab3..6f2164a 100644 --- a/lib/Service/RequestService.php +++ b/lib/Service/RequestService.php @@ -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 + */ + 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 ---- /** diff --git a/tests/Unit/Service/RequestServiceTest.php b/tests/Unit/Service/RequestServiceTest.php index becdf55..1de2f37 100644 --- a/tests/Unit/Service/RequestServiceTest.php +++ b/tests/Unit/Service/RequestServiceTest.php @@ -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.