Skip to content
Merged
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
12 changes: 12 additions & 0 deletions SPECIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---

Expand Down
5 changes: 4 additions & 1 deletion lib/Controller/EmployeeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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] = [
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/CalendarService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/CarryOverReminderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/CoverageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)));
}

/**
Expand Down
80 changes: 80 additions & 0 deletions lib/Service/EmployeeDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<string,true>|null uid => disabled, read once per request */
private ?array $disabled = null;

public function __construct(
private IUserManager $userManager,
Expand Down Expand Up @@ -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<string, string>
*/
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<string,true>
*/
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.
*
Expand Down
8 changes: 6 additions & 2 deletions lib/Service/EmployeeListService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)],
Expand Down
10 changes: 5 additions & 5 deletions lib/Service/EntitlementService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion lib/Service/InsightsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct(
* @return array<string,mixed>
*/
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);
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/RegionReminderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/ReportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function balancesReport(int $year, ?string $group = null): array {
* @return list<array<string,mixed>>
*/
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) {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions src/types/employees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 15 additions & 3 deletions src/views/hr/HrEmployees.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@
hideStatus />
{{ row.displayName }}
</router-link>
<NcChip
v-if="row.disabled"
class="employees__left"
noClose
:text="t('absence', 'Account disabled')" />
</td>
<td>
<template v-if="row.regionCode">
Expand All @@ -129,7 +134,7 @@
:text="t('absence', 'Region needed')" />
</template>
<NcChip
v-else
v-else-if="!row.disabled"
variant="warning"
noClose
:text="t('absence', 'No region code')" />
Expand All @@ -154,7 +159,7 @@
{{ formatDate(row.contract.start) }}
</template>
<NcChip
v-else
v-else-if="!row.disabled"
variant="warning"
noClose
:text="t('absence', 'No start date')" />
Expand Down Expand Up @@ -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 {
Expand All @@ -305,6 +310,7 @@ const matches: Record<FilterId, (row: EmployeeRow) => boolean> = {
missing: (row) => row.missing.length > 0,
partTime: (row) => row.partTime,
startsOrLeaves: (row) => row.startsOrLeaves,
disabled: (row) => row.disabled,
}

const currentYear = new Date().getFullYear()
Expand Down Expand Up @@ -335,6 +341,7 @@ const filters = computed<FilterOption[]>(() => {
{ 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) }) }] : []),
]
})

Expand Down Expand Up @@ -448,6 +455,11 @@ async function onSaved(): Promise<void> {
gap: 10px;
}

&__left {
margin-inline-start: 8px;
vertical-align: middle;
}

&__none {
color: var(--color-text-maxcontrast);
}
Expand Down
Loading
Loading