Skip to content

Commit

Permalink
Merge pull request #21820 from nextcloud/techdebt/noid/ldap-do-not-us…
Browse files Browse the repository at this point in the history
…e-custom-DI-names

Do not use custom DI object names for user_ldap
  • Loading branch information
MorrisJobke authored Jul 13, 2020
2 parents 3772031 + 3203286 commit c419342
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 29 deletions.
11 changes: 2 additions & 9 deletions apps/user_ldap/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@
*
*/

\OC::$server->registerService('LDAPUserPluginManager', function () {
return new OCA\User_LDAP\UserPluginManager();
});
\OC::$server->registerService('LDAPGroupPluginManager', function () {
return new OCA\User_LDAP\GroupPluginManager();
});

$app = \OC::$server->query(\OCA\User_LDAP\AppInfo\Application::class);

$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
Expand All @@ -45,8 +38,8 @@
$notificationManager->registerNotifierService(\OCA\User_LDAP\Notification\Notifier::class);
$userSession = \OC::$server->getUserSession();

$userPluginManager = \OC::$server->query('LDAPUserPluginManager');
$groupPluginManager = \OC::$server->query('LDAPGroupPluginManager');
$userPluginManager = \OC::$server->query(\OCA\User_LDAP\UserPluginManager::class);
$groupPluginManager = \OC::$server->query(\OCA\User_LDAP\GroupPluginManager::class);

