Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
235 changes: 235 additions & 0 deletions LICENSES/AGPL-3.0-only.txt

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions lib/Command/CirclesMaintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -34,6 +37,7 @@ public function __construct(
private MaintenanceService $maintenanceService,
private OutputService $outputService,
private IDBConnection $dbConnection,
private IAppManager $appManager,
) {
parent::__construct();
}
Expand All @@ -45,6 +49,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'
Expand Down Expand Up @@ -75,6 +81,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

if ($input->getOption('fix-ldap-users-display-name')) {
if (!in_array('user_ldap', $this->appManager->getInstalledApps())) {
$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');
Expand Down Expand Up @@ -170,4 +185,17 @@ public function fixSamlDisplayName(OutputInterface $output): void {
}
}
}

public function fixLdapUsersDisplayName(OutputInterface $output): void {
$ldapUserMapping = Server::get(UserMapping::class);
/** @var array<int, array{dn: string, name: string, uuid: string}> $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']);
}
}
}
}
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
>
<stubs>
<file name="tests/stub.phpstub" preloadClasses="true"/>
<file name="tests/stubs/oca_user_ldap_mapping_abstractmapping.php" />
<file name="tests/stubs/oca_user_ldap_mapping_usermapping.php" />
</stubs>
<projectFiles>
<directory name="lib" />
Expand Down
2 changes: 1 addition & 1 deletion tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@
</file>
<file src="lib/Tools/Traits/TNCLogger.php">
<RedundantCondition>
<code><![CDATA[isset($this->logger)]]></code>
<code><![CDATA[isset($this->logger) && $this->logger instanceof LoggerInterface]]></code>
</RedundantCondition>
<RedundantPropertyInitializationCheck>
<code><![CDATA[isset($this->logger)]]></code>
Expand Down
215 changes: 215 additions & 0 deletions tests/stubs/oca_user_ldap_mapping_abstractmapping.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
<?php

/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\User_LDAP\Mapping;

use OCP\DB\IPreparedStatement;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;

/**
* Class AbstractMapping
*
* @package OCA\User_LDAP\Mapping
*/
abstract class AbstractMapping {
/**
* returns the DB table name which holds the mappings
*
* @return string
*/
abstract protected function getTableName(bool $includePrefix = true);

/**
* @param IDBConnection $dbc
*/
public function __construct(
protected IDBConnection $dbc,
) {
}

/** @var array caches Names (value) by DN (key) */
protected $cache = [];

/**
* checks whether a provided string represents an existing table col
*
* @param string $col
* @return bool
*/
public function isColNameValid($col) {
}

/**
* Gets the value of one column based on a provided value of another column
*
* @param string $fetchCol
* @param string $compareCol
* @param string $search
* @return string|false
* @throws \Exception
*/
protected function getXbyY($fetchCol, $compareCol, $search) {
}

/**
* Performs a DELETE or UPDATE query to the database.
*
* @param IPreparedStatement $statement
* @param array $parameters
* @return bool true if at least one row was modified, false otherwise
*/
protected function modify(IPreparedStatement $statement, $parameters) {
}

/**
* Gets the LDAP DN based on the provided name.
* Replaces Access::ocname2dn
*
* @param string $name
* @return string|false
*/
public function getDNByName($name) {
}

/**
* Updates the DN based on the given UUID
*
* @param string $fdn
* @param string $uuid
* @return bool
*/
public function setDNbyUUID($fdn, $uuid) {
}

/**
* Updates the UUID based on the given DN
*
* required by Migration/UUIDFix
*
* @param $uuid
* @param $fdn
* @return bool
*/
public function setUUIDbyDN($uuid, $fdn): bool {
}

/**
* Get the hash to store in database column ldap_dn_hash for a given dn
*/
protected function getDNHash(string $fdn): string {
}

/**
* Gets the name based on the provided LDAP DN.
*
* @param string $fdn
* @return string|false
*/
public function getNameByDN($fdn) {
}

/**
* @param array<string> $hashList
*/
protected function prepareListOfIdsQuery(array $hashList): IQueryBuilder {
}

protected function collectResultsFromListOfIdsQuery(IQueryBuilder $qb, array &$results): void {
}

/**
* @param array<string> $fdns
* @return array<string,string>
*/
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 {
}
}
40 changes: 40 additions & 0 deletions tests/stubs/oca_user_ldap_mapping_usermapping.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\User_LDAP\Mapping;

use OCP\HintException;
use OCP\IDBConnection;
use OCP\Support\Subscription\IAssertion;

/**
* Class UserMapping
*
* @package OCA\User_LDAP\Mapping
*/
class UserMapping extends AbstractMapping {

public function __construct(
IDBConnection $dbc,
private IAssertion $assertion,
) {
parent::__construct($dbc);
}

/**
* @throws HintException
*/
public function map($fdn, $name, $uuid): bool {
}

/**
* returns the DB table name which holds the mappings
* @return string
*/
protected function getTableName(bool $includePrefix = true) {
}
}
Loading