diff options
author | Morris Jobke <hey@morrisjobke.de> | 2017-04-15 13:06:24 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-15 13:06:24 -0500 |
commit | 10290eb0060eb2194be2dd4fc8b707aa7eef5c0a (patch) | |
tree | b71665687f9c19f5b6f8e9f34ffbd5a8a2d4f5e8 /apps/sharebymail | |
parent | dafa9c740abee38bb54e9df05947bcf09857380a (diff) | |
parent | cab41118f67e6a4743bac2cfcfa69a4bee28f2a3 (diff) | |
download | nextcloud-server-10290eb0060eb2194be2dd4fc8b707aa7eef5c0a.tar.gz nextcloud-server-10290eb0060eb2194be2dd4fc8b707aa7eef5c0a.zip |
Merge pull request #2834 from nextcloud/accesListToShareManager
Access list to share manager
Diffstat (limited to 'apps/sharebymail')
-rw-r--r-- | apps/sharebymail/lib/ShareByMailProvider.php | 27 | ||||
-rw-r--r-- | apps/sharebymail/tests/ShareByMailProviderTest.php | 62 |
2 files changed, 89 insertions, 0 deletions
diff --git a/apps/sharebymail/lib/ShareByMailProvider.php b/apps/sharebymail/lib/ShareByMailProvider.php index 0b959ce4265..83170c5648c 100644 --- a/apps/sharebymail/lib/ShareByMailProvider.php +++ b/apps/sharebymail/lib/ShareByMailProvider.php @@ -834,4 +834,31 @@ class ShareByMailProvider implements IShareProvider { return $shares; } + /** + * @inheritdoc + */ + public function getAccessList($nodes, $currentAccess) { + $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 ['public' => $mail]; + } + } diff --git a/apps/sharebymail/tests/ShareByMailProviderTest.php b/apps/sharebymail/tests/ShareByMailProviderTest.php index 288ebb4bb45..13fb5d03bd8 100644 --- a/apps/sharebymail/tests/ShareByMailProviderTest.php +++ b/apps/sharebymail/tests/ShareByMailProviderTest.php @@ -664,4 +664,66 @@ class ShareByMailProviderTest extends TestCase { $u2->delete(); } + public function testGetAccessList() { + $userManager = \OC::$server->getUserManager(); + $rootFolder = \OC::$server->getRootFolder(); + + $provider = $this->getInstance(['sendMailNotification', 'createActivity']); + + $u1 = $userManager->createUser('testFed', md5(time())); + $u2 = $userManager->createUser('testFed2', md5(time())); + + $folder = $rootFolder->getUserFolder($u1->getUID())->newFolder('foo'); + + $accessList = $provider->getAccessList([$folder], true); + $this->assertArrayHasKey('public', $accessList); + $this->assertFalse($accessList['public']); + $accessList = $provider->getAccessList([$folder], false); + $this->assertArrayHasKey('public', $accessList); + $this->assertFalse($accessList['public']); + + $share1 = $this->shareManager->newShare(); + $share1->setSharedWith('user@server.com') + ->setSharedBy($u1->getUID()) + ->setShareOwner($u1->getUID()) + ->setPermissions(\OCP\Constants::PERMISSION_READ) + ->setNode($folder); + $share1 = $provider->create($share1); + + $share2 = $this->shareManager->newShare(); + $share2->setSharedWith('user2@server.com') + ->setSharedBy($u2->getUID()) + ->setShareOwner($u1->getUID()) + ->setPermissions(\OCP\Constants::PERMISSION_READ) + ->setNode($folder); + $share2 = $provider->create($share2); + + $accessList = $provider->getAccessList([$folder], true); + $this->assertArrayHasKey('public', $accessList); + $this->assertTrue($accessList['public']); + $accessList = $provider->getAccessList([$folder], false); + $this->assertArrayHasKey('public', $accessList); + $this->assertTrue($accessList['public']); + + $provider->delete($share2); + + $accessList = $provider->getAccessList([$folder], true); + $this->assertArrayHasKey('public', $accessList); + $this->assertTrue($accessList['public']); + $accessList = $provider->getAccessList([$folder], false); + $this->assertArrayHasKey('public', $accessList); + $this->assertTrue($accessList['public']); + + $provider->delete($share1); + + $accessList = $provider->getAccessList([$folder], true); + $this->assertArrayHasKey('public', $accessList); + $this->assertFalse($accessList['public']); + $accessList = $provider->getAccessList([$folder], false); + $this->assertArrayHasKey('public', $accessList); + $this->assertFalse($accessList['public']); + + $u1->delete(); + $u2->delete(); + } } |