Merge pull request #22118 from owncloud/post_update_permissions_hook

[Share 2.0] Add missing post_update_permissions hook
This commit is contained in:
Thomas Müller 2016-02-05 10:04:41 +01:00
commit c8e136b7dc
3 changed files with 53 additions and 7 deletions

View File

@ -77,6 +77,7 @@ class Manager implements IManager {
* @param IL10N $l
* @param IProviderFactory $factory
* @param IUserManager $userManager
* @param IRootFolder $rootFolder
*/
public function __construct(
ILogger $logger,
@ -613,6 +614,19 @@ class Manager implements IManager {
]);
}
if ($share->getPermissions() !== $originalShare->getPermissions()) {
$userFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
\OC_Hook::emit('OCP\Share', 'post_update_permissions', array(
'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
'itemSource' => $share->getNode()->getId(),
'shareType' => $share->getShareType(),
'shareWith' => $share->getSharedWith(),
'uidOwner' => $share->getSharedBy(),
'permissions' => $share->getPermissions(),
'path' => $userFolder->getRelativePath($share->getNode()->getPath()),
));
}
return $share;
}

View File

@ -105,6 +105,8 @@ class Share implements \OCP\Share\IShare {
* @inheritdoc
*/
public function setNode(Node $node) {
$this->fileId = null;
$this->nodeType = null;
$this->node = $node;
return $this;
}

View File

@ -1870,19 +1870,24 @@ class ManagerTest extends \Test\TestCase {
$originalShare = $this->manager->newShare();
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_USER)
->setSharedWith('origUser');
->setSharedWith('origUser')
->setPermissions(1);
$node = $this->getMock('\OCP\Files\File');
$node->method('getId')->willReturn(100);
$node->method('getPath')->willReturn('/newUser/files/myPath');
$manager->expects($this->once())->method('canShare')->willReturn(true);
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
$node = $this->getMock('\OCP\Files\File');
$share = $this->manager->newShare();
$share->setProviderId('foo')
->setId('42')
->setShareType(\OCP\Share::SHARE_TYPE_USER)
->setSharedWith('origUser')
->setShareOwner('newUser')
->setSharedBy('sharer')
->setPermissions(31)
->setNode($node);
$this->defaultProvider->expects($this->once())
@ -1894,6 +1899,20 @@ class ManagerTest extends \Test\TestCase {
\OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post');
$hookListner->expects($this->never())->method('post');
$this->rootFolder->method('getUserFolder')->with('newUser')->will($this->returnSelf());
$this->rootFolder->method('getRelativePath')->with('/newUser/files/myPath')->willReturn('/myPath');
$hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
\OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner2, 'post');
$hookListner2->expects($this->once())->method('post')->with([
'itemType' => 'file',
'itemSource' => 100,
'shareType' => \OCP\Share::SHARE_TYPE_USER,
'shareWith' => 'origUser',
'uidOwner' => 'sharer',
'permissions' => 31,
'path' => '/myPath',
]);
$manager->updateShare($share);
}
@ -1911,7 +1930,8 @@ class ManagerTest extends \Test\TestCase {
$originalShare = $this->manager->newShare();
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
->setSharedWith('origUser');
->setSharedWith('origUser')
->setPermissions(31);
$manager->expects($this->once())->method('canShare')->willReturn(true);
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
@ -1924,7 +1944,8 @@ class ManagerTest extends \Test\TestCase {
->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
->setSharedWith('origUser')
->setShareOwner('owner')
->setNode($node);
->setNode($node)
->setPermissions(31);
$this->defaultProvider->expects($this->once())
->method('update')
@ -1935,6 +1956,9 @@ class ManagerTest extends \Test\TestCase {
\OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post');
$hookListner->expects($this->never())->method('post');
$hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
\OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner2, 'post');
$hookListner2->expects($this->never())->method('post');
$manager->updateShare($share);
}
@ -1953,7 +1977,8 @@ class ManagerTest extends \Test\TestCase {
->getMock();
$originalShare = $this->manager->newShare();
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_LINK);
$originalShare->setShareType(\OCP\Share::SHARE_TYPE_LINK)
->setPermissions(15);
$tomorrow = new \DateTime();
$tomorrow->setTime(0,0,0);
@ -1970,7 +1995,8 @@ class ManagerTest extends \Test\TestCase {
->setShareOwner('owner')
->setPassword('password')
->setExpirationDate($tomorrow)
->setNode($file);
->setNode($file)
->setPermissions(15);
$manager->expects($this->once())->method('canShare')->willReturn(true);
$manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare);
@ -1990,6 +2016,10 @@ class ManagerTest extends \Test\TestCase {
'uidOwner' => 'owner',
]);
$hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
\OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner2, 'post');
$hookListner2->expects($this->never())->method('post');
$manager->updateShare($share);
}