Add mail element to access list

* Each provider just returns what they have so adding an element won't
require changing everything
* Added tests

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2017-01-04 08:59:43 +01:00
parent 2cbac3357b
commit 12afd7d1d5
No known key found for this signature in database
GPG Key ID: F941078878347C0C
7 changed files with 62 additions and 10 deletions

View File

@ -997,6 +997,6 @@ class FederatedShareProvider implements IShareProvider {
$remote = $cursor->fetch() !== false;
$cursor->closeCursor();
return ['users' => [], 'remote' => $remote, 'public' => false];
return ['remote' => $remote];
}
}

View File

@ -788,4 +788,32 @@ class FederatedShareProviderTest extends \Test\TestCase {
$u1->delete();
$u2->delete();
}
public function testGetAccessList() {
$userManager = \OC::$server->getUserManager();
$rootFolder = \OC::$server->getRootFolder();
$u1 = $userManager->createUser('testFed', md5(time()));
$folder1 = $rootFolder->getUserFolder($u1->getUID())->newFolder('foo');
$file1 = $folder1->newFile('bar1');
$this->tokenHandler->method('generateToken')->willReturn('token');
$this->notifications
->method('sendRemoteShare')
->willReturn(true);
$share1 = $this->shareManager->newShare();
$share1->setSharedWith('user@server.com')
->setSharedBy($u1->getUID())
->setShareOwner($u1->getUID())
->setPermissions(\OCP\Constants::PERMISSION_READ)
->setNode($file1);
$this->provider->create($share1);
$result = $this->provider->getAccessList([$file1], true);
$this->assertSame(['remote' => true], $result);
$u1->delete();
}
}

View File

@ -835,7 +835,27 @@ class ShareByMailProvider implements IShareProvider {
}
public function getAccessList($nodes, $currentAccess) {
return ['users' => [], 'remote' => false, 'public' => false];
$ids = [];
foreach ($nodes as $node) {
$ids[] = $node->getId();
}
$qb = $this->dbConnection->getQueryBuilder();
$qb->select('share_with')
->from('share')
->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL)))
->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)))
->andWhere($qb->expr()->orX(
$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
))
->setMaxResults(1);
$cursor = $qb->execute();
$mail = $cursor->fetch() !== false;
$cursor->closeCursor();
return ['mail' => $mail];
}
}

View File

@ -1138,6 +1138,6 @@ class DefaultShareProvider implements IShareProvider {
return $count > 0;
});
return ['users' => array_keys($users), 'public' => $link, 'remote' => false];
return ['users' => array_keys($users), 'public' => $link];
}
}

View File

@ -1236,9 +1236,17 @@ class Manager implements IManager {
foreach ($providers as $provider) {
$tmp = $provider->getAccessList($nodes, $currentAccess);
$al['users'] = array_merge($al['users'], $tmp['users']);
$al['public'] = $al['public'] || $tmp['public'];
$al['remote'] = $al['remote'] || $tmp['remote'];
foreach ($tmp as $k => $v) {
if (isset($al[$k])) {
if (is_array($al[$k])) {
$al[$k] = array_merge($al[$k], $v);
} else {
$al[$k] = $al[$k] || $v;
}
} else {
$al[$k] = $v;
}
}
}
$al['users'] = array_unique($al['users']);

View File

@ -2508,7 +2508,6 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertContains('testShare4', $result['users']);
$this->assertContains('testShare5', $result['users']);
$this->assertTrue($result['public']);
$this->assertFalse($result['remote']);
$provider->delete($share1);
$provider->delete($share2);
@ -2595,7 +2594,6 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertContains('testShare3', $result['users']);
$this->assertContains('testShare5', $result['users']);
$this->assertTrue($result['public']);
$this->assertFalse($result['remote']);
$provider->delete($share1);
$provider->delete($share2);

View File

@ -2804,7 +2804,6 @@ class ManagerTest extends \Test\TestCase {
'user2',
'user3',
],
'remote' => false,
'public' => true,
]);
@ -2820,7 +2819,6 @@ class ManagerTest extends \Test\TestCase {
'user5',
],
'remote' => true,
'public' => false,
]);
$this->rootFolder->method('getUserFolder')