[Share 2.0] When deleting a group share delete children

For group shares we can have children. Those are custom shares when a
user has moved or deleted a group share. Those also have to be deleted
if the group share is removed.
This commit is contained in:
Roeland Jago Douma 2016-01-28 20:35:46 +01:00
parent 8b3d7d09d5
commit 1ff4ec1cd3
2 changed files with 67 additions and 65 deletions

View File

@ -288,21 +288,21 @@ class DefaultShareProvider implements IShareProvider {
* Delete a share * Delete a share
* *
* @param \OCP\Share\IShare $share * @param \OCP\Share\IShare $share
* @throws BackendError
*/ */
public function delete(\OCP\Share\IShare $share) { public function delete(\OCP\Share\IShare $share) {
// Fetch share to make sure it exists
$share = $this->getShareById($share->getId());
$qb = $this->dbConn->getQueryBuilder(); $qb = $this->dbConn->getQueryBuilder();
$qb->delete('share') $qb->delete('share')
->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))); ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())));
try { /*
$qb->execute(); * If the share is a group share delete all possible
} catch (\Exception $e) { * user defined groups shares.
throw new BackendError(); */
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
$qb->orWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())));
} }
$qb->execute();
} }
/** /**

View File

@ -330,19 +330,14 @@ class DefaultShareProviderTest extends \Test\TestCase {
$share->method('getId')->willReturn($id); $share->method('getId')->willReturn($id);
$provider = $this->getMockBuilder('OC\Share20\DefaultShareProvider') $provider = $this->getMockBuilder('OC\Share20\DefaultShareProvider')
->setConstructorArgs([ ->setConstructorArgs([
$this->dbConn, $this->dbConn,
$this->userManager, $this->userManager,
$this->groupManager, $this->groupManager,
$this->rootFolder, $this->rootFolder,
] ])
) ->setMethods(['getShareById'])
->setMethods(['getShareById']) ->getMock();
->getMock();
$provider
->expects($this->once())
->method('getShareById')
->willReturn($share);
$provider->delete($share); $provider->delete($share);
@ -357,53 +352,60 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEmpty($result); $this->assertEmpty($result);
} }
/** public function testDeleteGroupShareWithUserGroupShares() {
* @expectedException \OC\Share20\Exception\BackendError $qb = $this->dbConn->getQueryBuilder();
*/ $qb->insert('share')
public function testDeleteFails() { ->values([
'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_GROUP),
'share_with' => $qb->expr()->literal('sharedWith'),
'uid_owner' => $qb->expr()->literal('sharedBy'),
'item_type' => $qb->expr()->literal('file'),
'file_source' => $qb->expr()->literal(42),
'file_target' => $qb->expr()->literal('myTarget'),
'permissions' => $qb->expr()->literal(13),
]);
$this->assertEquals(1, $qb->execute());
$id = $qb->getLastInsertId();
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')
->values([
'share_type' => $qb->expr()->literal(2),
'share_with' => $qb->expr()->literal('sharedWithUser'),
'uid_owner' => $qb->expr()->literal('sharedBy'),
'item_type' => $qb->expr()->literal('file'),
'file_source' => $qb->expr()->literal(42),
'file_target' => $qb->expr()->literal('myTarget'),
'permissions' => $qb->expr()->literal(13),
'parent' => $qb->expr()->literal($id),
]);
$this->assertEquals(1, $qb->execute());
$share = $this->getMock('OCP\Share\IShare'); $share = $this->getMock('OCP\Share\IShare');
$share $share->method('getId')->willReturn($id);
->method('getId') $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_GROUP);
->willReturn(42);
$expr = $this->getMock('OCP\DB\QueryBuilder\IExpressionBuilder');
$qb = $this->getMock('OCP\DB\QueryBuilder\IQueryBuilder');
$qb->expects($this->once())
->method('delete')
->will($this->returnSelf());
$qb->expects($this->once())
->method('expr')
->willReturn($expr);
$qb->expects($this->once())
->method('where')
->will($this->returnSelf());
$qb->expects($this->once())
->method('execute')
->will($this->throwException(new \Exception));
$db = $this->getMock('OCP\IDBConnection');
$db->expects($this->once())
->method('getQueryBuilder')
->with()
->willReturn($qb);
$provider = $this->getMockBuilder('OC\Share20\DefaultShareProvider') $provider = $this->getMockBuilder('OC\Share20\DefaultShareProvider')
->setConstructorArgs([ ->setConstructorArgs([
$db, $this->dbConn,
$this->userManager, $this->userManager,
$this->groupManager, $this->groupManager,
$this->rootFolder, $this->rootFolder,
] ])
) ->setMethods(['getShareById'])
->setMethods(['getShareById']) ->getMock();
->getMock();
$provider
->expects($this->once())
->method('getShareById')
->with(42)
->willReturn($share);
$provider->delete($share); $provider->delete($share);
$qb = $this->dbConn->getQueryBuilder();
$qb->select('*')
->from('share');
$cursor = $qb->execute();
$result = $cursor->fetchAll();
$cursor->closeCursor();
$this->assertEmpty($result);
} }
public function testGetChildren() { public function testGetChildren() {