Skip to content

Commit 14eb4c0

Browse files
authored
Merge pull request #53743 from nextcloud/backport/53304/stable31
[stable31] fix(files_sharing): Hide own reshares
2 parents 5cdee9f + 0cf2295 commit 14eb4c0

5 files changed

Lines changed: 58 additions & 109 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: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
namespace OCA\Files\Service;
1111

1212
use Closure;
13+
use Exception;
1314
use OC\Files\Filesystem;
1415
use OC\Files\View;
1516
use OC\User\NoUserException;
1617
use OCA\Encryption\Util;
1718
use OCA\Files\Exception\TransferOwnershipException;
1819
use OCP\Encryption\IManager as IEncryptionManager;
1920
use OCP\Files\Config\IUserMountCache;
21+
use OCP\Files\File;
2022
use OCP\Files\FileInfo;
2123
use OCP\Files\IHomeStorage;
2224
use OCP\Files\InvalidPathException;
@@ -69,7 +71,6 @@ public function transfer(
6971
?OutputInterface $output = null,
7072
bool $move = false,
7173
bool $firstLogin = false,
72-
bool $transferIncomingShares = false,
7374
): void {
7475
$output = $output ?? new NullOutput();
7576
$sourceUid = $sourceUser->getUID();
@@ -154,29 +155,26 @@ public function transfer(
154155
$sizeDifference = $sourceSize - $view->getFileInfo($finalTarget)->getSize();
155156

156157
// transfer the incoming shares
157-
if ($transferIncomingShares === true) {
158-
$sourceShares = $this->collectIncomingShares(
159-
$sourceUid,
160-
$output,
161-
$view
162-
);
163-
$destinationShares = $this->collectIncomingShares(
164-
$destinationUid,
165-
$output,
166-
$view,
167-
true
168-
);
169-
$this->transferIncomingShares(
170-
$sourceUid,
171-
$destinationUid,
172-
$sourceShares,
173-
$destinationShares,
174-
$output,
175-
$path,
176-
$finalTarget,
177-
$move
178-
);
179-
}
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+
);
180178

181179
$destinationPath = $finalTarget . '/' . $path;
182180
// restore the shares
@@ -333,7 +331,7 @@ private function collectUsersShares(
333331
return mb_strpos(
334332
Filesystem::normalizePath($relativePath . '/', false),
335333
$normalizedPath . '/') === 0;
336-
} catch (\Exception $e) {
334+
} catch (Exception $e) {
337335
return false;
338336
}
339337
});
@@ -361,14 +359,16 @@ private function collectUsersShares(
361359
}, $shares)));
362360
}
363361

364-
private function collectIncomingShares(string $sourceUid,
362+
private function collectIncomingShares(
363+
string $sourceUid,
365364
OutputInterface $output,
366-
View $view,
367-
bool $addKeys = false): array {
365+
?string $path,
366+
): array {
368367
$output->writeln("Collecting all incoming share information for files and folders of $sourceUid ...");
369368

370369
$shares = [];
371370
$progress = new ProgressBar($output);
371+
$normalizedPath = Filesystem::normalizePath($path);
372372

373373
$offset = 0;
374374
while (true) {
@@ -377,14 +377,19 @@ private function collectIncomingShares(string $sourceUid,
377377
if (empty($sharePage)) {
378378
break;
379379
}
380-
if ($addKeys) {
381-
foreach ($sharePage as $singleShare) {
382-
$shares[$singleShare->getNodeId()] = $singleShare;
383-
}
384-
} else {
385-
foreach ($sharePage as $singleShare) {
386-
$shares[] = $singleShare;
387-
}
380+
381+
if ($path !== null && $path !== "$sourceUid/files") {
382+
$sharePage = array_filter($sharePage, static function (IShare $share) use ($sourceUid, $normalizedPath) {
383+
try {
384+
return str_starts_with(Filesystem::normalizePath($sourceUid . '/files' . $share->getTarget() . '/', false), $normalizedPath . '/');
385+
} catch (Exception) {
386+
return false;
387+
}
388+
});
389+
}
390+
391+
foreach ($sharePage as $share) {
392+
$shares[$share->getNodeId()] = $share;
388393
}
389394

390395
$offset += 50;

apps/files_sharing/lib/MountProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
5353

5454
// filter out excluded shares and group shares that includes self
5555
$shares = array_filter($shares, function (IShare $share) use ($user) {
56-
return $share->getPermissions() > 0 && $share->getShareOwner() !== $user->getUID();
56+
return $share->getPermissions() > 0 && $share->getShareOwner() !== $user->getUID() && $share->getSharedBy() !== $user->getUID();
5757
});
5858

5959
$superShares = $this->buildSuperShares($shares, $user);

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)