LDAP: extend remnants output with "detected on" field
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
fbd4e9e651
commit
85f14bc591
|
@ -55,38 +55,49 @@ class ShowRemnants extends Command {
|
||||||
$this
|
$this
|
||||||
->setName('ldap:show-remnants')
|
->setName('ldap:show-remnants')
|
||||||
->setDescription('shows which users are not available on LDAP anymore, but have remnants in Nextcloud.')
|
->setDescription('shows which users are not available on LDAP anymore, but have remnants in Nextcloud.')
|
||||||
->addOption('json', null, InputOption::VALUE_NONE, 'return JSON array instead of pretty table.');
|
->addOption('json', null, InputOption::VALUE_NONE, 'return JSON array instead of pretty table.')
|
||||||
|
->addOption('short-date', null, InputOption::VALUE_NONE, 'show dates in Y-m-d format');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function formatDate(int $timestamp, string $default, bool $showShortDate) {
|
||||||
|
if (!($timestamp > 0)) {
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
if ($showShortDate) {
|
||||||
|
return date('Y-m-d', $timestamp);
|
||||||
|
}
|
||||||
|
return $this->dateFormatter->formatDate($timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* executes the command, i.e. creeates and outputs a table of LDAP users marked as deleted
|
* executes the command, i.e. creates and outputs a table of LDAP users marked as deleted
|
||||||
*
|
*
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected function execute(InputInterface $input, OutputInterface $output) {
|
protected function execute(InputInterface $input, OutputInterface $output) {
|
||||||
/** @var \Symfony\Component\Console\Helper\Table $table */
|
/** @var \Symfony\Component\Console\Helper\Table $table */
|
||||||
$table = new Table($output);
|
$table = new Table($output);
|
||||||
$table->setHeaders(array(
|
$table->setHeaders([
|
||||||
'Nextcloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login',
|
'Nextcloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login',
|
||||||
'Dir', 'Sharer'));
|
'Detected on', 'Dir', 'Sharer'
|
||||||
$rows = array();
|
]);
|
||||||
|
$rows = [];
|
||||||
$resultSet = $this->dui->getUsers();
|
$resultSet = $this->dui->getUsers();
|
||||||
foreach($resultSet as $user) {
|
foreach ($resultSet as $user) {
|
||||||
$hAS = $user->getHasActiveShares() ? 'Y' : 'N';
|
$rows[] = [
|
||||||
$lastLogin = ($user->getLastLogin() > 0) ?
|
'ocName' => $user->getOCName(),
|
||||||
$this->dateFormatter->formatDate($user->getLastLogin()) : '-';
|
'displayName' => $user->getDisplayName(),
|
||||||
$rows[] = array('ocName' => $user->getOCName(),
|
'uid' => $user->getUID(),
|
||||||
'displayName' => $user->getDisplayName(),
|
'dn' => $user->getDN(),
|
||||||
'uid' => $user->getUID(),
|
'lastLogin' => $this->formatDate($user->getLastLogin(), '-', (bool)$input->getOption('short-date')),
|
||||||
'dn' => $user->getDN(),
|
'detectedOn' => $this->formatDate($user->getDetectedOn(), 'unknown', (bool)$input->getOption('short-date')),
|
||||||
'lastLogin' => $lastLogin,
|
'homePath' => $user->getHomePath(),
|
||||||
'homePath' => $user->getHomePath(),
|
'sharer' => $user->getHasActiveShares() ? 'Y' : 'N',
|
||||||
'sharer' => $hAS
|
];
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($input->getOption('json')) {
|
if ($input->getOption('json')) {
|
||||||
$output->writeln(json_encode($rows));
|
$output->writeln(json_encode($rows));
|
||||||
} else {
|
} else {
|
||||||
$table->setRows($rows);
|
$table->setRows($rows);
|
||||||
$table->render($output);
|
$table->render($output);
|
||||||
|
|
|
@ -108,7 +108,13 @@ class DeletedUsersIndex {
|
||||||
* @throws \OCP\PreConditionNotMetException
|
* @throws \OCP\PreConditionNotMetException
|
||||||
*/
|
*/
|
||||||
public function markUser($ocName) {
|
public function markUser($ocName) {
|
||||||
|
$curValue = $this->config->getUserValue($ocName, 'user_ldap', 'isDeleted', '0');
|
||||||
|
if($curValue === '1') {
|
||||||
|
// the user is already marked, do not write to DB again
|
||||||
|
return;
|
||||||
|
}
|
||||||
$this->config->setUserValue($ocName, 'user_ldap', 'isDeleted', '1');
|
$this->config->setUserValue($ocName, 'user_ldap', 'isDeleted', '1');
|
||||||
|
$this->config->setUserValue($ocName, 'user_ldap', 'foundDeleted', (string)time());
|
||||||
$this->deletedUsers = null;
|
$this->deletedUsers = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,10 @@ class OfflineUser {
|
||||||
* @var string $lastLogin the timestamp of the last login
|
* @var string $lastLogin the timestamp of the last login
|
||||||
*/
|
*/
|
||||||
protected $lastLogin;
|
protected $lastLogin;
|
||||||
|
/**
|
||||||
|
* @var string $foundDeleted the timestamp when the user was detected as unavailable
|
||||||
|
*/
|
||||||
|
protected $foundDeleted;
|
||||||
/**
|
/**
|
||||||
* @var string $email
|
* @var string $email
|
||||||
*/
|
*/
|
||||||
|
@ -92,7 +96,8 @@ class OfflineUser {
|
||||||
* remove the Delete-flag from the user.
|
* remove the Delete-flag from the user.
|
||||||
*/
|
*/
|
||||||
public function unmark() {
|
public function unmark() {
|
||||||
$this->config->setUserValue($this->ocName, 'user_ldap', 'isDeleted', '0');
|
$this->config->deleteUserValue($this->ocName, 'user_ldap', 'isDeleted');
|
||||||
|
$this->config->deleteUserValue($this->ocName, 'user_ldap', 'foundDeleted');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -169,6 +174,14 @@ class OfflineUser {
|
||||||
return (int)$this->lastLogin;
|
return (int)$this->lastLogin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getter for the detection timestamp
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getDetectedOn() {
|
||||||
|
return (int)$this->foundDeleted;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getter for having active shares
|
* getter for having active shares
|
||||||
* @return bool
|
* @return bool
|
||||||
|
@ -181,13 +194,14 @@ class OfflineUser {
|
||||||
* reads the user details
|
* reads the user details
|
||||||
*/
|
*/
|
||||||
protected function fetchDetails() {
|
protected function fetchDetails() {
|
||||||
$properties = array (
|
$properties = [
|
||||||
'displayName' => 'user_ldap',
|
'displayName' => 'user_ldap',
|
||||||
'uid' => 'user_ldap',
|
'uid' => 'user_ldap',
|
||||||
'homePath' => 'user_ldap',
|
'homePath' => 'user_ldap',
|
||||||
'email' => 'settings',
|
'foundDeleted' => 'user_ldap',
|
||||||
'lastLogin' => 'login'
|
'email' => 'settings',
|
||||||
);
|
'lastLogin' => 'login',
|
||||||
|
];
|
||||||
foreach($properties as $property => $app) {
|
foreach($properties as $property => $app) {
|
||||||
$this->$property = $this->config->getUserValue($this->ocName, $app, $property, '');
|
$this->$property = $this->config->getUserValue($this->ocName, $app, $property, '');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue