Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deletion of user should also delete applicable users for the storage #32696

Merged
merged 1 commit into from
Sep 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so are we removing the user from the applicable list in a different location in the code ? (when applicable is more than one user). from your test results it seems to work so properly different existing code ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GlobalStoragesService does remove user from applicable list, here https://github.com/owncloud/core/blob/master/lib/private/Files/External/Service/GlobalStoragesService.php#L199-L214. So as per the test #32637 (comment) -> the global storages does remove user4 from the applicable list.

Let me know if this was the information, that you are looking for. If not I would need your helping hand in understanding the query.

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));
}
}