add new method getSharesInFolder(), see #339
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
This commit is contained in:
parent
16ec0f2177
commit
32dbf32bc5
|
@ -22,6 +22,7 @@
|
||||||
namespace OCA\ShareByMail;
|
namespace OCA\ShareByMail;
|
||||||
|
|
||||||
use OC\HintException;
|
use OC\HintException;
|
||||||
|
use OCP\Files\Folder;
|
||||||
use OCP\Files\IRootFolder;
|
use OCP\Files\IRootFolder;
|
||||||
use OCP\Files\Node;
|
use OCP\Files\Node;
|
||||||
use OCP\IDBConnection;
|
use OCP\IDBConnection;
|
||||||
|
@ -663,4 +664,45 @@ class ShareByMailProvider implements IShareProvider {
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getSharesInFolder($userId, Folder $node, $reshares) {
|
||||||
|
$qb = $this->dbConnection->getQueryBuilder();
|
||||||
|
$qb->select('*')
|
||||||
|
->from('share', 's')
|
||||||
|
->andWhere($qb->expr()->orX(
|
||||||
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
|
||||||
|
$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
|
||||||
|
))
|
||||||
|
->andWhere(
|
||||||
|
$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_EMAIL))
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reshares for this user are shares where they are the owner.
|
||||||
|
*/
|
||||||
|
if ($reshares === false) {
|
||||||
|
$qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)));
|
||||||
|
} else {
|
||||||
|
$qb->andWhere(
|
||||||
|
$qb->expr()->orX(
|
||||||
|
$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
|
||||||
|
$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$qb->innerJoin('s', 'filecache' ,'f', 's.file_source = f.fileid');
|
||||||
|
$qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
|
||||||
|
|
||||||
|
$qb->orderBy('id');
|
||||||
|
|
||||||
|
$cursor = $qb->execute();
|
||||||
|
$shares = [];
|
||||||
|
while ($data = $cursor->fetch()) {
|
||||||
|
$shares[$data['fileid']][] = $this->createShareObject($data);
|
||||||
|
}
|
||||||
|
$cursor->closeCursor();
|
||||||
|
|
||||||
|
return $shares;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -610,5 +610,46 @@ class ShareByMailProviderTest extends TestCase {
|
||||||
return (int)$id;
|
return (int)$id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetSharesInFolder() {
|
||||||
|
$userManager = \OC::$server->getUserManager();
|
||||||
|
$rootFolder = \OC::$server->getRootFolder();
|
||||||
|
|
||||||
|
$provider = $this->getInstance(['sendMailNotification']);
|
||||||
|
|
||||||
|
$u1 = $userManager->createUser('testFed', md5(time()));
|
||||||
|
$u2 = $userManager->createUser('testFed2', md5(time()));
|
||||||
|
|
||||||
|
$folder1 = $rootFolder->getUserFolder($u1->getUID())->newFolder('foo');
|
||||||
|
$file1 = $folder1->newFile('bar1');
|
||||||
|
$file2 = $folder1->newFile('bar2');
|
||||||
|
|
||||||
|
$share1 = $this->shareManager->newShare();
|
||||||
|
$share1->setSharedWith('user@server.com')
|
||||||
|
->setSharedBy($u1->getUID())
|
||||||
|
->setShareOwner($u1->getUID())
|
||||||
|
->setPermissions(\OCP\Constants::PERMISSION_READ)
|
||||||
|
->setNode($file1);
|
||||||
|
$provider->create($share1);
|
||||||
|
|
||||||
|
$share2 = $this->shareManager->newShare();
|
||||||
|
$share2->setSharedWith('user@server.com')
|
||||||
|
->setSharedBy($u2->getUID())
|
||||||
|
->setShareOwner($u1->getUID())
|
||||||
|
->setPermissions(\OCP\Constants::PERMISSION_READ)
|
||||||
|
->setNode($file2);
|
||||||
|
$provider->create($share2);
|
||||||
|
|
||||||
|
$result = $provider->getSharesInFolder($u1->getUID(), $folder1, false);
|
||||||
|
$this->assertCount(1, $result);
|
||||||
|
$this->assertCount(1, $result[$file1->getId()]);
|
||||||
|
|
||||||
|
$result = $provider->getSharesInFolder($u1->getUID(), $folder1, true);
|
||||||
|
$this->assertCount(2, $result);
|
||||||
|
$this->assertCount(1, $result[$file1->getId()]);
|
||||||
|
$this->assertCount(1, $result[$file2->getId()]);
|
||||||
|
|
||||||
|
$u1->delete();
|
||||||
|
$u2->delete();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue