namespace OCA\User_LDAP\User;
use OCA\User_LDAP\Mapping\UserMapping;
+use OCP\IConfig;
use OCP\Share\IManager;
/**
* @package OCA\User_LDAP
*/
class DeletedUsersIndex {
- /**
- * @var \OCP\IConfig $config
- */
- protected $config;
-
- /**
- * @var \OCA\User_LDAP\Mapping\UserMapping $mapping
- */
- protected $mapping;
+ protected IConfig $config;
+ protected UserMapping $mapping;
+ protected ?array $deletedUsers = null;
+ private IManager $shareManager;
- /**
- * @var array $deletedUsers
- */
- protected $deletedUsers;
- /** @var IManager */
- private $shareManager;
-
- public function __construct(\OCP\IConfig $config, UserMapping $mapping, IManager $shareManager) {
+ public function __construct(
+ IConfig $config,
+ UserMapping $mapping,
+ IManager $shareManager
+ ) {
$this->config = $config;
$this->mapping = $mapping;
$this->shareManager = $shareManager;
/**
* reads LDAP users marked as deleted from the database
- * @return \OCA\User_LDAP\User\OfflineUser[]
+ * @return OfflineUser[]
*/
- private function fetchDeletedUsers() {
- $deletedUsers = $this->config->getUsersForUserValue(
- 'user_ldap', 'isDeleted', '1');
+ private function fetchDeletedUsers(): array {
+ $deletedUsers = $this->config->getUsersForUserValue('user_ldap', 'isDeleted', '1');
$userObjects = [];
foreach ($deletedUsers as $user) {
/**
* returns all LDAP users that are marked as deleted
- * @return \OCA\User_LDAP\User\OfflineUser[]
+ * @return OfflineUser[]
*/
- public function getUsers() {
+ public function getUsers(): array {
if (is_array($this->deletedUsers)) {
return $this->deletedUsers;
}
/**
* whether at least one user was detected as deleted
- * @return bool
*/
- public function hasUsers() {
+ public function hasUsers(): bool {
if (!is_array($this->deletedUsers)) {
$this->fetchDeletedUsers();
}
/**
* marks a user as deleted
*
- * @param string $ocName
* @throws \OCP\PreConditionNotMetException
*/
- public function markUser($ocName) {
- $curValue = $this->config->getUserValue($ocName, 'user_ldap', 'isDeleted', '0');
- if ($curValue === '1') {
+ public function markUser(string $ocName): void {
+ if ($this->isUserMarked($ocName)) {
// the user is already marked, do not write to DB again
return;
}
$this->config->setUserValue($ocName, 'user_ldap', 'foundDeleted', (string)time());
$this->deletedUsers = null;
}
+
+ public function isUserMarked(string $ocName): bool {
+ return ($this->config->getUserValue($ocName, 'user_ldap', 'isDeleted', '0') === '1');
+ }
}
use OC\User\Backend;
use OC\User\NoUserException;
use OCA\User_LDAP\Exceptions\NotOnLDAP;
+use OCA\User_LDAP\User\DeletedUsersIndex;
use OCA\User_LDAP\User\OfflineUser;
use OCA\User_LDAP\User\User;
use OCP\IConfig;
use OCP\Notification\IManager as INotificationManager;
use OCP\User\Backend\ICountMappedUsersBackend;
use OCP\User\Backend\ICountUsersBackend;
+use OCP\User\Backend\IProvideEnabledStateBackend;
use OCP\UserInterface;
use Psr\Log\LoggerInterface;
-class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, IUserLDAP, ICountUsersBackend, ICountMappedUsersBackend {
+class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, IUserLDAP, ICountUsersBackend, ICountMappedUsersBackend, IProvideEnabledStateBackend {
/** @var \OCP\IConfig */
protected $ocConfig;
/** @var LoggerInterface */
protected $logger;
+ protected DeletedUsersIndex $deletedUsersIndex;
+
/**
* @param Access $access
* @param \OCP\IConfig $ocConfig
$this->notificationManager = $notificationManager;
$this->userPluginManager = $userPluginManager;
$this->logger = \OC::$server->get(LoggerInterface::class);
+ $this->deletedUsersIndex = \OC::$server->get(DeletedUsersIndex::class);
}
/**
}
}
- $marked = (int)$this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0);
- if ($marked === 0) {
+ $marked = $this->deletedUsersIndex->isUserMarked($uid);
+ if (!$marked) {
try {
$user = $this->access->userManager->get($uid);
if (($user instanceof User) && !$this->userExistsOnLDAP($uid, true)) {
$user->markUser();
- $marked = 1;
+ $marked = true;
}
} catch (\Exception $e) {
$this->logger->debug(
['app' => 'user_ldap', 'exception' => $e]
);
}
- if ($marked === 0) {
+ if (!$marked) {
$this->logger->notice(
'User '.$uid . ' is not marked as deleted, not cleaning up.',
['app' => 'user_ldap']
}
return false;
}
+
+ public function isUserEnabled(string $uid, callable $queryDatabaseValue): bool {
+ if ($this->deletedUsersIndex->isUserMarked($uid) && ($this->ocConfig->getAppValue('user_ldap', 'markRemnantsAsDisabled', '0') === '1')) {
+ return true;
+ } else {
+ return $queryDatabaseValue();
+ }
+ }
+
+ public function setUserEnabled(string $uid, bool $enabled, callable $queryDatabaseValue, callable $setDatabaseValue): void {
+ $setDatabaseValue($enabled);
+ }
}
use OCP\IUserBackend;
use OCP\IUserSession;
use OCP\Notification\IManager as INotificationManager;
+use OCP\UserInterface;
use OCP\User\Backend\ICountMappedUsersBackend;
use OCP\User\Backend\ICountUsersBackend;
-use OCP\UserInterface;
+use OCP\User\Backend\IProvideEnabledStateBackend;
-class User_Proxy extends Proxy implements IUserBackend, UserInterface, IUserLDAP, ICountUsersBackend, ICountMappedUsersBackend {
- /** @var array<string,User_LDAP> */
- private $backends = [];
- /** @var ?User_LDAP */
- private $refBackend = null;
+class User_Proxy extends Proxy implements IUserBackend, UserInterface, IUserLDAP, ICountUsersBackend, ICountMappedUsersBackend, IProvideEnabledStateBackend {
+ /** @var User_LDAP[] */
+ private array $backends = [];
+ private ?User_LDAP $refBackend = null;
private bool $isSetUp = false;
private Helper $helper;
public function createUser($username, $password) {
return $this->handleRequest($username, 'createUser', [$username, $password]);
}
+
+ public function isUserEnabled(string $uid, callable $queryDatabaseValue): bool {
+ return $this->handleRequest($uid, 'isUserEnabled', [$uid, $queryDatabaseValue]);
+ }
+
+ public function setUserEnabled(string $uid, bool $enabled, callable $queryDatabaseValue, callable $setDatabaseValue): void {
+ $this->handleRequest($uid, 'setUserEnabled', [$uid, $enabled, $queryDatabaseValue, $setDatabaseValue]);
+ }
}