Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d84df15
Add getAccessList to ShareManager
rullzer Sep 9, 2016
7dcc98e
Add owner to access list
rullzer Sep 9, 2016
88299ec
Added to public interface
rullzer Oct 19, 2016
a1edcc8
Port Encryption/file to new getAccessList
rullzer Oct 19, 2016
553b3b2
Fix tests
rullzer Oct 27, 2016
97f8ca6
Added ShareHelper
rullzer Oct 27, 2016
2cbac33
Offload acceslist creation to providers
rullzer Dec 22, 2016
12afd7d
Add mail element to access list
rullzer Jan 4, 2017
4437e00
Add shareHelper test
rullzer Jan 4, 2017
0c2dc3b
Fix comments
rullzer Mar 20, 2017
91e6507
Return the paths for the users without setting them all up
nickvergessen Mar 27, 2017
cf7c320
Also return the token
nickvergessen Mar 27, 2017
4bcb7d8
Return the token as well
nickvergessen Mar 28, 2017
3c1365c
Fix returned paths for remote shares
nickvergessen Mar 28, 2017
5df727d
Fix federated file sharing
nickvergessen Apr 10, 2017
2fcf334
Fix tests for ShareHelper
nickvergessen Apr 10, 2017
5b57bb9
Fix default share provider
nickvergessen Apr 10, 2017
4eeb194
Fix share manager test
nickvergessen Apr 10, 2017
6c23a5f
Add unit tests for sharebymail provider
nickvergessen Apr 11, 2017
629b7c0
Adjust docs and make !$currentAccess simpler
nickvergessen Apr 11, 2017
7d416ac
Activate the test
nickvergessen Apr 11, 2017
29f2088
Catch exceptions and use as many results as possible
nickvergessen Apr 11, 2017
e1d54e3
Add more tests for the share helper
nickvergessen Apr 11, 2017
f57ef55
Add samples to the docs
nickvergessen Apr 11, 2017
b96297e
Do not set full path if not currentAccess
rullzer Apr 13, 2017
aef95b9
Not needed in the DIContainer anymore
rullzer Apr 13, 2017
0f56823
Fix server container registration
rullzer Apr 13, 2017
6a519ab
Update autoloader
rullzer Apr 13, 2017
cab4111
Mail shares trigger the public key
rullzer Apr 13, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add getAccessList to ShareManager
Signed-off-by: Roeland Jago Douma <[email protected]>
  • Loading branch information
rullzer committed Apr 13, 2017
commit d84df155900bfdb58a8826802cde5a096065a078
67 changes: 62 additions & 5 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
use OCP\Share\IProviderFactory;
use OCP\Share\IShare;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\GenericEvent;
use OCP\Share\IShareProvider;
Expand Down Expand Up @@ -1176,7 +1177,7 @@ public function userDeletedFromGroup($uid, $gid) {

/**
* Get access list to a path. This means
* all the users and groups that can access a given path.
* all the users that can access a given path.
*
* Consider:
* -root
Expand All @@ -1185,20 +1186,76 @@ public function userDeletedFromGroup($uid, $gid) {
* |-fileA
*
* fileA is shared with user1
* folder2 is shared with group2
* folder2 is shared with group2 (user4 is a member of group2)
* folder1 is shared with user2
*
* Then the access list will to '/folder1/folder2/fileA' is:
* [
* 'users' => ['user1', 'user2'],
* 'groups' => ['group2']
* users => ['user1', 'user2', 'user4'],
* public => bool
* remote => bool
* ]
*
* This is required for encryption
* This is required for encryption/activities
*
* @param \OCP\Files\Node $path
* @return array
*/
public function getAccessList(\OCP\Files\Node $path) {
$owner = $path->getOwner()->getUID();

//Get node for the owner
$userFolder = $this->rootFolder->getUserFolder($owner);
$path = $userFolder->getById($path->getId())[0];

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

/** @var IShare[] $shares */
$shares = [];

// Collect all the shares
while ($path !== $userFolder) {
foreach ($providers as $provider) {
$shares = array_merge($shares, $provider->getSharesByPath($path));
}
$path = $path->getParent();
}

$users = [];
$public = false;
$remote = false;
foreach ($shares as $share) {
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
$uid = $share->getSharedWith();

// Skip if user does not exist
if (!$this->userManager->userExists($uid)) {
continue;
}

$users[$uid] = null;
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
$group = $this->groupManager->get($share->getSharedWith());

// If group does not exist skip
if ($group === null) {
continue;
}

$groupUsers = $group->getUsers();
foreach ($groupUsers as $groupUser) {
$users[$groupUser->getUID()] = null;
}
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
$public = true;
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) {
$remote = true;
}
}

$users = array_keys($users);

return ['users' => $users, 'public' => $public, 'remote' => $remote];
}

/**
Expand Down
83 changes: 82 additions & 1 deletion tests/lib/Share20/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2639,7 +2639,6 @@ public function testMoveShareGroup() {
$this->manager->moveShare($share, 'recipient');
}


/**
* @dataProvider dataTestShareProviderExists
*/
Expand Down Expand Up @@ -2737,6 +2736,88 @@ public function testGetSharesInFolder() {

$this->assertSame($expects, $result);
}

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

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

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

$file->method('getParent')
->willReturn($folder);
$folder->method('getParent')
->willReturn($userFolder);
$userFolder->method('getById')
->with($this->equalTo(42))
->willReturn([$file]);

$userShare = $this->createMock(IShare::class);
$userShare->method('getShareType')
->willReturn(\OCP\Share::SHARE_TYPE_USER);
$userShare->method('getSharedWith')
->willReturn('user1');
$groupShare = $this->createMock(IShare::class);
$groupShare->method('getShareType')
->willReturn(\OCP\Share::SHARE_TYPE_GROUP);
$groupShare->method('getSharedWith')
->willReturn('group1');
$publicShare = $this->createMock(IShare::class);
$publicShare->method('getShareType')
->willReturn(\OCP\Share::SHARE_TYPE_LINK);
$remoteShare = $this->createMock(IShare::class);
$remoteShare->method('getShareType')
->willReturn(\OCP\Share::SHARE_TYPE_REMOTE);

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

$user2 = $this->createMock(IUser::class);
$user2->method('getUID')
->willReturn('user2');
$group1 = $this->createMock(IGroup::class);
$this->groupManager->method('get')
->with($this->equalTo('group1'))
->willReturn($group1);
$group1->method('getUsers')
->willReturn([$user2]);

$this->defaultProvider->expects($this->any())
->method('getSharesByPath')
->will($this->returnCallback(function(Node $path) use ($file, $folder, $userShare, $groupShare, $publicShare, $remoteShare) {
if ($path === $file) {
return [$userShare, $publicShare];
} else if ($path === $folder) {
return [$groupShare, $remoteShare];
} else {
return [];
}
}));

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

$expected = [
'users' => ['user1', 'user2'],
'public' => true,
'remote' => true,
];

$this->assertEquals($expected, $this->manager->getAccessList($node));
}
}

class DummyFactory implements IProviderFactory {
Expand Down