Skip to content

Commit

Permalink
feat(user:list): Show first_seen in output of user:list --info
Browse files Browse the repository at this point in the history
Also format unknown and never in a better way.

Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc authored and Pytal committed Dec 9, 2024
1 parent 145dd59 commit f102154
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
30 changes: 12 additions & 18 deletions core/Command/User/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}
$groups = $this->groupManager->getUserGroupIds($user);
$firstLogin = $user->getFirstLogin();
$lastLogin = $user->getLastLogin();
if ($firstLogin < 0) {
$firstSeen = 'unknown';
} elseif ($firstLogin === 0) {
$firstSeen = 'never';
} else {
$firstSeen = date(\DateTimeInterface::ATOM, $firstLogin); // ISO-8601
}
if ($lastLogin < 0) {
$lastSeen = 'unknown';
} elseif ($lastLogin === 0) {
$lastSeen = 'never';
} else {
$lastSeen = date(\DateTimeInterface::ATOM, $lastLogin); // ISO-8601
}
$data = [
'user_id' => $user->getUID(),
'display_name' => $user->getDisplayName(),
Expand All @@ -72,15 +56,25 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'groups' => $groups,
'quota' => $user->getQuota(),
'storage' => $this->getStorageInfo($user),
'first_seen' => $firstSeen,
'last_seen' => $lastSeen,
'first_seen' => $this->formatLoginDate($user->getFirstLogin()),
'last_seen' => $this->formatLoginDate($user->getLastLogin()),
'user_directory' => $user->getHome(),
'backend' => $user->getBackendClassName()
];
$this->writeArrayInOutputFormat($input, $output, $data);
return 0;
}

private function formatLoginDate(int $timestamp): string {
if ($timestamp < 0) {
return 'unknown';
} elseif ($timestamp === 0) {
return 'never';
} else {
return date(\DateTimeInterface::ATOM, $timestamp); // ISO-8601
}
}

/**
* @param IUser $user
* @return array
Expand Down
13 changes: 12 additions & 1 deletion core/Command/User/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ private function formatUsers(array $users, bool $detailed = false): \Generator {
'enabled' => $user->isEnabled(),
'groups' => $groups,
'quota' => $user->getQuota(),
'last_seen' => date(\DateTimeInterface::ATOM, $user->getLastLogin()), // ISO-8601
'first_seen' => $this->formatLoginDate($user->getFirstLogin()),
'last_seen' => $this->formatLoginDate($user->getLastLogin()),
'user_directory' => $user->getHome(),
'backend' => $user->getBackendClassName()
];
Expand All @@ -93,4 +94,14 @@ private function formatUsers(array $users, bool $detailed = false): \Generator {
yield $user->getUID() => $value;
}
}

private function formatLoginDate(int $timestamp): string {
if ($timestamp < 0) {
return 'unknown';
} elseif ($timestamp === 0) {
return 'never';
} else {
return date(\DateTimeInterface::ATOM, $timestamp); // ISO-8601
}
}
}

0 comments on commit f102154

Please sign in to comment.