Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2019-11-13 01:53:33 +0300
committerArthur Schiwon <blizzz@arthur-schiwon.de>2019-11-28 19:03:33 +0300
commitbe85d00a386dfc8c60f413e7000009237855ce7e (patch)
tree5390a23a6d71e6021672e188b85dfbdf4e224876 /apps/files_external/lib
parent6b97f6af48ba8dc029e616cf778a1cbcd0fea001 (diff)
when a user was delete remove them from applicable list, unless
it is the only user, then remove the mount Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/files_external/lib')
-rw-r--r--apps/files_external/lib/AppInfo/Application.php17
-rw-r--r--apps/files_external/lib/Service/DBConfigService.php24
2 files changed, 41 insertions, 0 deletions
diff --git a/apps/files_external/lib/AppInfo/Application.php b/apps/files_external/lib/AppInfo/Application.php
index 1ee7cb08ccf..aa14772bae0 100644
--- a/apps/files_external/lib/AppInfo/Application.php
+++ b/apps/files_external/lib/AppInfo/Application.php
@@ -30,6 +30,7 @@
namespace OCA\Files_External\AppInfo;
use OCA\Files_External\Config\UserPlaceholderHandler;
+use OCA\Files_External\Service\DBConfigService;
use OCA\Files_External\Lib\Auth\AmazonS3\AccessKey;
use OCA\Files_External\Lib\Auth\Builtin;
use OCA\Files_External\Lib\Auth\NullMechanism;
@@ -63,6 +64,8 @@ use OCA\Files_External\Service\BackendService;
use OCP\AppFramework\App;
use OCP\AppFramework\IAppContainer;
use OCP\Files\Config\IUserMountCache;
+use OCP\IUser;
+use Symfony\Component\EventDispatcher\GenericEvent;
/**
* @package OCA\Files_External\AppInfo
@@ -96,6 +99,20 @@ 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());
+ }
+ );
+ }
+
/**
* @{inheritdoc}
*/
diff --git a/apps/files_external/lib/Service/DBConfigService.php b/apps/files_external/lib/Service/DBConfigService.php
index 65995b21cc4..0d8d048fc1d 100644
--- a/apps/files_external/lib/Service/DBConfigService.php
+++ b/apps/files_external/lib/Service/DBConfigService.php
@@ -114,6 +114,30 @@ class DBConfigService {
return $this->getMountsFromQuery($query);
}
+ public function modifyMountsOnUserDelete(string $uid) {
+ $builder = $this->connection->getQueryBuilder();
+ $query = $builder->select(['a.mount_id', $builder->func()->count('a.mount_id', 'count')])
+ ->from('external_applicable', 'a')
+ ->rightJoin('a', 'external_applicable', 'b', $builder->expr()->eq('a.mount_id', 'b.mount_id'))
+ ->where($builder->expr()->andX( // mounts for user
+ $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_USER, IQueryBuilder::PARAM_INT)),
+ $builder->expr()->eq('a.value', $builder->createNamedParameter($uid))
+ )
+ )
+ ->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'], self::APPLICABLE_TYPE_USER, $uid);
+ } else {
+ $this->removeMount($row['mount_id']);
+ }
+ }
+ }
+
/**
* Get admin defined mounts
*