Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiple LDAP configuration support by fixing AccessFactory #37903

Merged
merged 3 commits into from
May 2, 2023
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
7 changes: 3 additions & 4 deletions apps/user_ldap/lib/AccessFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,35 @@
use OCA\User_LDAP\User\Manager;
use OCP\IConfig;
use OCP\IUserManager;
use OCP\Server;
use Psr\Log\LoggerInterface;

class AccessFactory {
private ILDAPWrapper $ldap;
private Manager $userManager;
private Helper $helper;
private IConfig $config;
private IUserManager $ncUserManager;
private LoggerInterface $logger;

public function __construct(
ILDAPWrapper $ldap,
Manager $userManager,
Helper $helper,
IConfig $config,
IUserManager $ncUserManager,
LoggerInterface $logger) {
$this->ldap = $ldap;
$this->userManager = $userManager;
$this->helper = $helper;
$this->config = $config;
$this->ncUserManager = $ncUserManager;
$this->logger = $logger;
}

public function get(Connection $connection): Access {
/* Each Access instance gets its own Manager instance, see OCA\User_LDAP\AppInfo\Application::register() */
return new Access(
$connection,
$this->ldap,
$this->userManager,
Server::get(Manager::class),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment to explain why we do not use DI? It will help to not revert in the future.

$this->helper,
$this->config,
$this->ncUserManager,
Expand Down
19 changes: 2 additions & 17 deletions apps/user_ldap/lib/Jobs/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
use OCA\User_LDAP\Helper;
use OCA\User_LDAP\LDAP;
use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\User\Manager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCP\IAvatarManager;
Expand All @@ -48,8 +47,6 @@ class Sync extends TimedJob {
protected $ldapHelper;
/** @var LDAP */
protected $ldap;
/** @var Manager */
protected $userManager;
/** @var UserMapping */
protected $mapper;
/** @var IConfig */
Expand All @@ -69,9 +66,8 @@ class Sync extends TimedJob {
/** @var AccessFactory */
protected $accessFactory;

public function __construct(Manager $userManager, ITimeFactory $time) {
public function __construct(ITimeFactory $time) {
parent::__construct($time);
$this->userManager = $userManager;
$this->setInterval(
(int)\OC::$server->getConfig()->getAppValue(
'user_ldap',
Expand Down Expand Up @@ -350,10 +346,6 @@ public function setArgument($argument) {
$this->notificationManager = \OC::$server->getNotificationManager();
}

if (isset($argument['userManager'])) {
$this->userManager = $argument['userManager'];
}

if (isset($argument['mapper'])) {
$this->mapper = $argument['mapper'];
} else {
Expand All @@ -369,14 +361,7 @@ public function setArgument($argument) {
if (isset($argument['accessFactory'])) {
$this->accessFactory = $argument['accessFactory'];
} else {
$this->accessFactory = new AccessFactory(
$this->ldap,
$this->userManager,
$this->ldapHelper,
$this->config,
$this->ncUserManager,
$this->logger
);
$this->accessFactory = \OCP\Server::get(AccessFactory::class);
}
}
}
3 changes: 1 addition & 2 deletions apps/user_ldap/tests/Jobs/SyncTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
use Test\TestCase;

class SyncTest extends TestCase {

/** @var array */
protected $arguments;
/** @var Helper|\PHPUnit\Framework\MockObject\MockObject */
Expand Down Expand Up @@ -99,7 +98,7 @@ protected function setUp(): void {
'accessFactory' => $this->accessFactory,
];

$this->sync = new Sync($this->userManager, $this->createMock(ITimeFactory::class));
$this->sync = new Sync($this->createMock(ITimeFactory::class));
}

public function intervalDataProvider() {
Expand Down