Merge pull request #3965 from nextcloud/downstream-27343
Providing --path option to transfer-ownership
This commit is contained in:
commit
d2654c8aea
|
@ -34,6 +34,7 @@ use OCP\IUserManager;
|
||||||
use OCP\Share\IManager;
|
use OCP\Share\IManager;
|
||||||
use OCP\Share\IShare;
|
use OCP\Share\IShare;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Helper\ProgressBar;
|
use Symfony\Component\Console\Helper\ProgressBar;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
@ -65,6 +66,9 @@ class TransferOwnership extends Command {
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $destinationUser;
|
private $destinationUser;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
private $sourcePath;
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $finalTarget;
|
private $finalTarget;
|
||||||
|
|
||||||
|
@ -88,6 +92,13 @@ class TransferOwnership extends Command {
|
||||||
'destination-user',
|
'destination-user',
|
||||||
InputArgument::REQUIRED,
|
InputArgument::REQUIRED,
|
||||||
'user who will be the new owner of the files'
|
'user who will be the new owner of the files'
|
||||||
|
)
|
||||||
|
->addOption(
|
||||||
|
'path',
|
||||||
|
null,
|
||||||
|
InputOption::VALUE_REQUIRED,
|
||||||
|
'selectively provide the path to transfer. For example --path="folder_name"',
|
||||||
|
''
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +118,8 @@ class TransferOwnership extends Command {
|
||||||
|
|
||||||
$this->sourceUser = $sourceUserObject->getUID();
|
$this->sourceUser = $sourceUserObject->getUID();
|
||||||
$this->destinationUser = $destinationUserObject->getUID();
|
$this->destinationUser = $destinationUserObject->getUID();
|
||||||
|
$sourcePathOption = ltrim($input->getOption('path'), '/');
|
||||||
|
$this->sourcePath = rtrim($this->sourceUser . '/files/' . $sourcePathOption, '/');
|
||||||
|
|
||||||
// target user has to be ready
|
// target user has to be ready
|
||||||
if (!\OC::$server->getEncryptionManager()->isReadyForUser($this->destinationUser)) {
|
if (!\OC::$server->getEncryptionManager()->isReadyForUser($this->destinationUser)) {
|
||||||
|
@ -121,6 +134,12 @@ class TransferOwnership extends Command {
|
||||||
Filesystem::initMountPoints($this->sourceUser);
|
Filesystem::initMountPoints($this->sourceUser);
|
||||||
Filesystem::initMountPoints($this->destinationUser);
|
Filesystem::initMountPoints($this->destinationUser);
|
||||||
|
|
||||||
|
$view = new View();
|
||||||
|
if (!$view->is_dir($this->sourcePath)) {
|
||||||
|
$output->writeln("<error>Unknown path provided: $sourcePathOption</error>");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// analyse source folder
|
// analyse source folder
|
||||||
$this->analyse($output);
|
$this->analyse($output);
|
||||||
|
|
||||||
|
@ -155,7 +174,8 @@ class TransferOwnership extends Command {
|
||||||
$progress = new ProgressBar($output);
|
$progress = new ProgressBar($output);
|
||||||
$progress->start();
|
$progress->start();
|
||||||
$self = $this;
|
$self = $this;
|
||||||
$this->walkFiles($view, "$this->sourceUser/files",
|
|
||||||
|
$this->walkFiles($view, $this->sourcePath,
|
||||||
function (FileInfo $fileInfo) use ($progress, $self) {
|
function (FileInfo $fileInfo) use ($progress, $self) {
|
||||||
if ($fileInfo->getType() === FileInfo::TYPE_FOLDER) {
|
if ($fileInfo->getType() === FileInfo::TYPE_FOLDER) {
|
||||||
// only analyze into folders from main storage,
|
// only analyze into folders from main storage,
|
||||||
|
@ -216,10 +236,19 @@ class TransferOwnership extends Command {
|
||||||
protected function transfer(OutputInterface $output) {
|
protected function transfer(OutputInterface $output) {
|
||||||
$view = new View();
|
$view = new View();
|
||||||
$output->writeln("Transferring files to $this->finalTarget ...");
|
$output->writeln("Transferring files to $this->finalTarget ...");
|
||||||
$view->rename("$this->sourceUser/files", $this->finalTarget);
|
|
||||||
|
// This change will help user to transfer the folder specified using --path option.
|
||||||
|
// Else only the content inside folder is transferred which is not correct.
|
||||||
|
if($this->sourcePath !== "$this->sourceUser/files") {
|
||||||
|
$view->mkdir($this->finalTarget);
|
||||||
|
$this->finalTarget = $this->finalTarget . '/' . basename($this->sourcePath);
|
||||||
|
}
|
||||||
|
$view->rename($this->sourcePath, $this->finalTarget);
|
||||||
|
if (!is_dir("$this->sourceUser/files")) {
|
||||||
// because the files folder is moved away we need to recreate it
|
// because the files folder is moved away we need to recreate it
|
||||||
$view->mkdir("$this->sourceUser/files");
|
$view->mkdir("$this->sourceUser/files");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param OutputInterface $output
|
* @param OutputInterface $output
|
||||||
|
|
|
@ -88,6 +88,20 @@ class CommandLineContext implements \Behat\Behat\Context\Context {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @When /^transfering ownership of path "([^"]+)" from "([^"]+)" to "([^"]+)"/
|
||||||
|
*/
|
||||||
|
public function transferingOwnershipPath($path, $user1, $user2) {
|
||||||
|
$path = '--path=' . $path;
|
||||||
|
if($this->runOcc(['files:transfer-ownership', $path, $user1, $user2]) === 0) {
|
||||||
|
$this->lastTransferPath = $this->findLastTransferFolderForUser($user1, $user2);
|
||||||
|
} else {
|
||||||
|
// failure
|
||||||
|
$this->lastTransferPath = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @When /^using received transfer folder of "([^"]+)" as dav path$/
|
* @When /^using received transfer folder of "([^"]+)" as dav path$/
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -117,3 +117,110 @@ Feature: transfer-ownership
|
||||||
Then the command error output contains the text "Unknown target user"
|
Then the command error output contains the text "Unknown target user"
|
||||||
And the command failed with exit code 1
|
And the command failed with exit code 1
|
||||||
|
|
||||||
|
Scenario: transfering ownership of a folder
|
||||||
|
Given user "user0" exists
|
||||||
|
And user "user1" exists
|
||||||
|
And User "user0" created a folder "/test"
|
||||||
|
And User "user0" uploads file "data/textfile.txt" to "/test/somefile.txt"
|
||||||
|
When transfering ownership of path "test" from "user0" to "user1"
|
||||||
|
And the command was successful
|
||||||
|
And As an "user1"
|
||||||
|
And using received transfer folder of "user1" as dav path
|
||||||
|
Then Downloaded content when downloading file "/test/somefile.txt" with range "bytes=0-6" should be "This is"
|
||||||
|
|
||||||
|
Scenario: transfering ownership of file shares
|
||||||
|
Given user "user0" exists
|
||||||
|
And user "user1" exists
|
||||||
|
And user "user2" exists
|
||||||
|
And User "user0" created a folder "/test"
|
||||||
|
And User "user0" uploads file "data/textfile.txt" to "/test/somefile.txt"
|
||||||
|
And file "/test/somefile.txt" of user "user0" is shared with user "user2" with permissions 19
|
||||||
|
When transfering ownership of path "test" from "user0" to "user1"
|
||||||
|
And the command was successful
|
||||||
|
And As an "user2"
|
||||||
|
Then Downloaded content when downloading file "/somefile.txt" with range "bytes=0-6" should be "This is"
|
||||||
|
|
||||||
|
Scenario: transfering ownership of folder shared with third user
|
||||||
|
Given user "user0" exists
|
||||||
|
And user "user1" exists
|
||||||
|
And user "user2" exists
|
||||||
|
And User "user0" created a folder "/test"
|
||||||
|
And User "user0" uploads file "data/textfile.txt" to "/test/somefile.txt"
|
||||||
|
And folder "/test" of user "user0" is shared with user "user2" with permissions 31
|
||||||
|
When transfering ownership of path "test" from "user0" to "user1"
|
||||||
|
And the command was successful
|
||||||
|
And As an "user2"
|
||||||
|
Then Downloaded content when downloading file "/test/somefile.txt" with range "bytes=0-6" should be "This is"
|
||||||
|
|
||||||
|
Scenario: transfering ownership of folder shared with transfer recipient
|
||||||
|
Given user "user0" exists
|
||||||
|
And user "user1" exists
|
||||||
|
And User "user0" created a folder "/test"
|
||||||
|
And User "user0" uploads file "data/textfile.txt" to "/test/somefile.txt"
|
||||||
|
And folder "/test" of user "user0" is shared with user "user1" with permissions 31
|
||||||
|
When transfering ownership of path "test" from "user0" to "user1"
|
||||||
|
And the command was successful
|
||||||
|
And As an "user1"
|
||||||
|
Then as "user1" the folder "/test" does not exist
|
||||||
|
And using received transfer folder of "user1" as dav path
|
||||||
|
And Downloaded content when downloading file "/test/somefile.txt" with range "bytes=0-6" should be "This is"
|
||||||
|
|
||||||
|
Scenario: transfering ownership of folder doubly shared with third user
|
||||||
|
Given group "group1" exists
|
||||||
|
And user "user0" exists
|
||||||
|
And user "user1" exists
|
||||||
|
And user "user2" exists
|
||||||
|
And user "user2" belongs to group "group1"
|
||||||
|
And User "user0" created a folder "/test"
|
||||||
|
And User "user0" uploads file "data/textfile.txt" to "/test/somefile.txt"
|
||||||
|
And folder "/test" of user "user0" is shared with group "group1" with permissions 31
|
||||||
|
And folder "/test" of user "user0" is shared with user "user2" with permissions 31
|
||||||
|
When transfering ownership of path "test" from "user0" to "user1"
|
||||||
|
And the command was successful
|
||||||
|
And As an "user2"
|
||||||
|
Then Downloaded content when downloading file "/test/somefile.txt" with range "bytes=0-6" should be "This is"
|
||||||
|
|
||||||
|
Scenario: transfering ownership does not transfer received shares
|
||||||
|
Given user "user0" exists
|
||||||
|
And user "user1" exists
|
||||||
|
And user "user2" exists
|
||||||
|
And User "user2" created a folder "/test"
|
||||||
|
And User "user0" created a folder "/sub"
|
||||||
|
And folder "/test" of user "user2" is shared with user "user0" with permissions 31
|
||||||
|
And User "user0" moved folder "/test" to "/sub/test"
|
||||||
|
When transfering ownership of path "sub" from "user0" to "user1"
|
||||||
|
And the command was successful
|
||||||
|
And As an "user1"
|
||||||
|
And using received transfer folder of "user1" as dav path
|
||||||
|
Then as "user1" the folder "/sub/test" does not exist
|
||||||
|
|
||||||
|
Scenario: transfering ownership does not transfer external storage
|
||||||
|
Given user "user0" exists
|
||||||
|
And user "user1" exists
|
||||||
|
And User "user0" created a folder "/sub"
|
||||||
|
When transfering ownership of path "sub" from "user0" to "user1"
|
||||||
|
And the command was successful
|
||||||
|
And As an "user1"
|
||||||
|
And using received transfer folder of "user1" as dav path
|
||||||
|
Then as "user1" the folder "/local_storage" does not exist
|
||||||
|
|
||||||
|
Scenario: transfering ownership fails with invalid source user
|
||||||
|
Given user "user0" exists
|
||||||
|
And User "user0" created a folder "/sub"
|
||||||
|
When transfering ownership of path "sub" from "invalid_user" to "user0"
|
||||||
|
Then the command error output contains the text "Unknown source user"
|
||||||
|
And the command failed with exit code 1
|
||||||
|
|
||||||
|
Scenario: transfering ownership fails with invalid target user
|
||||||
|
Given user "user0" exists
|
||||||
|
And User "user0" created a folder "/sub"
|
||||||
|
When transfering ownership of path "sub" from "user0" to "invalid_user"
|
||||||
|
Then the command error output contains the text "Unknown target user"
|
||||||
|
And the command failed with exit code 1
|
||||||
|
|
||||||
|
Scenario: transfering ownership fails with invalid path
|
||||||
|
Given user "user0" exists
|
||||||
|
And user "user1" exists
|
||||||
|
When transfering ownership of path "test" from "user0" to "user1"
|
||||||
|
Then the command error output contains the text "Unknown target user"
|
||||||
|
And the command failed with exit code 1
|
||||||
|
|
Loading…
Reference in New Issue