Skip to content
Merged
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
Next Next commit
Fix ldap:check-user method for newly created LDAP users
Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Feb 22, 2022
commit bbfaeabdf3c7bf60fc1fae8725aa7fc107235a0a
26 changes: 11 additions & 15 deletions apps/user_ldap/lib/Command/CheckUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int
try {
$uid = $input->getArgument('ocName');
$this->isAllowed($input->getOption('force'));
$this->confirmUserIsMapped($uid);
$wasMapped = $this->userWasMapped($uid);
$exists = $this->backend->userExistsOnLDAP($uid, true);
if ($exists === true) {
$output->writeln('The user is still available on LDAP.');
if ($input->getOption('update')) {
$this->updateUser($uid, $output);
}
return 0;
} elseif ($wasMapped) {
$this->dui->markUser($uid);
$output->writeln('The user does not exists on LDAP anymore.');
$output->writeln('Clean up the user\'s remnants by: ./occ user:delete "'
. $uid . '"');
return 0;
} else {
throw new \Exception('The given user is not a recognized LDAP user.');
}

$this->dui->markUser($uid);
$output->writeln('The user does not exists on LDAP anymore.');
$output->writeln('Clean up the user\'s remnants by: ./occ user:delete "'
. $uid . '"');
return 0;
} catch (\Exception $e) {
$output->writeln('<error>' . $e->getMessage(). '</error>');
return 1;
Expand All @@ -114,16 +116,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/**
* checks whether a user is actually mapped
* @param string $ocName the username as used in Nextcloud
* @throws \Exception
* @return true
*/
protected function confirmUserIsMapped($ocName) {
protected function userWasMapped(string $ocName): bool {
$dn = $this->mapping->getDNByName($ocName);
if ($dn === false) {
throw new \Exception('The given user is not a recognized LDAP user.');
}

return true;
return ($dn !== false);
}

/**
Expand Down