diff --git a/lib/Command/CirclesMaintenance.php b/lib/Command/CirclesMaintenance.php index 8ba52011c..d5088cf33 100644 --- a/lib/Command/CirclesMaintenance.php +++ b/lib/Command/CirclesMaintenance.php @@ -15,7 +15,10 @@ use OCA\Circles\Service\FederatedUserService; use OCA\Circles\Service\MaintenanceService; use OCA\Circles\Service\OutputService; +use OCA\User_LDAP\Mapping\UserMapping; +use OCP\App\IAppManager; use OCP\IDBConnection; +use OCP\Server; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputInterface; @@ -37,6 +40,7 @@ public function __construct( private OutputService $outputService, private IDBConnection $dbConnection, private LoggerInterface $logger, + private IAppManager $appManager, ) { parent::__construct(); } @@ -48,6 +52,8 @@ protected function configure() { ->setDescription('Clean stuff, keeps the app running') ->addOption('refresh-display-name', '', InputOption::VALUE_REQUIRED, 'refresh single user display name', '') ->addOption('fix-saml-users-display-name', '', InputOption::VALUE_NONE, 'retrieve users from the db table \'user_saml_users\' to fix their display-name') + ->addOption('fix-ldap-users-display-name', '', + InputOption::VALUE_NONE, 'retrieve users from the db table \'user_ldap_users\' to fix their display-name') ->addOption('level', '', InputOption::VALUE_REQUIRED, 'level of maintenance', '3') ->addOption( 'reset', '', InputOption::VALUE_NONE, 'reset Circles; remove all data related to the App' @@ -78,6 +84,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } + if ($input->getOption('fix-ldap-users-display-name')) { + if (!$this->appManager->isEnabledForAnyone('user_ldap')) { + $output->writeln('The "user_ldap" app is not enabled'); + return 1; + } + $this->fixLdapUsersDisplayName($output); + return 0; + } + $reset = $input->getOption('reset'); $uninstall = $input->getOption('uninstall'); $level = (int)$input->getOption('level'); @@ -177,4 +192,17 @@ public function fixSamlDisplayName(OutputInterface $output): void { } } } + + public function fixLdapUsersDisplayName(OutputInterface $output): void { + $ldapUserMapping = Server::get(UserMapping::class); + /** @var array $list */ + $list = $ldapUserMapping->getList(); + foreach ($list as $user) { + try { + $this->refreshSingleDisplayName($user['name'], $output); + } catch (Exception $e) { + $output->writeln(get_class($e) . ' while trying to update display name of ' . $user['name']); + } + } + } } diff --git a/psalm.xml b/psalm.xml index 5f4846390..32ab4c9fc 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,10 +1,10 @@ + + diff --git a/tests/stubs/oca_user_ldap_mapping_abstractmapping.php b/tests/stubs/oca_user_ldap_mapping_abstractmapping.php new file mode 100644 index 000000000..1fef812a5 --- /dev/null +++ b/tests/stubs/oca_user_ldap_mapping_abstractmapping.php @@ -0,0 +1,215 @@ + $hashList + */ + protected function prepareListOfIdsQuery(array $hashList): IQueryBuilder { + } + + protected function collectResultsFromListOfIdsQuery(IQueryBuilder $qb, array &$results): void { + } + + /** + * @param array $fdns + * @return array + */ + public function getListOfIdsByDn(array $fdns): array { + } + + /** + * Searches mapped names by the giving string in the name column + * + * @return string[] + */ + public function getNamesBySearch(string $search, string $prefixMatch = '', string $postfixMatch = ''): array { + } + + /** + * Gets the name based on the provided LDAP UUID. + * + * @param string $uuid + * @return string|false + */ + public function getNameByUUID($uuid) { + } + + public function getDnByUUID($uuid) { + } + + /** + * Gets the UUID based on the provided LDAP DN + * + * @param string $dn + * @return false|string + * @throws \Exception + */ + public function getUUIDByDN($dn) { + } + + public function getList(int $offset = 0, ?int $limit = null, bool $invalidatedOnly = false): array { + } + + /** + * attempts to map the given entry + * + * @param string $fdn fully distinguished name (from LDAP) + * @param string $name + * @param string $uuid a unique identifier as used in LDAP + * @return bool + */ + public function map($fdn, $name, $uuid) { + } + + /** + * removes a mapping based on the owncloud_name of the entry + * + * @param string $name + * @return bool + */ + public function unmap($name) { + } + + /** + * Truncates the mapping table + * + * @return bool + */ + public function clear() { + } + + /** + * clears the mapping table one by one and executing a callback with + * each row's id (=owncloud_name col) + * + * @param callable $preCallback + * @param callable $postCallback + * @return bool true on success, false when at least one row was not + * deleted + */ + public function clearCb(callable $preCallback, callable $postCallback): bool { + } + + /** + * returns the number of entries in the mappings table + * + * @return int + */ + public function count(): int { + } + + public function countInvalidated(): int { + } +} diff --git a/tests/stubs/oca_user_ldap_mapping_usermapping.php b/tests/stubs/oca_user_ldap_mapping_usermapping.php new file mode 100644 index 000000000..eeef81c49 --- /dev/null +++ b/tests/stubs/oca_user_ldap_mapping_usermapping.php @@ -0,0 +1,40 @@ +