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:
parent
2cbac3357b
commit
12afd7d1d5
|
@ -997,6 +997,6 @@ class FederatedShareProvider implements IShareProvider {
|
|||
$remote = $cursor->fetch() !== false;
|
||||
$cursor->closeCursor();
|
||||
|
||||
return ['users' => [], 'remote' => $remote, 'public' => false];
|
||||
return ['remote' => $remote];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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']);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue