Merge pull request #19077 from nextcloud/backport/17920+18254/stable16
[stable16] when a user was deleted remove them from applicable list, unless...
This commit is contained in:
commit
719f828de9
3 changed files with 62 additions and 0 deletions
|
@ -34,6 +34,8 @@ require_once __DIR__ . '/../3rdparty/autoload.php';
|
|||
|
||||
// register Application object singleton
|
||||
\OC_Mount_Config::$app = new \OCA\Files_External\AppInfo\Application();
|
||||
\OC_Mount_Config::$app->registerListeners();
|
||||
|
||||
$appContainer = \OC_Mount_Config::$app->getContainer();
|
||||
|
||||
\OCA\Files\App::getNavigationManager()->add(function () {
|
||||
|
|
|
@ -32,6 +32,7 @@ namespace OCA\Files_External\AppInfo;
|
|||
use OCA\Files_External\Config\UserPlaceholderHandler;
|
||||
use OCA\Files_External\Lib\Auth\PublicKey\RSAPrivateKey;
|
||||
use OCA\Files_External\Lib\Auth\SMB\KerberosAuth;
|
||||
use OCA\Files_External\Service\DBConfigService;
|
||||
use \OCP\AppFramework\App;
|
||||
use OCP\AppFramework\IAppContainer;
|
||||
use \OCA\Files_External\Service\BackendService;
|
||||
|
@ -62,6 +63,9 @@ use OCA\Files_External\Lib\Backend\DAV;
|
|||
use OCA\Files_External\Lib\Backend\FTP;
|
||||
use OCA\Files_External\Lib\Backend\Local;
|
||||
use OCP\Files\Config\IUserMountCache;
|
||||
use OCP\IGroup;
|
||||
use OCP\IUser;
|
||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||
|
||||
/**
|
||||
* @package OCA\Files_External\AppInfo
|
||||
|
@ -95,6 +99,30 @@ class Application extends App implements IBackendProvider, IAuthMechanismProvide
|
|||
$this->getAuthMechanisms();
|
||||
}
|
||||
|
||||
public function registerListeners() {
|
||||
$dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
|
||||
$dispatcher->addListener(
|
||||
IUser::class . '::postDelete',
|
||||
function (GenericEvent $event) {
|
||||
/** @var IUser $user */
|
||||
$user = $event->getSubject();
|
||||
/** @var DBConfigService $config */
|
||||
$config = $this->getContainer()->query(DBConfigService::class);
|
||||
$config->modifyMountsOnUserDelete($user->getUID());
|
||||
}
|
||||
);
|
||||
$dispatcher->addListener(
|
||||
IGroup::class . '::postDelete',
|
||||
function (GenericEvent $event) {
|
||||
/** @var IGroup $group */
|
||||
$group = $event->getSubject();
|
||||
/** @var DBConfigService $config */
|
||||
$config = $this->getContainer()->query(DBConfigService::class);
|
||||
$config->modifyMountsOnGroupDelete($group->getGID());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @{inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -114,6 +114,38 @@ class DBConfigService {
|
|||
return $this->getMountsFromQuery($query);
|
||||
}
|
||||
|
||||
public function modifyMountsOnUserDelete(string $uid): void {
|
||||
$this->modifyMountsOnDelete($uid, self::APPLICABLE_TYPE_USER);
|
||||
}
|
||||
|
||||
public function modifyMountsOnGroupDelete(string $gid): void {
|
||||
$this->modifyMountsOnDelete($gid, self::APPLICABLE_TYPE_GROUP);
|
||||
}
|
||||
|
||||
protected function modifyMountsOnDelete(string $applicableId, int $applicableType): void {
|
||||
$builder = $this->connection->getQueryBuilder();
|
||||
$query = $builder->select(['a.mount_id', $builder->func()->count('a.mount_id', 'count')])
|
||||
->from('external_applicable', 'a')
|
||||
->leftJoin('a', 'external_applicable', 'b', $builder->expr()->eq('a.mount_id', 'b.mount_id'))
|
||||
->where($builder->expr()->andX(
|
||||
$builder->expr()->eq('b.type', $builder->createNamedParameter($applicableType, IQueryBuilder::PARAM_INT)),
|
||||
$builder->expr()->eq('b.value', $builder->createNamedParameter($applicableId))
|
||||
)
|
||||
)
|
||||
->groupBy(['a.mount_id']);
|
||||
$stmt = $query->execute();
|
||||
$result = $stmt->fetchAll();
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($result as $row) {
|
||||
if((int)$row['count'] > 1) {
|
||||
$this->removeApplicable($row['mount_id'], $applicableType, $applicableId);
|
||||
} else {
|
||||
$this->removeMount($row['mount_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get admin defined mounts
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue