Browse Source

Correctly determinate the owner in case of shared external storages

Signed-off-by: Joas Schilling <coding@schilljs.com>
tags/v16.0.0alpha1
Joas Schilling 5 years ago
parent
commit
f66c37bdb8
No account linked to committer's email address
2 changed files with 34 additions and 18 deletions
  1. 4
    2
      lib/private/Share20/Manager.php
  2. 30
    16
      tests/lib/Share20/ManagerTest.php

+ 4
- 2
lib/private/Share20/Manager.php View File

return $al; return $al;
} }


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


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

+ 30
- 16
tests/lib/Share20/ManagerTest.php View File

$extraProvider = $this->createMock(IShareProvider::class); $extraProvider = $this->createMock(IShareProvider::class);
$factory->setSecondProvider($extraProvider); $factory->setSecondProvider($extraProvider);


$owner = $this->createMock(IUser::class);
$owner->expects($this->once())
$nodeOwner = $this->createMock(IUser::class);
$nodeOwner->expects($this->once())
->method('getUID') ->method('getUID')
->willReturn('owner');
->willReturn('user1');


$node = $this->createMock(Node::class); $node = $this->createMock(Node::class);
$node->expects($this->once()) $node->expects($this->once())
->method('getOwner') ->method('getOwner')
->willReturn($owner);
->willReturn($nodeOwner);
$node->method('getId') $node->method('getId')
->willReturn(42); ->willReturn(42);


$file = $this->createMock(File::class); $file = $this->createMock(File::class);
$folder = $this->createMock(Folder::class); $folder = $this->createMock(Folder::class);


$owner = $this->createMock(IUser::class);
$owner->expects($this->once())
->method('getUID')
->willReturn('owner');

$file->method('getParent') $file->method('getParent')
->willReturn($folder); ->willReturn($folder);
$file->method('getPath') $file->method('getPath')
->willReturn('/owner/files/folder/file'); ->willReturn('/owner/files/folder/file');
$file->method('getOwner')
->willReturn($owner);
$file->method('getId') $file->method('getId')
->willReturn(23); ->willReturn(23);
$folder->method('getParent') $folder->method('getParent')
->willReturn('/owner/files/folder'); ->willReturn('/owner/files/folder');
$userFolder->method('getById') $userFolder->method('getById')
->with($this->equalTo(42)) ->with($this->equalTo(42))
->willReturn([$file]);
->willReturn([12 => $file]);
$userFolder->method('getPath') $userFolder->method('getPath')
->willReturn('/owner/files');
->willReturn('/user1/files');


$this->userManager->method('userExists') $this->userManager->method('userExists')
->with($this->equalTo('owner'))
->with($this->equalTo('user1'))
->willReturn(true); ->willReturn(true);


$this->defaultProvider->method('getAccessList') $this->defaultProvider->method('getAccessList')
]); ]);


$this->rootFolder->method('getUserFolder') $this->rootFolder->method('getUserFolder')
->with($this->equalTo('owner'))
->with($this->equalTo('user1'))
->willReturn($userFolder); ->willReturn($userFolder);


$expected = [ $expected = [
$extraProvider = $this->createMock(IShareProvider::class); $extraProvider = $this->createMock(IShareProvider::class);
$factory->setSecondProvider($extraProvider); $factory->setSecondProvider($extraProvider);


$owner = $this->createMock(IUser::class);
$owner->expects($this->once())
$nodeOwner = $this->createMock(IUser::class);
$nodeOwner->expects($this->once())
->method('getUID') ->method('getUID')
->willReturn('owner');
->willReturn('user1');


$node = $this->createMock(Node::class); $node = $this->createMock(Node::class);
$node->expects($this->once()) $node->expects($this->once())
->method('getOwner') ->method('getOwner')
->willReturn($owner);
->willReturn($nodeOwner);
$node->method('getId') $node->method('getId')
->willReturn(42); ->willReturn(42);


$userFolder = $this->createMock(Folder::class); $userFolder = $this->createMock(Folder::class);
$file = $this->createMock(File::class); $file = $this->createMock(File::class);

$owner = $this->createMock(IUser::class);
$owner->expects($this->once())
->method('getUID')
->willReturn('owner');
$folder = $this->createMock(Folder::class); $folder = $this->createMock(Folder::class);


$file->method('getParent') $file->method('getParent')
->willReturn($folder); ->willReturn($folder);
$file->method('getPath') $file->method('getPath')
->willReturn('/owner/files/folder/file'); ->willReturn('/owner/files/folder/file');
$file->method('getOwner')
->willReturn($owner);
$file->method('getId') $file->method('getId')
->willReturn(23); ->willReturn(23);
$folder->method('getParent') $folder->method('getParent')
->willReturn('/owner/files/folder'); ->willReturn('/owner/files/folder');
$userFolder->method('getById') $userFolder->method('getById')
->with($this->equalTo(42)) ->with($this->equalTo(42))
->willReturn([$file]);
->willReturn([42 => $file]);
$userFolder->method('getPath') $userFolder->method('getPath')
->willReturn('/owner/files');
->willReturn('/user1/files');


$this->userManager->method('userExists') $this->userManager->method('userExists')
->with($this->equalTo('owner'))
->with($this->equalTo('user1'))
->willReturn(true); ->willReturn(true);


$this->defaultProvider->method('getAccessList') $this->defaultProvider->method('getAccessList')
]); ]);


$this->rootFolder->method('getUserFolder') $this->rootFolder->method('getUserFolder')
->with($this->equalTo('owner'))
->with($this->equalTo('user1'))
->willReturn($userFolder); ->willReturn($userFolder);


$expected = [ $expected = [

Loading…
Cancel
Save