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

[stable10] Backport of Remove user from the storage setting or storag… #32069

Merged
merged 1 commit into from
Jul 18, 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
4 changes: 2 additions & 2 deletions apps/files_external/lib/Lib/Backend/AmazonS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

use OCA\Files_External\Lib\Auth\AmazonS3\AccessKey;
use OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
use OCP\Files\External\Backend\Backend;
use OCP\Files\External\Backend\Backend as ExternalBackend;
use OCP\Files\External\DefinitionParameter;
use OCP\IL10N;

class AmazonS3 extends Backend {
class AmazonS3 extends ExternalBackend {

use LegacyDependencyCheckPolyfill;

Expand Down
4 changes: 2 additions & 2 deletions apps/files_external/lib/Lib/Backend/DAV.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

use OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
use OCP\Files\External\Auth\AuthMechanism;
use OCP\Files\External\Backend\Backend;
use OCP\Files\External\Backend\Backend as ExternalBackend;
use OCP\Files\External\DefinitionParameter;
use OCP\IL10N;

class DAV extends Backend {
class DAV extends ExternalBackend {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't remember seeing this on the original PR, did you need this to avoid errors ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are right. An error was thrown for phpunit for db postgresql. So I made this change. But it looks like I might have to make few more changes to get these error cleared. I am currently looking into this issue. I will ping you in this PR once its ready.


use LegacyDependencyCheckPolyfill;

Expand Down
4 changes: 2 additions & 2 deletions apps/files_external/lib/Lib/Backend/Google.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
use OCP\IL10N;
use OCP\Files\External\DefinitionParameter;
use OCP\Files\External\Auth\AuthMechanism;
use OCP\Files\External\Backend\Backend;
use OCP\Files\External\Backend\Backend as ExternalBackend;
use OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;

class Google extends Backend {
class Google extends ExternalBackend {

use LegacyDependencyCheckPolyfill;

Expand Down
4 changes: 2 additions & 2 deletions apps/files_external/lib/Lib/Backend/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
namespace OCA\Files_External\Lib\Backend;

use OCP\Files\External\Auth\AuthMechanism;
use OCP\Files\External\Backend\Backend;
use OCP\Files\External\Backend\Backend as ExternalBackend;
use OCP\Files\External\DefinitionParameter;
use OCP\Files\External\IStoragesBackendService;
use OCP\IL10N;

class Local extends Backend {
class Local extends ExternalBackend {

public function __construct(IL10N $l) {
$this
Expand Down
4 changes: 2 additions & 2 deletions apps/files_external/lib/Lib/Backend/OwnCloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
namespace OCA\Files_External\Lib\Backend;

use OCP\Files\External\Auth\AuthMechanism;
use OCP\Files\External\Backend\Backend;
use OCP\Files\External\Backend\Backend as ExternalBackend;
use OCP\Files\External\DefinitionParameter;
use OCP\IL10N;

class OwnCloud extends Backend {
class OwnCloud extends ExternalBackend {

public function __construct(IL10N $l) {
$this
Expand Down
4 changes: 2 additions & 2 deletions apps/files_external/lib/Lib/Backend/SFTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
namespace OCA\Files_External\Lib\Backend;

use OCP\Files\External\Auth\AuthMechanism;
use OCP\Files\External\Backend\Backend;
use OCP\Files\External\Backend\Backend as ExternalBackend;
use OCP\Files\External\DefinitionParameter;
use OCP\IL10N;

class SFTP extends Backend {
class SFTP extends ExternalBackend {

public function __construct(IL10N $l) {
$this
Expand Down
4 changes: 2 additions & 2 deletions apps/files_external/lib/Lib/Backend/SFTP_Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
namespace OCA\Files_External\Lib\Backend;

use OCP\Files\External\Auth\AuthMechanism;
use OCP\Files\External\Backend\Backend;
use OCP\Files\External\Backend\Backend as ExternalBackend;
use OCP\Files\External\DefinitionParameter;
use OCP\IL10N;

class SFTP_Key extends Backend {
class SFTP_Key extends ExternalBackend {

public function __construct(IL10N $l, SFTP $sftpBackend) {
$this
Expand Down
4 changes: 2 additions & 2 deletions apps/files_external/lib/Lib/Backend/SMB.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

use OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
use OCP\Files\External\Auth\AuthMechanism;
use OCP\Files\External\Backend\Backend;
use OCP\Files\External\Backend\Backend as ExternalBackend;
use OCP\Files\External\DefinitionParameter;
use OCP\Files\External\IStorageConfig;
use OCP\IL10N;
use OCP\IUser;

class SMB extends Backend {
class SMB extends ExternalBackend {

use LegacyDependencyCheckPolyfill;

Expand Down
4 changes: 2 additions & 2 deletions apps/files_external/lib/Lib/Backend/SMB_OC.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

use OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
use OCP\Files\External\Auth\AuthMechanism;
use OCP\Files\External\Backend\Backend;
use OCP\Files\External\Backend\Backend as ExternalBackend;
use OCP\Files\External\DefinitionParameter;
use OCP\Files\External\IStorageConfig;
use OCP\Files\External\IStoragesBackendService;
Expand All @@ -34,7 +34,7 @@
/**
* Deprecated SMB_OC class - use SMB with the password::sessioncredentials auth mechanism
*/
class SMB_OC extends Backend {
class SMB_OC extends ExternalBackend {

use LegacyDependencyCheckPolyfill;

Expand Down
4 changes: 2 additions & 2 deletions apps/files_external/lib/Lib/Backend/Swift.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

use OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
use OCP\Files\External\Auth\AuthMechanism;
use OCP\Files\External\Backend\Backend;
use OCP\Files\External\Backend\Backend as ExternalBackend;
use OCP\Files\External\DefinitionParameter;
use OCP\IL10N;

class Swift extends Backend {
class Swift extends ExternalBackend {

use LegacyDependencyCheckPolyfill;

Expand Down
33 changes: 33 additions & 0 deletions lib/private/Files/External/Service/GlobalStoragesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use OCP\Files\External\IStorageConfig;
use OCP\Files\External\IStoragesBackendService;
use OCP\Files\External\Service\IGlobalStoragesService;
use OCP\IUser;

/**
* Service class to manage global external storages
Expand Down Expand Up @@ -183,4 +184,36 @@ public function getStorageForAllUsers() {

return array_combine($keys, $configs);
}

/**
* Deletes the external storages mounted to the user
*
* @param IUser $user
* @return bool
*/
public function deleteAllForUser($user) {
$userId = $user->getUID();
$result = false;
//Get all valid storages
$mounts = $this->getStorages();
foreach ($mounts as $mount) {
$applicableUsers = $mount->getApplicableUsers();
$id = $mount->getId();
if (\in_array($userId, $applicableUsers, true)) {
if (\count($applicableUsers) === 1) {
//As this storage is associated only with this user.
$this->removeStorage($id);
$result = true;
} else {
$storage = $this->getStorage($id);
$userIndex = \array_search($userId, $applicableUsers, true);
unset($applicableUsers[$userIndex]);
$storage->setApplicableUsers($applicableUsers);
$this->updateStorage($storage);
$result = true;
}
}
}
return $result;
}
}
20 changes: 20 additions & 0 deletions lib/private/Files/External/Service/UserStoragesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OC\Files\Filesystem;

use OCP\Files\Config\IUserMountCache;
use OCP\IUser;
use OCP\IUserSession;

use OCP\Files\External\IStorageConfig;
Expand Down Expand Up @@ -56,6 +57,7 @@ public function __construct(
IUserMountCache $userMountCache
) {
$this->userSession = $userSession;
$this->userMountCache = $userMountCache;
parent::__construct($backendService, $dbConfig, $userMountCache);
}

Expand Down Expand Up @@ -140,4 +142,22 @@ public function getVisibilityType() {
protected function isApplicable(IStorageConfig $config) {
return ($config->getApplicableUsers() === [$this->getUser()->getUID()]) && $config->getType() === IStorageConfig::MOUNT_TYPE_PERSONAl;
}

/**
* Deletes the storages mounted to a user
* @param IUser $user
* @return bool
*/
public function deleteAllMountsForUser(IUser $user) {
$getUserMounts = $this->userMountCache->getMountsForUser($user);
$result = false;
if (\count($getUserMounts) > 0) {
foreach ($getUserMounts as $userMount) {
$id = $userMount->getStorageId();
$this->userMountCache->removeUserStorageMount($id, $user->getUID());
$result = true;
}
}
return $result;
}
}
6 changes: 5 additions & 1 deletion lib/private/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
use OCP\IUserBackend;
use OCP\IUserSession;
use OCP\User\IChangePasswordBackend;
use OCP\UserInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\GenericEvent;

Expand Down Expand Up @@ -227,6 +226,11 @@ public function delete() {
// Delete the user's keys in preferences
\OC::$server->getConfig()->deleteAllUserValues($this->getUID());

// Delete all mount points for user
\OC::$server->getUserStoragesService()->deleteAllMountsForUser($this);
//Delete external storage or remove user from applicableUsers list
\OC::$server->getGlobalStoragesService()->deleteAllForUser($this);

// Delete user files in /data/
if ($homePath !== false) {
// FIXME: this operates directly on FS, should use View instead...
Expand Down
8 changes: 8 additions & 0 deletions lib/public/Files/External/Service/IGlobalStoragesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,12 @@ interface IGlobalStoragesService extends IStoragesService {
* @since 10.0
*/
public function getStorageForAllUsers();

/**
* Deletes the external storages mounted to the user
* @param \OCP\IUser $user
* @return bool
* @since 10.0.10
*/
public function deleteAllForUser($user);
}
8 changes: 7 additions & 1 deletion lib/public/Files/External/Service/IUserStoragesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,11 @@
* @since 10.0
*/
interface IUserStoragesService extends IStoragesService {

/**
* Deletes the storages mounted to a user
* @param \OCP\IUser $user
* @return bool
* @since 10.0.10
*/
public function deleteAllMountsForUser(\OCP\IUser $user);
}
Loading