$userBackend = new OCA\User_LDAP\User_Proxy(
$configPrefixes, $ldapWrapper, $ocConfig, $notificationManager, $userSession, $userPluginManager
Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/appinfo/register_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
$ocConfig,
\OC::$server->getNotificationManager(),
\OC::$server->getUserSession(),
\OC::$server->query('LDAPUserPluginManager')
\OC::$server->query(\OCA\User_LDAP\UserPluginManager::class)
);
$deletedUsersIndex = new DeletedUsersIndex(
$ocConfig, $dbConnection, $userMapping
Expand Down
6 changes: 4 additions & 2 deletions apps/user_ldap/lib/Command/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
namespace OCA\User_LDAP\Command;

use OCA\User_LDAP\Group_Proxy;
use OCA\User_LDAP\GroupPluginManager;
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\LDAP;
use OCA\User_LDAP\User_Proxy;
use OCA\User_LDAP\UserPluginManager;
use OCP\IConfig;

use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -115,7 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->validateOffsetAndLimit($offset, $limit);

if ($input->getOption('group')) {
$proxy = new Group_Proxy($configPrefixes, $ldapWrapper, \OC::$server->query('LDAPGroupPluginManager'));
$proxy = new Group_Proxy($configPrefixes, $ldapWrapper, \OC::$server->query(GroupPluginManager::class));
$getMethod = 'getGroups';
$printID = false;
// convert the limit of groups to null. This will show all the groups available instead of
Expand All @@ -130,7 +132,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->ocConfig,
\OC::$server->getNotificationManager(),
\OC::$server->getUserSession(),
\OC::$server->query('LDAPUserPluginManager')
\OC::$server->query(UserPluginManager::class)
);
$getMethod = 'getDisplayNames';
$printID = true;
Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public static function loginName2UserName($param) {
$notificationManager = \OC::$server->getNotificationManager();

$userSession = \OC::$server->getUserSession();
$userPluginManager = \OC::$server->query('LDAPUserPluginManager');
$userPluginManager = \OC::$server->query(UserPluginManager::class);

$userBackend = new User_Proxy(
$configPrefixes, $ldapWrapper, $ocConfig, $notificationManager, $userSession, $userPluginManager
Expand Down
3 changes: 2 additions & 1 deletion apps/user_ldap/lib/Jobs/CleanUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use OCA\User_LDAP\User\DeletedUsersIndex;
use OCA\User_LDAP\User_LDAP;
use OCA\User_LDAP\User_Proxy;
use OCA\User_LDAP\UserPluginManager;

/**
* Class CleanUp
Expand Down Expand Up @@ -105,7 +106,7 @@ public function setArguments($arguments) {
$this->ocConfig,
\OC::$server->getNotificationManager(),
\OC::$server->getUserSession(),
\OC::$server->query('LDAPUserPluginManager')
\OC::$server->query(UserPluginManager::class)
);
}

Expand Down
5 changes: 3 additions & 2 deletions apps/user_ldap/lib/Jobs/UpdateGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCA\User_LDAP\Access;
use OCA\User_LDAP\Connection;
use OCA\User_LDAP\FilesystemHelper;
use OCA\User_LDAP\GroupPluginManager;
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\LDAP;
use OCA\User_LDAP\LogWrapper;
Expand Down Expand Up @@ -198,9 +199,9 @@ private static function getGroupBE() {
$userMapper = new UserMapping($dbc);
$ldapAccess->setGroupMapper($groupMapper);
$ldapAccess->setUserMapper($userMapper);
self::$groupBE = new \OCA\User_LDAP\Group_LDAP($ldapAccess, \OC::$server->query('LDAPGroupPluginManager'));
self::$groupBE = new \OCA\User_LDAP\Group_LDAP($ldapAccess, \OC::$server->query(GroupPluginManager::class));
} else {
self::$groupBE = new \OCA\User_LDAP\Group_Proxy($configPrefixes, $ldapWrapper, \OC::$server->query('LDAPGroupPluginManager'));
self::$groupBE = new \OCA\User_LDAP\Group_Proxy($configPrefixes, $ldapWrapper, \OC::$server->query(GroupPluginManager::class));
}

return self::$groupBE;
Expand Down
3 changes: 2 additions & 1 deletion apps/user_ldap/lib/Migration/UUIDFixGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@
use OCA\User_LDAP\LDAP;
use OCA\User_LDAP\Mapping\GroupMapping;
use OCA\User_LDAP\User_Proxy;
use OCA\User_LDAP\UserPluginManager;
use OCP\IConfig;

class UUIDFixGroup extends UUIDFix {
public function __construct(GroupMapping $mapper, LDAP $ldap, IConfig $config, Helper $helper) {
$this->mapper = $mapper;
$this->proxy = new User_Proxy($helper->getServerConfigurationPrefixes(true), $ldap, $config,
\OC::$server->getNotificationManager(), \OC::$server->getUserSession(),
\OC::$server->query('LDAPUserPluginManager'));
\OC::$server->query(UserPluginManager::class));
}
}
3 changes: 2 additions & 1 deletion apps/user_ldap/lib/Migration/UUIDFixUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace OCA\User_LDAP\Migration;

use OCA\User_LDAP\Group_Proxy;
use OCA\User_LDAP\GroupPluginManager;
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\LDAP;
use OCA\User_LDAP\Mapping\UserMapping;
Expand All @@ -34,7 +35,7 @@
class UUIDFixUser extends UUIDFix {
public function __construct(UserMapping $mapper, LDAP $ldap, IConfig $config, Helper $helper) {
$this->mapper = $mapper;
$groupPluginManager = \OC::$server->query('LDAPGroupPluginManager');
$groupPluginManager = \OC::$server->query(GroupPluginManager::class);
$this->proxy = new Group_Proxy($helper->getServerConfigurationPrefixes(true), $ldap, $groupPluginManager);
}
}
10 changes: 6 additions & 4 deletions apps/user_ldap/tests/Integration/AbstractIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
use OCA\User_LDAP\Access;
use OCA\User_LDAP\Connection;
use OCA\User_LDAP\FilesystemHelper;
use OCA\User_LDAP\GroupPluginManager;
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\LDAP;
use OCA\User_LDAP\LogWrapper;
use OCA\User_LDAP\User\Manager;
use OCA\User_LDAP\UserPluginManager;

abstract class AbstractIntegrationTest {
/** @var LDAP */
Expand All @@ -47,7 +49,7 @@ abstract class AbstractIntegrationTest {

/** @var Manager */
protected $userManager;

/** @var Helper */
protected $helper;

Expand All @@ -72,10 +74,10 @@ public function __construct($host, $port, $bind, $pwd, $base) {
* the LDAP backend.
*/
public function init() {
\OC::$server->registerService('LDAPUserPluginManager', function () {
\OC::$server->registerService(UserPluginManager::class, function () {
return new \OCA\User_LDAP\UserPluginManager();
});
\OC::$server->registerService('LDAPGroupPluginManager', function () {
\OC::$server->registerService(GroupPluginManager::class, function () {
return new \OCA\User_LDAP\GroupPluginManager();
});

Expand Down Expand Up @@ -128,7 +130,7 @@ protected function initUserManager() {
\OC::$server->getNotificationManager()
);
}

/**
* initializes the test Helper
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
namespace OCA\user_ldap\tests\Integration\Lib;

use OCA\User_LDAP\Group_LDAP;
use OCA\User_LDAP\GroupPluginManager;
use OCA\User_LDAP\Mapping\GroupMapping;
use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
use OCA\User_LDAP\User_LDAP;
use OCA\User_LDAP\UserPluginManager;

require_once __DIR__ . '/../Bootstrap.php';

Expand All @@ -50,12 +52,12 @@ public function init() {
$groupMapper->clear();
$this->access->setGroupMapper($groupMapper);

$userBackend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), \OC::$server->query('LDAPUserPluginManager'));
$userBackend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), \OC::$server->query(UserPluginManager::class));
$userManager = \OC::$server->getUserManager();
$userManager->clearBackends();
$userManager->registerBackend($userBackend);

$groupBackend = new Group_LDAP($this->access, \OC::$server->query('LDAPGroupPluginManager'));
$groupBackend = new Group_LDAP($this->access, \OC::$server->query(GroupPluginManager::class));
$groupManger = \OC::$server->getGroupManager();
$groupManger->clearBackends();
$groupManger->addBackend($groupBackend);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
use OCA\User_LDAP\User_LDAP;
use OCA\User_LDAP\UserPluginManager;

require_once __DIR__ . '/../Bootstrap.php';

Expand All @@ -49,7 +50,7 @@ public function init() {
$this->mapping = new UserMapping(\OC::$server->getDatabaseConnection());
$this->mapping->clear();
$this->access->setUserMapper($this->mapping);
$this->backend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), \OC::$server->query('LDAPUserPluginManager'));
$this->backend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), \OC::$server->query(UserPluginManager::class));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
use OCA\User_LDAP\User_LDAP;
use OCA\User_LDAP\UserPluginManager;

require_once __DIR__ . '/../Bootstrap.php';

Expand All @@ -50,7 +51,7 @@ public function init() {
require(__DIR__ . '/../setup-scripts/createExplicitUsers.php');
parent::init();

$this->backend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), \OC::$server->query('LDAPUserPluginManager'));
$this->backend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), \OC::$server->query(UserPluginManager::class));
}

public function initConnection() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use OCA\User_LDAP\User\Manager;
use OCA\User_LDAP\User\User;
use OCA\User_LDAP\User_LDAP;
use OCA\User_LDAP\UserPluginManager;
use OCP\Image;

require_once __DIR__ . '/../../Bootstrap.php';
Expand All @@ -54,7 +55,7 @@ public function init() {
$this->mapping = new UserMapping(\OC::$server->getDatabaseConnection());
$this->mapping->clear();
$this->access->setUserMapper($this->mapping);
$userBackend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), \OC::$server->query('LDAPUserPluginManager'));
$userBackend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), \OC::$server->query(UserPluginManager::class));
\OC_User::useBackend($userBackend);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
use OCA\User_LDAP\User_LDAP;
use OCA\User_LDAP\UserPluginManager;

require_once __DIR__ . '/../../Bootstrap.php';

Expand All @@ -46,7 +47,7 @@ public function init() {
$this->mapping->clear();
$this->access->setUserMapper($this->mapping);

$userBackend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), \OC::$server->query('LDAPUserPluginManager'));
$userBackend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), \OC::$server->query(UserPluginManager::class));
\OC_User::useBackend($userBackend);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
use OCA\User_LDAP\User_LDAP;
use OCA\User_LDAP\UserPluginManager;

require_once __DIR__ . '/../../Bootstrap.php';

Expand All @@ -44,7 +45,7 @@ public function init() {
$this->mapping = new UserMapping(\OC::$server->getDatabaseConnection());
$this->mapping->clear();
$this->access->setUserMapper($this->mapping);
$userBackend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), \OC::$server->query('LDAPUserPluginManager'));
$userBackend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), \OC::$server->query(UserPluginManager::class));
\OC_User::useBackend($userBackend);
}

Expand Down

0 comments on commit c419342

Please sign in to comment.