Merge pull request #5797 from paulijar/share20-postUnshareFromSelf
Dispatch event postUnshareFromSelf when the recipient of a share unshares it
This commit is contained in:
commit
b1954bed97
4 changed files with 103 additions and 0 deletions
|
@ -40,6 +40,7 @@ class LegacyHooks {
|
|||
|
||||
$this->eventDispatcher->addListener('OCP\Share::preUnshare', [$this, 'preUnshare']);
|
||||
$this->eventDispatcher->addListener('OCP\Share::postUnshare', [$this, 'postUnshare']);
|
||||
$this->eventDispatcher->addListener('OCP\Share::postUnshareFromSelf', [$this, 'postUnshareFromSelf']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,6 +75,20 @@ class LegacyHooks {
|
|||
\OC_Hook::emit('OCP\Share', 'post_unshare', $formatted);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GenericEvent $e
|
||||
*/
|
||||
public function postUnshareFromSelf(GenericEvent $e) {
|
||||
/** @var IShare $share */
|
||||
$share = $e->getSubject();
|
||||
|
||||
$formatted = $this->formatHookParams($share);
|
||||
$formatted['itemTarget'] = $formatted['fileTarget'];
|
||||
$formatted['unsharedItems'] = [$formatted];
|
||||
|
||||
\OC_Hook::emit('OCP\Share', 'post_unshareFromSelf', $formatted);
|
||||
}
|
||||
|
||||
private function formatHookParams(IShare $share) {
|
||||
// Prepare hook
|
||||
$shareType = $share->getShareType();
|
||||
|
|
|
@ -871,6 +871,8 @@ class Manager implements IManager {
|
|||
$provider = $this->factory->getProvider($providerId);
|
||||
|
||||
$provider->deleteFromSelf($share, $recipientId);
|
||||
$event = new GenericEvent($share);
|
||||
$this->eventDispatcher->dispatch('OCP\Share::postUnshareFromSelf', $event);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -135,4 +135,56 @@ class LegacyHooksTest extends TestCase {
|
|||
$event->setArgument('deletedShares', [$share]);
|
||||
$this->eventDispatcher->dispatch('OCP\Share::postUnshare', $event);
|
||||
}
|
||||
|
||||
public function testPostUnshareFromSelf() {
|
||||
$path = $this->createMock(File::class);
|
||||
$path->method('getId')->willReturn(1);
|
||||
|
||||
$share = $this->manager->newShare();
|
||||
$share->setId(42)
|
||||
->setProviderId('prov')
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedWith('awesomeUser')
|
||||
->setSharedBy('sharedBy')
|
||||
->setNode($path)
|
||||
->setTarget('myTarget');
|
||||
|
||||
$hookListner = $this->getMockBuilder('Dummy')->setMethods(['postFromSelf'])->getMock();
|
||||
\OCP\Util::connectHook('OCP\Share', 'post_unshareFromSelf', $hookListner, 'postFromSelf');
|
||||
|
||||
$hookListnerExpectsPostFromSelf = [
|
||||
'id' => 42,
|
||||
'itemType' => 'file',
|
||||
'itemSource' => 1,
|
||||
'shareType' => \OCP\Share::SHARE_TYPE_USER,
|
||||
'shareWith' => 'awesomeUser',
|
||||
'itemparent' => null,
|
||||
'uidOwner' => 'sharedBy',
|
||||
'fileSource' => 1,
|
||||
'fileTarget' => 'myTarget',
|
||||
'itemTarget' => 'myTarget',
|
||||
'unsharedItems' => [
|
||||
[
|
||||
'id' => 42,
|
||||
'itemType' => 'file',
|
||||
'itemSource' => 1,
|
||||
'shareType' => \OCP\Share::SHARE_TYPE_USER,
|
||||
'shareWith' => 'awesomeUser',
|
||||
'itemparent' => null,
|
||||
'uidOwner' => 'sharedBy',
|
||||
'fileSource' => 1,
|
||||
'fileTarget' => 'myTarget',
|
||||
'itemTarget' => 'myTarget',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$hookListner
|
||||
->expects($this->exactly(1))
|
||||
->method('postFromSelf')
|
||||
->with($hookListnerExpectsPostFromSelf);
|
||||
|
||||
$event = new GenericEvent($share);
|
||||
$this->eventDispatcher->dispatch('OCP\Share::postUnshareFromSelf', $event);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -332,6 +332,40 @@ class ManagerTest extends \Test\TestCase {
|
|||
$manager->deleteShare($share1);
|
||||
}
|
||||
|
||||
public function testDeleteFromSelf() {
|
||||
$manager = $this->createManagerMock()
|
||||
->setMethods(['getShareById'])
|
||||
->getMock();
|
||||
|
||||
$recipientId = 'unshareFrom';
|
||||
$share = $this->manager->newShare();
|
||||
$share->setId(42)
|
||||
->setProviderId('prov')
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedWith('sharedWith')
|
||||
->setSharedBy('sharedBy')
|
||||
->setShareOwner('shareOwner')
|
||||
->setTarget('myTarget')
|
||||
->setNodeId(1)
|
||||
->setNodeType('file');
|
||||
|
||||
$this->defaultProvider
|
||||
->expects($this->once())
|
||||
->method('deleteFromSelf')
|
||||
->with($share, $recipientId);
|
||||
|
||||
$this->eventDispatcher->expects($this->at(0))
|
||||
->method('dispatch')
|
||||
->with(
|
||||
'OCP\Share::postUnshareFromSelf',
|
||||
$this->callBack(function(GenericEvent $e) use ($share) {
|
||||
return $e->getSubject() === $share;
|
||||
})
|
||||
);
|
||||
|
||||
$manager->deleteFromSelf($share, $recipientId);
|
||||
}
|
||||
|
||||
public function testDeleteChildren() {
|
||||
$manager = $this->createManagerMock()
|
||||
->setMethods(['deleteShare'])
|
||||
|
|
Loading…
Reference in a new issue