Skip to content

Commit 987af41

Browse files
committed
fix(files): Always transfer incoming shares when doing ownership transfer to prevent broken reshares
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent 918473d commit 987af41

4 files changed

Lines changed: 36 additions & 95 deletions

File tree

apps/files/lib/Command/TransferOwnership.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected function configure(): void {
5858
'transfer-incoming-shares',
5959
null,
6060
InputOption::VALUE_OPTIONAL,
61-
'transfer incoming user file shares to destination user. Usage: --transfer-incoming-shares=1 (value required)',
61+
'Incoming shares are always transferred now, so this option does not affect the ownership transfer anymore',
6262
'2'
6363
);
6464
}
@@ -88,35 +88,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8888
}
8989

9090
try {
91-
$includeIncomingArgument = $input->getOption('transfer-incoming-shares');
92-
93-
switch ($includeIncomingArgument) {
94-
case '0':
95-
$includeIncoming = false;
96-
break;
97-
case '1':
98-
$includeIncoming = true;
99-
break;
100-
case '2':
101-
$includeIncoming = $this->config->getSystemValue('transferIncomingShares', false);
102-
if (gettype($includeIncoming) !== 'boolean') {
103-
$output->writeln("<error> config.php: 'transfer-incoming-shares': wrong usage. Transfer aborted.</error>");
104-
return self::FAILURE;
105-
}
106-
break;
107-
default:
108-
$output->writeln('<error>Option --transfer-incoming-shares: wrong usage. Transfer aborted.</error>');
109-
return self::FAILURE;
110-
}
111-
11291
$this->transferService->transfer(
11392
$sourceUserObject,
11493
$destinationUserObject,
11594
ltrim($input->getOption('path'), '/'),
11695
$output,
11796
$input->getOption('move') === true,
11897
false,
119-
$includeIncoming
12098
);
12199
} catch (TransferOwnershipException $e) {
122100
$output->writeln('<error>' . $e->getMessage() . '</error>');

apps/files/lib/Service/OwnershipTransferService.php

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public function transfer(
7171
?OutputInterface $output = null,
7272
bool $move = false,
7373
bool $firstLogin = false,
74-
bool $transferIncomingShares = false,
7574
): void {
7675
$output = $output ?? new NullOutput();
7776
$sourceUid = $sourceUser->getUID();
@@ -156,28 +155,26 @@ public function transfer(
156155
$sizeDifference = $sourceSize - $view->getFileInfo($finalTarget)->getSize();
157156

158157
// transfer the incoming shares
159-
if ($transferIncomingShares === true) {
160-
$sourceShares = $this->collectIncomingShares(
161-
$sourceUid,
162-
$output,
163-
$sourcePath,
164-
);
165-
$destinationShares = $this->collectIncomingShares(
166-
$destinationUid,
167-
$output,
168-
null,
169-
);
170-
$this->transferIncomingShares(
171-
$sourceUid,
172-
$destinationUid,
173-
$sourceShares,
174-
$destinationShares,
175-
$output,
176-
$path,
177-
$finalTarget,
178-
$move
179-
);
180-
}
158+
$sourceShares = $this->collectIncomingShares(
159+
$sourceUid,
160+
$output,
161+
$sourcePath,
162+
);
163+
$destinationShares = $this->collectIncomingShares(
164+
$destinationUid,
165+
$output,
166+
null,
167+
);
168+
$this->transferIncomingShares(
169+
$sourceUid,
170+
$destinationUid,
171+
$sourceShares,
172+
$destinationShares,
173+
$output,
174+
$path,
175+
$finalTarget,
176+
$move
177+
);
181178

182179
$destinationPath = $finalTarget . '/' . $path;
183180
// restore the shares

build/integration/features/bootstrap/CommandLineContext.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,6 @@ public function transferringOwnershipPath($path, $user1, $user2) {
108108
}
109109
}
110110

111-
/**
112-
* @When /^transferring ownership of path "([^"]+)" from "([^"]+)" to "([^"]+)" with received shares$/
113-
*/
114-
public function transferringOwnershipPathWithIncomingShares($path, $user1, $user2) {
115-
$path = '--path=' . $path;
116-
if ($this->runOcc(['files:transfer-ownership', $path, $user1, $user2, '--transfer-incoming-shares=1']) === 0) {
117-
$this->lastTransferPath = $this->findLastTransferFolderForUser($user1, $user2);
118-
} else {
119-
// failure
120-
$this->lastTransferPath = null;
121-
}
122-
}
123-
124111
/**
125112
* @When /^using received transfer folder of "([^"]+)" as dav path$/
126113
*/

build/integration/files_features/transfer-ownership.feature

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ Feature: transfer-ownership
184184
And As an "user2"
185185
Then Downloaded content when downloading file "/test/somefile.txt" with range "bytes=0-6" should be "This is"
186186
And using old dav path
187-
And as "user0" the folder "/test" exists
187+
And as "user0" the folder "/test" does not exist
188188
And using received transfer folder of "user1" as dav path
189-
And as "user1" the folder "/test" does not exist
190-
And As an "user0"
189+
And as "user1" the folder "/test" exists
190+
And As an "user1"
191191
And Getting info of last share
192192
And the OCS status code should be "100"
193193
And Share fields of last share match with
@@ -210,13 +210,12 @@ Feature: transfer-ownership
210210
And user "user1" accepts last share
211211
When transferring ownership from "user0" to "user1"
212212
And the command was successful
213-
And As an "user1"
214-
Then Downloaded content when downloading file "/test/somefile.txt" with range "bytes=0-6" should be "This is"
215213
And using old dav path
216-
And as "user0" the folder "/test" exists
214+
Then as "user0" the folder "/test" does not exist
215+
When As an "user1"
217216
And using received transfer folder of "user1" as dav path
218-
And as "user1" the folder "/test" does not exist
219-
And As an "user1"
217+
Then as "user1" the folder "/test" exists
218+
And Downloaded content when downloading file "/test/somefile.txt" with range "bytes=0-6" should be "This is"
220219
And Getting info of last share
221220
And the OCS status code should be "100"
222221
And Share fields of last share match with
@@ -242,18 +241,18 @@ Feature: transfer-ownership
242241
And As an "user2"
243242
Then Downloaded content when downloading file "/test/somefile.txt" with range "bytes=0-6" should be "This is"
244243
And using old dav path
245-
And as "user0" the folder "/test" exists
244+
And as "user0" the folder "/test" does not exist
246245
And using received transfer folder of "user1" as dav path
247-
And as "user1" the folder "/test" does not exist
248-
And As an "user0"
246+
And as "user1" the folder "/test" exists
247+
And As an "user1"
249248
And Getting info of last share
250249
And the OCS status code should be "100"
251250
And Share fields of last share match with
252251
| uid_owner | user0 |
253252
| uid_file_owner | user3 |
254253
| share_with | group1 |
255254

256-
Scenario: transferring ownership does not transfer received shares
255+
Scenario: transferring ownership transfers received shares
257256
Given user "user0" exists
258257
And user "user1" exists
259258
And user "user2" exists
@@ -264,16 +263,16 @@ Feature: transfer-ownership
264263
And the command was successful
265264
And As an "user1"
266265
And using received transfer folder of "user1" as dav path
267-
Then as "user1" the folder "/test" does not exist
266+
Then as "user1" the folder "/test" exists
268267
And using old dav path
269-
And as "user0" the folder "/test" exists
268+
And as "user0" the folder "/test" does not exist
270269
And As an "user2"
271270
And Getting info of last share
272271
And the OCS status code should be "100"
273272
And Share fields of last share match with
274273
| uid_owner | user2 |
275274
| uid_file_owner | user2 |
276-
| share_with | user0 |
275+
| share_with | user1 |
277276

278277
@local_storage
279278
Scenario: transferring ownership does not transfer external storage
@@ -516,26 +515,6 @@ Feature: transfer-ownership
516515
Then the command failed with exit code 1
517516
And the command error output contains the text "Moving a storage (user0/files/test) into another storage (user1) is not allowed"
518517

519-
Scenario: transferring ownership does not transfer received shares
520-
Given user "user0" exists
521-
And user "user1" exists
522-
And user "user2" exists
523-
And User "user2" created a folder "/test"
524-
And User "user0" created a folder "/sub"
525-
And folder "/test" of user "user2" is shared with user "user0" with permissions 31
526-
And user "user0" accepts last share
527-
And User "user0" moved folder "/test" to "/sub/test"
528-
When transferring ownership of path "sub" from "user0" to "user1"
529-
And the command was successful
530-
And As an "user1"
531-
And using received transfer folder of "user1" as dav path
532-
Then as "user1" the folder "/sub" exists
533-
And as "user1" the folder "/sub/test" does not exist
534-
And using old dav path
535-
And as "user0" the folder "/sub" does not exist
536-
And Getting info of last share
537-
And the OCS status code should be "404"
538-
539518
Scenario: transferring ownership transfers received shares into subdir when requested
540519
Given user "user0" exists
541520
And user "user1" exists
@@ -548,7 +527,7 @@ Feature: transfer-ownership
548527
And User "user0" moved folder "/transfer-share" to "/sub/transfer-share"
549528
And folder "/do-not-transfer" of user "user2" is shared with user "user0" with permissions 31
550529
And user "user0" accepts last share
551-
When transferring ownership of path "sub" from "user0" to "user1" with received shares
530+
When transferring ownership of path "sub" from "user0" to "user1"
552531
And the command was successful
553532
And As an "user1"
554533
And using received transfer folder of "user1" as dav path

0 commit comments

Comments
 (0)