From 35bb0759218c2c8b9b5f24b3dadcdd0d9a7ba282 Mon Sep 17 00:00:00 2001 From: Sujith H Date: Thu, 13 Sep 2018 22:41:51 +0530 Subject: [PATCH] Deletion of user should also delete applicable users for the storage When a user is deleted the storage added by the user should be removed from the db. This change helps to remove the user from the applicable with the help of DBConfigService. Signed-off-by: Sujith H --- .../External/Service/UserStoragesService.php | 16 ++++++++++++++++ .../External/Service/UserStoragesServiceTest.php | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/lib/private/Files/External/Service/UserStoragesService.php b/lib/private/Files/External/Service/UserStoragesService.php index 863f9a3e1888..2d0728042d4e 100644 --- a/lib/private/Files/External/Service/UserStoragesService.php +++ b/lib/private/Files/External/Service/UserStoragesService.php @@ -150,6 +150,7 @@ protected function isApplicable(IStorageConfig $config) { */ public function deleteAllMountsForUser(IUser $user) { $getUserMounts = $this->userMountCache->getMountsForUser($user); + $allMounts = $this->dbConfig->getAllMounts(); $result = false; if (\count($getUserMounts) > 0) { foreach ($getUserMounts as $userMount) { @@ -158,6 +159,21 @@ public function deleteAllMountsForUser(IUser $user) { $result = true; } } + if (\count($allMounts)) { + foreach ($allMounts as $userMount) { + /** + * Remove any mounts which are applicable to only this user + * Specifically targeted to, mounts created by the user. + */ + if (\count($userMount['applicable']) === 1) { + foreach ($userMount['applicable'] as $applicableUser) { + if ($applicableUser['value'] === $user->getUID()) { + $this->dbConfig->removeMount($applicableUser['mount_id']); + } + } + } + } + } return $result; } } diff --git a/tests/lib/Files/External/Service/UserStoragesServiceTest.php b/tests/lib/Files/External/Service/UserStoragesServiceTest.php index b2a41c23b6e3..3b98d3a0767a 100644 --- a/tests/lib/Files/External/Service/UserStoragesServiceTest.php +++ b/tests/lib/Files/External/Service/UserStoragesServiceTest.php @@ -24,6 +24,7 @@ namespace Test\Files\External\Service; use OC\Files\Config\UserMountCache; +use OC\Files\External\Service\DBConfigService; use OC\Files\External\Service\GlobalStoragesService; use OC\Files\External\Service\UserStoragesService; use OC\Files\External\StorageConfig; @@ -258,6 +259,11 @@ public function testDeleteAllMountsForUser() { $backendService = \OC::$server->getStoragesBackendService(); $userSession = \OC::$server->getUserSession(); $this->service = new UserStoragesService($backendService, $this->dbConfig, $userSession, $userMountCache); + + $dbConfigService = new DBConfigService(\OC::$server->getDatabaseConnection(), \OC::$server->getCrypto()); + $id = $dbConfigService->addMount('/directtest', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_PERSONAl); + $dbConfigService->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'user1'); + $this->assertTrue($this->service->deleteAllMountsForUser($user1)); $storarge1Result1 = $userMountCache->getMountsForStorageId(10); $storarge1Result2 = $userMountCache->getMountsForStorageId(12); @@ -265,5 +271,6 @@ public function testDeleteAllMountsForUser() { $this->assertEquals(1, \count($storarge1Result2)); $this->assertEquals(12, $storarge1Result2[0]->getStorageId()); $this->assertEquals('/bar/', $storarge1Result2[0]->getMountPoint()); + $this->assertNull($dbConfigService->getMountById($id)); } }