diff --git a/SPECIFICATION.md b/SPECIFICATION.md index 3d2c570..376dd43 100644 --- a/SPECIFICATION.md +++ b/SPECIFICATION.md @@ -173,6 +173,18 @@ calendar forever, with an empty allowance and nothing to show. deleted later, the app **fails open** (every non-guest account counts again) and logs an error — failing closed would silently freeze leave booking for the whole company. +- **Disabled accounts are people who left.** They stay employees for their records: + HR still sees them on the Employees page (marked *Account disabled*, with a + filter), can open, correct and record their leave, finds them in the people + picker, and exports them with the requests. Nothing about the people working here + now counts them: they are left out of Insights and every report (balances + included), coverage, the team calendar, the pickers of everyone but HR, the + region and carry-over reminders, a change of the default vacation days, the bulk + entitlement edit and the year rollover. Their row never shows missing data. + `EmployeeDirectory::listActive()` and friends read the disabled accounts once per + request (`IUserManager::getDisabledUsers()`), not account by account. Retention + still counts from the contract end date only, so disabling an account by mistake + starts no deletion. Enabling the account again brings the person back everywhere. --- diff --git a/lib/Controller/EmployeeController.php b/lib/Controller/EmployeeController.php index aa5cdd5..ad8536f 100644 --- a/lib/Controller/EmployeeController.php +++ b/lib/Controller/EmployeeController.php @@ -151,6 +151,9 @@ public function search(string $search = '', int $limit = 20): DataResponse { $results['users'] ?? [], ); + // HR may still record or correct the leave of somebody who left; for + // everyone else a disabled account is nobody to pick. + $isHr = $this->permission->isHr((string)$this->userId); $employees = []; // First, because somebody typing their own name has matched it exactly and // should not be pushed below looser matches on it. @@ -164,7 +167,7 @@ public function search(string $search = '', int $limit = 20): DataResponse { if ($uid === '' || isset($employees[$uid])) { continue; } - if (!$this->employees->isEmployee($uid)) { + if (!($isHr ? $this->employees->isEmployee($uid) : $this->employees->isActive($uid))) { continue; } $employees[$uid] = [ diff --git a/lib/Service/CalendarService.php b/lib/Service/CalendarService.php index 64f0738..1b33b72 100644 --- a/lib/Service/CalendarService.php +++ b/lib/Service/CalendarService.php @@ -105,7 +105,7 @@ public function teamEvents(string $uid): array { } $year = $this->clock->serverYear(); $requests = $this->requestMapper->findInForceBetween(($year - 1) . '-01-01', ($year + 1) . '-12-31'); - $names = $this->employees->displayNames(); + $names = $this->employees->activeDisplayNames(); $l = $this->personalL10n($uid); $reveal = $this->config->getSharedCalendarVisibility() === ConfigService::VISIBILITY_REVEAL; $events = []; diff --git a/lib/Service/CarryOverReminderService.php b/lib/Service/CarryOverReminderService.php index 62bfe87..8f6b775 100644 --- a/lib/Service/CarryOverReminderService.php +++ b/lib/Service/CarryOverReminderService.php @@ -66,7 +66,7 @@ public function remind(): int { // Confidential types (§5.7) are not on the employee's own balance either. $hrOnlyIds = $this->leaveTypeMapper->hrOnlyTypeIds(); $reminded = 0; - foreach ($this->balanceService->getBalancesForEmployees($this->employees->listAll(), $year) as $uid => $rows) { + foreach ($this->balanceService->getBalancesForEmployees($this->employees->listActive(), $year) as $uid => $rows) { $days = 0.0; foreach ($rows as $row) { if (!in_array($row['typeId'], $hrOnlyIds, true)) { diff --git a/lib/Service/CoverageService.php b/lib/Service/CoverageService.php index dd061c5..4ff281a 100644 --- a/lib/Service/CoverageService.php +++ b/lib/Service/CoverageService.php @@ -55,7 +55,7 @@ public function resolveScopeUids(string $actorUid, string $scope, bool $withOwnM return []; } if ($scope === self::SCOPE_COMPANY && $this->permission->isHr($actorUid)) { - return $this->employees->listAll(); + return $this->employees->listActive(); } // Team scope: the actor's reports if they manage, otherwise their peers + self. $reports = $this->managerResolver->getDirectReports($actorUid); @@ -243,7 +243,7 @@ private function teammateUids(string $uid): array { ...($managerUid !== null ? [$managerUid] : []), ...$this->managerResolver->getDirectReports($uid), ]); - return $this->employees->filter(array_values(array_filter($uids, static fn (string $other): bool => $other !== $uid))); + return $this->employees->filterActive(array_values(array_filter($uids, static fn (string $other): bool => $other !== $uid))); } /** diff --git a/lib/Service/EmployeeDirectory.php b/lib/Service/EmployeeDirectory.php index d231f90..410fdb9 100644 --- a/lib/Service/EmployeeDirectory.php +++ b/lib/Service/EmployeeDirectory.php @@ -36,6 +36,12 @@ * it also bounds what {@see listAll()} has to enumerate: reading one group * beats walking the whole user backend on a large LDAP instance. * + * A **disabled account** is still an employee here: HR keeps the records of + * people who left, can correct them and exports them. Everything about the + * people who work here now (reports, coverage, pickers, the team calendar, + * reminders and the rollover) asks for the *active* employees instead + * ({@see listActive()}, {@see isActive()}), which leave disabled accounts out. + * * A guest is a user in the Guests app's own user backend, which is what * `OCA\Guests\GuestManager::isGuest()` checks too. Reading the backend name * keeps this app free of a hard dependency on the Guests app: with the app @@ -53,6 +59,8 @@ class EmployeeDirectory { private array $guestCache = []; /** Employees-group id resolved once per request; null = not resolved yet. */ private ?string $employeesGroup = null; + /** @var array|null uid => disabled, read once per request */ + private ?array $disabled = null; public function __construct( private IUserManager $userManager, @@ -193,6 +201,78 @@ public function isGuest(string $uid): bool { return $user !== null && $this->isGuestUser($user); } + /** + * Every employee whose account is enabled: the people who work here now. + * + * @return string[] + */ + public function listActive(): array { + return $this->withoutDisabled($this->listAll()); + } + + /** + * {@see listInGroup()}, without the disabled accounts. + * + * @return string[] + */ + public function listActiveInGroup(?string $group): array { + return $this->withoutDisabled($this->listInGroup($group)); + } + + /** + * {@see displayNames()}, without the disabled accounts. + * + * @return array + */ + public function activeDisplayNames(): array { + return array_diff_key($this->displayNames(), $this->disabledUids()); + } + + /** Whether this uid is an employee whose account is enabled. */ + public function isActive(string $uid): bool { + return $this->isEmployee($uid) && !isset($this->disabledUids()[$uid]); + } + + /** Whether this uid's account is disabled, false for an unknown uid. */ + public function isDisabled(string $uid): bool { + return isset($this->disabledUids()[$uid]); + } + + /** + * {@see filter()}, without the disabled accounts. + * + * @param string[] $uids + * @return string[] + */ + public function filterActive(array $uids): array { + return $this->withoutDisabled($this->filter($uids)); + } + + /** + * @param string[] $uids + * @return string[] + */ + private function withoutDisabled(array $uids): array { + $disabled = $this->disabledUids(); + return array_values(array_filter($uids, static fn (string $uid): bool => !isset($disabled[$uid]))); + } + + /** + * The disabled accounts, read in one call rather than account by account, + * which on LDAP would cost a lookup per person. + * + * @return array + */ + private function disabledUids(): array { + if ($this->disabled === null) { + $this->disabled = []; + foreach ($this->userManager->getDisabledUsers() as $user) { + $this->disabled[$user->getUID()] = true; + } + } + return $this->disabled; + } + /** * Filter a list of uids down to the employees in it, preserving order. * diff --git a/lib/Service/EmployeeListService.php b/lib/Service/EmployeeListService.php index 1686bcf..fce3dd8 100644 --- a/lib/Service/EmployeeListService.php +++ b/lib/Service/EmployeeListService.php @@ -93,7 +93,10 @@ public function rows(array $uids, int $year): array { } } $current = self::currentPeriod($contract, $today); - $missing = array_keys(array_filter([ + // Somebody who left keeps their records here, but nothing is missing + // any more: their row never counts towards the data HR has to fill in. + $disabled = $this->directory->isDisabled($uid); + $missing = $disabled ? [] : array_keys(array_filter([ self::MISSING_REGION => $this->holidays->needsRegion($region), self::MISSING_CONTRACT => $contract['periods'] === [], self::MISSING_START => $contract['start'] === null, @@ -102,7 +105,8 @@ public function rows(array $uids, int $year): array { 'uid' => $uid, 'displayName' => $this->displayName($uid), 'regionCode' => $region, - 'regionIncomplete' => $region !== '' && $this->holidays->needsRegion($region), + 'regionIncomplete' => !$disabled && $region !== '' && $this->holidays->needsRegion($region), + 'disabled' => $disabled, 'contract' => $contract, 'current' => $current, 'manager' => $managerUid === null ? null : ['uid' => $managerUid, 'displayName' => $this->displayName($managerUid)], diff --git a/lib/Service/EntitlementService.php b/lib/Service/EntitlementService.php index 5ef6315..e744a03 100644 --- a/lib/Service/EntitlementService.php +++ b/lib/Service/EntitlementService.php @@ -241,7 +241,7 @@ private function onDefault(float $days): array { if ($annualTypeId === null) { return []; } - $employees = array_fill_keys($this->employees->listAll(), true); + $employees = array_fill_keys($this->employees->listActive(), true); return array_values(array_filter( $this->entitlementMapper->findForYear($this->clock->serverYear()), static fn (Entitlement $ent): bool => $ent->getTypeId() === $annualTypeId @@ -364,7 +364,7 @@ public function rollover(int $fromYear): array { $annualTypeId = $this->annualTypeId(); if ($annualTypeId !== null) { $default = $this->config->getDefaultEntitlement(); - foreach ($this->employees->listAll() as $uid) { + foreach ($this->employees->listActive() as $uid) { $targets[$uid][$annualTypeId] ??= $default; } } @@ -380,8 +380,8 @@ public function rollover(int $fromYear): array { foreach ($targets as $uid => $perType) { $uid = (string)$uid; // No entitlement for a year outside the contract (§6.4), and no carry-over - // from one - if (!$this->balanceService->isEmployedIn($uid, $toYear)) { + // from one. Nor for somebody whose account is disabled: they left. + if (!$this->balanceService->isEmployedIn($uid, $toYear) || $this->employees->isDisabled($uid)) { continue; } $carriesOver = $this->balanceService->isEmployedIn($uid, $fromYear); @@ -642,6 +642,6 @@ private function assertCountingType(int $typeId): void { * @return string[] */ private function targetUids(?string $group): array { - return $this->employees->listInGroup($group); + return $this->employees->listActiveInGroup($group); } } diff --git a/lib/Service/InsightsService.php b/lib/Service/InsightsService.php index afa48ff..fc190ff 100644 --- a/lib/Service/InsightsService.php +++ b/lib/Service/InsightsService.php @@ -47,7 +47,7 @@ public function __construct( * @return array */ public function getInsights(int $year): array { - $uids = $this->employees->listInGroup(null); + $uids = $this->employees->listActiveInGroup(null); $uidSet = array_fill_keys($uids, true); $teams = $this->buildTeams($uids); $balances = $this->balanceService->getBalancesForEmployees($uids, $year); diff --git a/lib/Service/RegionReminderService.php b/lib/Service/RegionReminderService.php index cfdc4db..655faba 100644 --- a/lib/Service/RegionReminderService.php +++ b/lib/Service/RegionReminderService.php @@ -49,7 +49,7 @@ public function plan(): array { $since = $this->clock->now()->getTimestamp() - self::QUIET_SECONDS; $remindedAt = $this->userConfig->getValuesByUsers(ConfigService::APP_ID, ConfigLexicon::KEY_REGION_REMINDED_AT, ValueType::INT); $plan = ['send' => [], 'recent' => []]; - foreach ($this->employees->listAll() as $uid) { + foreach ($this->employees->listActive() as $uid) { $uid = (string)$uid; $code = $codes[$uid] ?? ''; if (!$this->holidays->needsRegion($code)) { diff --git a/lib/Service/ReportService.php b/lib/Service/ReportService.php index 855eb4c..8bf53d5 100644 --- a/lib/Service/ReportService.php +++ b/lib/Service/ReportService.php @@ -67,7 +67,7 @@ public function balancesReport(int $year, ?string $group = null): array { * @return list> */ public function teamBalances(string $managerUid, int $year): array { - $uids = $this->employees->filter($this->managerResolver->getDirectReports($managerUid)); + $uids = $this->employees->filterActive($this->managerResolver->getDirectReports($managerUid)); $balances = $this->balanceService->getBalancesForEmployees($uids, $year); $report = []; foreach ($uids as $uid) { @@ -266,7 +266,7 @@ private function sickLeaveTypes(?int $typeId): array { * @return string[] */ private function employeeUids(?string $group): array { - return $this->employees->listInGroup($group); + return $this->employees->listActiveInGroup($group); } private function displayName(string $uid): string { diff --git a/src/types/employees.ts b/src/types/employees.ts index 98a90fb..7d3c1c4 100644 --- a/src/types/employees.ts +++ b/src/types/employees.ts @@ -145,6 +145,8 @@ export interface EmployeeRow { regionCode: string /** A country-only code while that country has regional holidays in the list. */ regionIncomplete: boolean + /** The account is disabled: somebody who left, kept for the records */ + disabled: boolean contract: Contract /** The working pattern in force today, or the first one while none has started; null without any. */ current: ContractPeriod | null diff --git a/src/views/hr/HrEmployees.vue b/src/views/hr/HrEmployees.vue index 734c57b..debd44e 100644 --- a/src/views/hr/HrEmployees.vue +++ b/src/views/hr/HrEmployees.vue @@ -118,6 +118,11 @@ hideStatus /> {{ row.displayName }} + @@ -154,7 +159,7 @@ {{ formatDate(row.contract.start) }} @@ -283,7 +288,7 @@ import { formatNumber } from '../../utils/locale.ts' import { regionFlag } from '../../utils/regions.ts' import { formatWeekdays } from '../../utils/weekdays.ts' -type FilterId = 'all' | 'missing' | 'partTime' | 'startsOrLeaves' +type FilterId = 'all' | 'missing' | 'partTime' | 'startsOrLeaves' | 'disabled' /** A chip of the filter row */ interface FilterOption { @@ -305,6 +310,7 @@ const matches: Record boolean> = { missing: (row) => row.missing.length > 0, partTime: (row) => row.partTime, startsOrLeaves: (row) => row.startsOrLeaves, + disabled: (row) => row.disabled, } const currentYear = new Date().getFullYear() @@ -335,6 +341,7 @@ const filters = computed(() => { { id: 'missing', label: `⚠️ ${n('absence', 'Missing data {count}', 'Missing data {count}', count(matches.missing), { count: count(matches.missing) })}` }, { id: 'partTime', label: n('absence', 'Part-time {count}', 'Part-time {count}', count(matches.partTime), { count: count(matches.partTime) }) }, { id: 'startsOrLeaves', label: n('absence', 'Starts or leaves in {year} {count}', 'Starts or leaves in {year} {count}', count(matches.startsOrLeaves), { year: year.value, count: count(matches.startsOrLeaves) }) }, + ...(count(matches.disabled) > 0 ? [{ id: 'disabled' as const, label: n('absence', 'Account disabled {count}', 'Account disabled {count}', count(matches.disabled), { count: count(matches.disabled) }) }] : []), ] }) @@ -448,6 +455,11 @@ async function onSaved(): Promise { gap: 10px; } + &__left { + margin-inline-start: 8px; + vertical-align: middle; + } + &__none { color: var(--color-text-maxcontrast); } diff --git a/tests/Integration/DisabledAccountsTest.php b/tests/Integration/DisabledAccountsTest.php new file mode 100644 index 0000000..6c0a14e --- /dev/null +++ b/tests/Integration/DisabledAccountsTest.php @@ -0,0 +1,83 @@ +get($uid) ?? $users->createUser($uid, 'Itest-Password-disabled-1'))->setDisplayName('Itest ' . $uid); + } + $users->get(self::LEFT)->setEnabled(false); + } + + protected function tearDown(): void { + foreach ([self::ACTIVE, self::LEFT] as $uid) { + Server::get(IUserManager::class)->get($uid)?->delete(); + } + parent::tearDown(); + } + + public function testTheDirectoryKeepsThemAsEmployeesButNotAsActiveOnes(): void { + $directory = Server::get(EmployeeDirectory::class); + + self::assertTrue($directory->isEmployee(self::LEFT)); + self::assertContains(self::LEFT, $directory->listAll()); + self::assertArrayHasKey(self::LEFT, $directory->displayNames()); + + self::assertFalse($directory->isActive(self::LEFT)); + self::assertTrue($directory->isDisabled(self::LEFT)); + self::assertNotContains(self::LEFT, $directory->listActive()); + self::assertNotContains(self::LEFT, $directory->listActiveInGroup(null)); + self::assertArrayNotHasKey(self::LEFT, $directory->activeDisplayNames()); + self::assertSame([self::ACTIVE], $directory->filterActive([self::LEFT, self::ACTIVE])); + + self::assertTrue($directory->isActive(self::ACTIVE)); + self::assertContains(self::ACTIVE, $directory->listActive()); + } + + public function testHrStillSeesThemWithNothingMissing(): void { + $rows = Server::get(EmployeeListService::class)->rows([self::ACTIVE, self::LEFT], self::YEAR); + [$active, $left] = $rows; + + self::assertTrue($left['disabled']); + self::assertSame([], $left['missing']); + self::assertFalse($left['regionIncomplete']); + + self::assertFalse($active['disabled']); + self::assertNotSame([], $active['missing']); + } + + public function testReportsAndInsightsLeaveThemOut(): void { + $report = Server::get(ReportService::class)->balancesReport(self::YEAR); + self::assertNotContains(self::LEFT, array_column($report, 'employeeUid')); + self::assertContains(self::ACTIVE, array_column($report, 'employeeUid')); + + $insights = json_encode(Server::get(InsightsService::class)->getInsights(self::YEAR), JSON_THROW_ON_ERROR); + self::assertStringNotContainsString(self::LEFT, $insights); + } +} diff --git a/tests/Unit/Controller/EmployeeControllerTest.php b/tests/Unit/Controller/EmployeeControllerTest.php index 8450579..a77f816 100644 --- a/tests/Unit/Controller/EmployeeControllerTest.php +++ b/tests/Unit/Controller/EmployeeControllerTest.php @@ -73,6 +73,7 @@ public function testSearchIncludesTheSigningInUserWhenTheyMatch(): void { $this->collaboratorSearchReturns([]); $this->selfIs('Frank Karlitschek'); $this->employees->method('isEmployee')->willReturn(true); + $this->employees->method('isActive')->willReturn(true); $data = $this->controller->search('frank')->getData(); @@ -83,6 +84,7 @@ public function testSearchMatchesTheSigningInUserByUid(): void { $this->collaboratorSearchReturns([]); $this->selfIs('Frank Karlitschek'); $this->employees->method('isEmployee')->willReturn(true); + $this->employees->method('isActive')->willReturn(true); self::assertSame('hr-user', $this->controller->search('hr-us')->getData()[0]['uid']); } @@ -93,6 +95,7 @@ public function testSearchLeavesTheSigningInUserOutWhenTheyDoNotMatch(): void { ]); $this->selfIs('Frank Karlitschek'); $this->employees->method('isEmployee')->willReturn(true); + $this->employees->method('isActive')->willReturn(true); $data = $this->controller->search('lea')->getData(); @@ -104,6 +107,7 @@ public function testSearchNeverOffersTheSigningInUserWhenTheyAreAGuest(): void { $this->selfIs('Guest Person'); // Guests hold no entitlement and take no leave, their own account included. $this->employees->method('isEmployee')->willReturn(false); + $this->employees->method('isActive')->willReturn(false); self::assertSame([], $this->controller->search('guest')->getData()); } @@ -115,6 +119,7 @@ public function testSearchDoesNotListTheSigningInUserTwice(): void { ]); $this->selfIs('Frank Karlitschek'); $this->employees->method('isEmployee')->willReturn(true); + $this->employees->method('isActive')->willReturn(true); self::assertCount(1, $this->controller->search('frank')->getData()); } diff --git a/tests/Unit/Service/CalendarServiceTest.php b/tests/Unit/Service/CalendarServiceTest.php index c434cdc..2a15627 100644 --- a/tests/Unit/Service/CalendarServiceTest.php +++ b/tests/Unit/Service/CalendarServiceTest.php @@ -50,7 +50,7 @@ protected function setUp(): void { $this->permission = $this->createMock(PermissionService::class); $this->permission->method('isEmployeeOrHr')->willReturn(true); $this->employees = $this->createMock(EmployeeDirectory::class); - $this->employees->method('displayNames')->willReturn(['alice' => 'Alice Example', 'bob' => 'Bob Example', '90817' => 'Numeric Example']); + $this->employees->method('activeDisplayNames')->willReturn(['alice' => 'Alice Example', 'bob' => 'Bob Example', '90817' => 'Numeric Example']); $this->clock = $this->createMock(ClockService::class); $this->clock->method('serverYear')->willReturn(2026); $this->l10nFactory = $this->createMock(IFactory::class); diff --git a/tests/Unit/Service/CarryOverReminderServiceTest.php b/tests/Unit/Service/CarryOverReminderServiceTest.php index 9a661ac..9648291 100644 --- a/tests/Unit/Service/CarryOverReminderServiceTest.php +++ b/tests/Unit/Service/CarryOverReminderServiceTest.php @@ -48,7 +48,7 @@ protected function setUp(): void { $this->balances->method('getBalancesForEmployees')->willReturnCallback(fn (): array => $this->rows); $employees = $this->createMock(EmployeeDirectory::class); - $employees->method('listAll')->willReturnCallback(fn (): array => array_keys($this->rows)); + $employees->method('listActive')->willReturnCallback(fn (): array => array_keys($this->rows)); $types = $this->createMock(LeaveTypeMapper::class); $types->method('hrOnlyTypeIds')->willReturn([9]); diff --git a/tests/Unit/Service/InsightsServiceTest.php b/tests/Unit/Service/InsightsServiceTest.php index 2284571..6113907 100644 --- a/tests/Unit/Service/InsightsServiceTest.php +++ b/tests/Unit/Service/InsightsServiceTest.php @@ -46,7 +46,7 @@ protected function setUp(): void { // can key on the uid without standing up fake user objects. $userManager->method('get')->willReturn(null); - $this->employees->method('listInGroup')->willReturn(['alice', 'bob', 'carol']); + $this->employees->method('listActiveInGroup')->willReturn(['alice', 'bob', 'carol']); $this->managerResolver->method('getManagerUidsOf')->willReturnCallback( static fn (array $uids): array => array_combine($uids, array_map(static fn (string $uid): ?string => $uid === 'carol' ? null : 'mgr1', $uids)), );