]> source.dussan.org Git - nextcloud-server.git/commitdiff
extend with group deletion handling 17920/head
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Wed, 13 Nov 2019 11:28:23 +0000 (12:28 +0100)
committerArthur Schiwon <blizzz@arthur-schiwon.de>
Thu, 28 Nov 2019 16:03:33 +0000 (17:03 +0100)
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
apps/files_external/lib/AppInfo/Application.php
apps/files_external/lib/Service/DBConfigService.php

index aa14772bae09f9e96e01b18d426256a995d21c05..47c88a67d20626f82765b1aac670147465daa99a 100644 (file)
@@ -64,6 +64,7 @@ use OCA\Files_External\Service\BackendService;
 use OCP\AppFramework\App;
 use OCP\AppFramework\IAppContainer;
 use OCP\Files\Config\IUserMountCache;
+use OCP\IGroup;
 use OCP\IUser;
 use Symfony\Component\EventDispatcher\GenericEvent;
 
@@ -111,6 +112,16 @@ class Application extends App implements IBackendProvider, IAuthMechanismProvide
                                $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());
+                       }
+               );
        }
 
        /**
index 0d8d048fc1d9d74840012e7379d3305e582ab014..9394924d3968e552c0a15401381c5f12f1c488f1 100644 (file)
@@ -114,15 +114,23 @@ class DBConfigService {
                return $this->getMountsFromQuery($query);
        }
 
-       public function modifyMountsOnUserDelete(string $uid) {
+       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')
                        ->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))
-                               )
+                       ->where($builder->expr()->andX(
+                               $builder->expr()->eq('a.type', $builder->createNamedParameter($applicableType, IQueryBuilder::PARAM_INT)),
+                               $builder->expr()->eq('a.value', $builder->createNamedParameter($applicableId))
+                       )
                        )
                        ->groupBy(['a.mount_id']);
                $stmt = $query->execute();
@@ -131,7 +139,7 @@ class DBConfigService {
 
                foreach ($result as $row) {
                        if((int)$row['count'] > 1) {
-                               $this->removeApplicable($row['mount_id'], self::APPLICABLE_TYPE_USER, $uid);
+                               $this->removeApplicable($row['mount_id'], $applicableType, $applicableId);
                        } else {
                                $this->removeMount($row['mount_id']);
                        }