Skip to content

Commit

Permalink
Merge pull request #32696 from owncloud/fix-deletion-of-applicable-users
Browse files Browse the repository at this point in the history
Deletion of user should also delete applicable users for the storage
  • Loading branch information
Vincent Petry authored Sep 27, 2018
2 parents 2a37c38 + 35bb075 commit 4dad523
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/private/Files/External/Service/UserStoragesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
}
7 changes: 7 additions & 0 deletions tests/lib/Files/External/Service/UserStoragesServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -258,12 +259,18 @@ 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);
$this->assertEquals(0, \count($storarge1Result1));
$this->assertEquals(1, \count($storarge1Result2));
$this->assertEquals(12, $storarge1Result2[0]->getStorageId());
$this->assertEquals('/bar/', $storarge1Result2[0]->getMountPoint());
$this->assertNull($dbConfigService->getMountById($id));
}
}

0 comments on commit 4dad523

Please sign in to comment.