Skip to content

Commit 59b5abe

Browse files
committed
Fix ldap:check-user method for newly created LDAP users
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent c84c765 commit 59b5abe

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

apps/user_ldap/lib/Command/CheckUser.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9090
try {
9191
$uid = $input->getArgument('ocName');
9292
$this->isAllowed($input->getOption('force'));
93-
$this->confirmUserIsMapped($uid);
93+
$wasMapped = $this->userWasMapped($uid);
9494
$exists = $this->backend->userExistsOnLDAP($uid, true);
9595
if ($exists === true) {
9696
$output->writeln('The user is still available on LDAP.');
9797
if ($input->getOption('update')) {
9898
$this->updateUser($uid, $output);
9999
}
100100
return 0;
101+
} elseif ($wasMapped) {
102+
$this->dui->markUser($uid);
103+
$output->writeln('The user does not exists on LDAP anymore.');
104+
$output->writeln('Clean up the user\'s remnants by: ./occ user:delete "'
105+
. $uid . '"');
106+
return 0;
107+
} else {
108+
throw new \Exception('The given user is not a recognized LDAP user.');
101109
}
102-
103-
$this->dui->markUser($uid);
104-
$output->writeln('The user does not exists on LDAP anymore.');
105-
$output->writeln('Clean up the user\'s remnants by: ./occ user:delete "'
106-
. $uid . '"');
107-
return 0;
108110
} catch (\Exception $e) {
109111
$output->writeln('<error>' . $e->getMessage(). '</error>');
110112
return 1;
@@ -114,16 +116,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
114116
/**
115117
* checks whether a user is actually mapped
116118
* @param string $ocName the username as used in Nextcloud
117-
* @throws \Exception
118-
* @return true
119119
*/
120-
protected function confirmUserIsMapped($ocName) {
120+
protected function userWasMapped(string $ocName): bool {
121121
$dn = $this->mapping->getDNByName($ocName);
122-
if ($dn === false) {
123-
throw new \Exception('The given user is not a recognized LDAP user.');
124-
}
125-
126-
return true;
122+
return ($dn !== false);
127123
}
128124

129125
/**

0 commit comments

Comments
 (0)