Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat(occ): Show first_seen in output of user:list --info
Also format unknown and never in a better way.

Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Jan 7, 2025
commit 1d0962ab33ce9e6846479ce44381d8cdcb8ad122
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
}
}
}