Skip to content

Commit 30e7d3e

Browse files
authored
Merge pull request #14194 from nextcloud/bugfix/noid/correctly-determinate-owner-in-case-of-shared-external-storages
Correctly determinate the owner in case of shared external storages
2 parents ef4e7d0 + f66c37b commit 30e7d3e

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

lib/private/Share20/Manager.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,10 +1419,12 @@ public function getAccessList(\OCP\Files\Node $path, $recursive = true, $current
14191419
return $al;
14201420
}
14211421

1422-
//Get node for the owner
1422+
//Get node for the owner and correct the owner in case of external storages
14231423
$userFolder = $this->rootFolder->getUserFolder($owner);
14241424
if ($path->getId() !== $userFolder->getId() && !$userFolder->isSubNode($path)) {
1425-
$path = $userFolder->getById($path->getId())[0];
1425+
$nodes = $userFolder->getById($path->getId());
1426+
$path = array_shift($nodes);
1427+
$owner = $path->getOwner()->getUID();
14261428
}
14271429

14281430
$providers = $this->factory->getAllProviders();

tests/lib/Share20/ManagerTest.php

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3427,26 +3427,33 @@ public function testGetAccessList() {
34273427
$extraProvider = $this->createMock(IShareProvider::class);
34283428
$factory->setSecondProvider($extraProvider);
34293429

3430-
$owner = $this->createMock(IUser::class);
3431-
$owner->expects($this->once())
3430+
$nodeOwner = $this->createMock(IUser::class);
3431+
$nodeOwner->expects($this->once())
34323432
->method('getUID')
3433-
->willReturn('owner');
3433+
->willReturn('user1');
34343434

34353435
$node = $this->createMock(Node::class);
34363436
$node->expects($this->once())
34373437
->method('getOwner')
3438-
->willReturn($owner);
3438+
->willReturn($nodeOwner);
34393439
$node->method('getId')
34403440
->willReturn(42);
34413441

34423442
$userFolder = $this->createMock(Folder::class);
34433443
$file = $this->createMock(File::class);
34443444
$folder = $this->createMock(Folder::class);
34453445

3446+
$owner = $this->createMock(IUser::class);
3447+
$owner->expects($this->once())
3448+
->method('getUID')
3449+
->willReturn('owner');
3450+
34463451
$file->method('getParent')
34473452
->willReturn($folder);
34483453
$file->method('getPath')
34493454
->willReturn('/owner/files/folder/file');
3455+
$file->method('getOwner')
3456+
->willReturn($owner);
34503457
$file->method('getId')
34513458
->willReturn(23);
34523459
$folder->method('getParent')
@@ -3455,12 +3462,12 @@ public function testGetAccessList() {
34553462
->willReturn('/owner/files/folder');
34563463
$userFolder->method('getById')
34573464
->with($this->equalTo(42))
3458-
->willReturn([$file]);
3465+
->willReturn([12 => $file]);
34593466
$userFolder->method('getPath')
3460-
->willReturn('/owner/files');
3467+
->willReturn('/user1/files');
34613468

34623469
$this->userManager->method('userExists')
3463-
->with($this->equalTo('owner'))
3470+
->with($this->equalTo('user1'))
34643471
->willReturn(true);
34653472

34663473
$this->defaultProvider->method('getAccessList')
@@ -3494,7 +3501,7 @@ public function testGetAccessList() {
34943501
]);
34953502

34963503
$this->rootFolder->method('getUserFolder')
3497-
->with($this->equalTo('owner'))
3504+
->with($this->equalTo('user1'))
34983505
->willReturn($userFolder);
34993506

35003507
$expected = [
@@ -3536,26 +3543,33 @@ public function testGetAccessListWithCurrentAccess() {
35363543
$extraProvider = $this->createMock(IShareProvider::class);
35373544
$factory->setSecondProvider($extraProvider);
35383545

3539-
$owner = $this->createMock(IUser::class);
3540-
$owner->expects($this->once())
3546+
$nodeOwner = $this->createMock(IUser::class);
3547+
$nodeOwner->expects($this->once())
35413548
->method('getUID')
3542-
->willReturn('owner');
3549+
->willReturn('user1');
35433550

35443551
$node = $this->createMock(Node::class);
35453552
$node->expects($this->once())
35463553
->method('getOwner')
3547-
->willReturn($owner);
3554+
->willReturn($nodeOwner);
35483555
$node->method('getId')
35493556
->willReturn(42);
35503557

35513558
$userFolder = $this->createMock(Folder::class);
35523559
$file = $this->createMock(File::class);
3560+
3561+
$owner = $this->createMock(IUser::class);
3562+
$owner->expects($this->once())
3563+
->method('getUID')
3564+
->willReturn('owner');
35533565
$folder = $this->createMock(Folder::class);
35543566

35553567
$file->method('getParent')
35563568
->willReturn($folder);
35573569
$file->method('getPath')
35583570
->willReturn('/owner/files/folder/file');
3571+
$file->method('getOwner')
3572+
->willReturn($owner);
35593573
$file->method('getId')
35603574
->willReturn(23);
35613575
$folder->method('getParent')
@@ -3564,12 +3578,12 @@ public function testGetAccessListWithCurrentAccess() {
35643578
->willReturn('/owner/files/folder');
35653579
$userFolder->method('getById')
35663580
->with($this->equalTo(42))
3567-
->willReturn([$file]);
3581+
->willReturn([42 => $file]);
35683582
$userFolder->method('getPath')
3569-
->willReturn('/owner/files');
3583+
->willReturn('/user1/files');
35703584

35713585
$this->userManager->method('userExists')
3572-
->with($this->equalTo('owner'))
3586+
->with($this->equalTo('user1'))
35733587
->willReturn(true);
35743588

35753589
$this->defaultProvider->method('getAccessList')
@@ -3605,7 +3619,7 @@ public function testGetAccessListWithCurrentAccess() {
36053619
]);
36063620

36073621
$this->rootFolder->method('getUserFolder')
3608-
->with($this->equalTo('owner'))
3622+
->with($this->equalTo('user1'))
36093623
->willReturn($userFolder);
36103624

36113625
$expected = [

0 commit comments

Comments
 (0)