Skip to content

Commit 41fe4dc

Browse files
authored
Merge pull request #23700 from nextcloud/fix/noid/remnants-sharee-display
Use ShareManager to determine shares of unlocatable LDAP users and fix an issue in a condition
2 parents ae54ae6 + fd1fd5a commit 41fe4dc

17 files changed

+212
-134
lines changed

apps/user_ldap/ajax/wizard.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@
6161
new \OCA\User_LDAP\LogWrapper(),
6262
\OC::$server->getAvatarManager(),
6363
new \OCP\Image(),
64-
\OC::$server->getDatabaseConnection(),
6564
\OC::$server->getUserManager(),
66-
\OC::$server->getNotificationManager());
65+
\OC::$server->getNotificationManager(),
66+
\OC::$server->get(\OCP\Share\IManager::class)
67+
);
6768

6869
$access = new \OCA\User_LDAP\Access(
6970
$con,

apps/user_ldap/lib/Access.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
use OC\ServerNotAvailableException;
5353
use OCA\User_LDAP\Exceptions\ConstraintViolationException;
5454
use OCA\User_LDAP\Mapping\AbstractMapping;
55+
use OCA\User_LDAP\Mapping\UserMapping;
5556
use OCA\User_LDAP\User\Manager;
5657
use OCA\User_LDAP\User\OfflineUser;
5758
use OCP\IConfig;
@@ -74,9 +75,7 @@ class Access extends LDAPUtility {
7475
protected $pagedSearchedSuccessful;
7576

7677
/**
77-
* protected $cookies = [];
78-
*
79-
* @var AbstractMapping $userMapper
78+
* @var UserMapping $userMapper
8079
*/
8180
protected $userMapper;
8281

@@ -123,12 +122,9 @@ public function setUserMapper(AbstractMapping $mapper) {
123122
}
124123

125124
/**
126-
* returns the User Mapper
127-
*
128-
* @return AbstractMapping
129125
* @throws \Exception
130126
*/
131-
public function getUserMapper() {
127+
public function getUserMapper(): UserMapping {
132128
if (is_null($this->userMapper)) {
133129
throw new \Exception('UserMapper was not assigned to this Access instance.');
134130
}

apps/user_ldap/lib/Jobs/CleanUp.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
use OC\BackgroundJob\TimedJob;
3232
use OCA\User_LDAP\Helper;
33-
use OCA\User_LDAP\LDAP;
3433
use OCA\User_LDAP\Mapping\UserMapping;
3534
use OCA\User_LDAP\User\DeletedUsersIndex;
3635
use OCA\User_LDAP\User_LDAP;
@@ -68,11 +67,12 @@ class CleanUp extends TimedJob {
6867
/** @var DeletedUsersIndex */
6968
protected $dui;
7069

71-
public function __construct(User_Proxy $userBackend) {
70+
public function __construct(User_Proxy $userBackend, DeletedUsersIndex $dui) {
7271
$minutes = \OC::$server->getConfig()->getSystemValue(
7372
'ldapUserCleanupInterval', (string)$this->defaultIntervalMin);
7473
$this->setInterval((int)$minutes * 60);
7574
$this->userBackend = $userBackend;
75+
$this->dui = $dui;
7676
}
7777

7878
/**
@@ -115,9 +115,6 @@ public function setArguments($arguments) {
115115

116116
if (isset($arguments['deletedUsersIndex'])) {
117117
$this->dui = $arguments['deletedUsersIndex'];
118-
} else {
119-
$this->dui = new DeletedUsersIndex(
120-
$this->ocConfig, $this->db, $this->mapping);
121118
}
122119
}
123120

apps/user_ldap/lib/Jobs/Sync.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,13 @@
2929
use OCA\User_LDAP\AccessFactory;
3030
use OCA\User_LDAP\Configuration;
3131
use OCA\User_LDAP\ConnectionFactory;
32-
use OCA\User_LDAP\FilesystemHelper;
3332
use OCA\User_LDAP\Helper;
3433
use OCA\User_LDAP\LDAP;
35-
use OCA\User_LDAP\LogWrapper;
3634
use OCA\User_LDAP\Mapping\UserMapping;
3735
use OCA\User_LDAP\User\Manager;
3836
use OCP\IAvatarManager;
3937
use OCP\IConfig;
4038
use OCP\IDBConnection;
41-
use OCP\Image;
4239
use OCP\IUserManager;
4340
use OCP\Notification\IManager;
4441

@@ -68,7 +65,8 @@ class Sync extends TimedJob {
6865
/** @var AccessFactory */
6966
protected $accessFactory;
7067

71-
public function __construct() {
68+
public function __construct(Manager $userManager) {
69+
$this->userManager = $userManager;
7270
$this->setInterval(
7371
\OC::$server->getConfig()->getAppValue(
7472
'user_ldap',
@@ -345,25 +343,14 @@ public function setArgument($argument) {
345343

346344
if (isset($argument['userManager'])) {
347345
$this->userManager = $argument['userManager'];
348-
} else {
349-
$this->userManager = new Manager(
350-
$this->config,
351-
new FilesystemHelper(),
352-
new LogWrapper(),
353-
$this->avatarManager,
354-
new Image(),
355-
$this->dbc,
356-
$this->ncUserManager,
357-
$this->notificationManager
358-
);
359346
}
360347

361348
if (isset($argument['mapper'])) {
362349
$this->mapper = $argument['mapper'];
363350
} else {
364351
$this->mapper = new UserMapping($this->dbc);
365352
}
366-
353+
367354
if (isset($argument['connectionFactory'])) {
368355
$this->connectionFactory = $argument['connectionFactory'];
369356
} else {

apps/user_ldap/lib/LDAPProviderFactory.php

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,19 @@
2626

2727
namespace OCA\User_LDAP;
2828

29-
use OCA\User_LDAP\Mapping\UserMapping;
30-
use OCA\User_LDAP\User\DeletedUsersIndex;
3129
use OCP\IServerContainer;
30+
use OCP\LDAP\ILDAPProvider;
3231
use OCP\LDAP\ILDAPProviderFactory;
3332

3433
class LDAPProviderFactory implements ILDAPProviderFactory {
35-
/**
36-
* Server container
37-
*
38-
* @var IServerContainer
39-
*/
34+
/** * @var IServerContainer */
4035
private $serverContainer;
41-
42-
/**
43-
* Constructor for the LDAP provider factory
44-
*
45-
* @param IServerContainer $serverContainer server container
46-
*/
36+
4737
public function __construct(IServerContainer $serverContainer) {
4838
$this->serverContainer = $serverContainer;
4939
}
50-
51-
/**
52-
* creates and returns an instance of the ILDAPProvider
53-
*
54-
* @return OCP\LDAP\ILDAPProvider
55-
*/
56-
public function getLDAPProvider() {
57-
$dbConnection = $this->serverContainer->getDatabaseConnection();
58-
$userMapping = new UserMapping($dbConnection);
59-
return new LDAPProvider($this->serverContainer, new Helper($this->serverContainer->getConfig()),
60-
new DeletedUsersIndex($this->serverContainer->getConfig(),
61-
$dbConnection, $userMapping));
40+
41+
public function getLDAPProvider(): ILDAPProvider {
42+
return $this->serverContainer->get(LDAPProvider::class);
6243
}
6344
}

apps/user_ldap/lib/Proxy.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use OCA\User_LDAP\Mapping\GroupMapping;
3737
use OCA\User_LDAP\Mapping\UserMapping;
3838
use OCA\User_LDAP\User\Manager;
39+
use OCP\Share\IManager;
3940

4041
abstract class Proxy {
4142
private static $accesses = [];
@@ -67,7 +68,7 @@ private function addAccess($configPrefix) {
6768
static $avatarM;
6869
static $userMap;
6970
static $groupMap;
70-
static $db;
71+
static $shareManager;
7172
static $coreUserManager;
7273
static $coreNotificationManager;
7374
if ($fs === null) {
@@ -80,10 +81,11 @@ private function addAccess($configPrefix) {
8081
$groupMap = new GroupMapping($db);
8182
$coreUserManager = \OC::$server->getUserManager();
8283
$coreNotificationManager = \OC::$server->getNotificationManager();
84+
$shareManager = \OC::$server->get(IManager::class);
8385
}
8486
$userManager =
85-
new Manager($ocConfig, $fs, $log, $avatarM, new \OCP\Image(), $db,
86-
$coreUserManager, $coreNotificationManager);
87+
new Manager($ocConfig, $fs, $log, $avatarM, new \OCP\Image(),
88+
$coreUserManager, $coreNotificationManager, $shareManager);
8789
$connector = new Connection($this->ldap, $configPrefix);
8890
$access = new Access($connector, $this->ldap, $userManager, new Helper($ocConfig), $ocConfig, $coreUserManager);
8991
$access->setUserMapper($userMap);

apps/user_ldap/lib/User/DeletedUsersIndex.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
namespace OCA\User_LDAP\User;
2727

2828
use OCA\User_LDAP\Mapping\UserMapping;
29+
use OCP\Share\IManager;
2930

3031
/**
3132
* Class DeletedUsersIndex
@@ -37,11 +38,6 @@ class DeletedUsersIndex {
3738
*/
3839
protected $config;
3940

40-
/**
41-
* @var \OCP\IDBConnection $db
42-
*/
43-
protected $db;
44-
4541
/**
4642
* @var \OCA\User_LDAP\Mapping\UserMapping $mapping
4743
*/
@@ -51,16 +47,13 @@ class DeletedUsersIndex {
5147
* @var array $deletedUsers
5248
*/
5349
protected $deletedUsers;
50+
/** @var IManager */
51+
private $shareManager;
5452

55-
/**
56-
* @param \OCP\IConfig $config
57-
* @param \OCP\IDBConnection $db
58-
* @param \OCA\User_LDAP\Mapping\UserMapping $mapping
59-
*/
60-
public function __construct(\OCP\IConfig $config, \OCP\IDBConnection $db, UserMapping $mapping) {
53+
public function __construct(\OCP\IConfig $config, UserMapping $mapping, IManager $shareManager) {
6154
$this->config = $config;
62-
$this->db = $db;
6355
$this->mapping = $mapping;
56+
$this->shareManager = $shareManager;
6457
}
6558

6659
/**
@@ -73,7 +66,7 @@ private function fetchDeletedUsers() {
7366

7467
$userObjects = [];
7568
foreach ($deletedUsers as $user) {
76-
$userObjects[] = new OfflineUser($user, $this->config, $this->db, $this->mapping);
69+
$userObjects[] = new OfflineUser($user, $this->config, $this->mapping, $this->shareManager);
7770
}
7871
$this->deletedUsers = $userObjects;
7972

apps/user_ldap/lib/User/Manager.php

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
use OCP\Image;
4040
use OCP\IUserManager;
4141
use OCP\Notification\IManager as INotificationManager;
42+
use OCP\Share\IManager;
4243

4344
/**
4445
* Manager
@@ -82,32 +83,29 @@ class Manager {
8283
* @var CappedMemoryCache $usersByUid
8384
*/
8485
protected $usersByUid;
86+
/** @var IManager */
87+
private $shareManager;
8588

86-
/**
87-
* @param IConfig $ocConfig
88-
* @param \OCA\User_LDAP\FilesystemHelper $ocFilesystem object that
89-
* gives access to necessary functions from the OC filesystem
90-
* @param \OCA\User_LDAP\LogWrapper $ocLog
91-
* @param IAvatarManager $avatarManager
92-
* @param Image $image an empty image instance
93-
* @param IDBConnection $db
94-
* @throws \Exception when the methods mentioned above do not exist
95-
*/
96-
public function __construct(IConfig $ocConfig,
97-
FilesystemHelper $ocFilesystem, LogWrapper $ocLog,
98-
IAvatarManager $avatarManager, Image $image,
99-
IDBConnection $db, IUserManager $userManager,
100-
INotificationManager $notificationManager) {
89+
public function __construct(
90+
IConfig $ocConfig,
91+
FilesystemHelper $ocFilesystem,
92+
LogWrapper $ocLog,
93+
IAvatarManager $avatarManager,
94+
Image $image,
95+
IUserManager $userManager,
96+
INotificationManager $notificationManager,
97+
IManager $shareManager
98+
) {
10199
$this->ocConfig = $ocConfig;
102100
$this->ocFilesystem = $ocFilesystem;
103101
$this->ocLog = $ocLog;
104102
$this->avatarManager = $avatarManager;
105103
$this->image = $image;
106-
$this->db = $db;
107104
$this->userManager = $userManager;
108105
$this->notificationManager = $notificationManager;
109106
$this->usersByDN = new CappedMemoryCache();
110107
$this->usersByUid = new CappedMemoryCache();
108+
$this->shareManager = $shareManager;
111109
}
112110

113111
/**
@@ -229,8 +227,9 @@ public function getDeletedUser($id) {
229227
return new OfflineUser(
230228
$id,
231229
$this->ocConfig,
232-
$this->db,
233-
$this->access->getUserMapper());
230+
$this->access->getUserMapper(),
231+
$this->shareManager
232+
);
234233
}
235234

236235
/**

0 commit comments

Comments
 (0)