summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/private/Share20/LegacyHooks.php15
-rw-r--r--lib/private/Share20/Manager.php2
-rw-r--r--tests/lib/Share20/LegacyHooksTest.php52
-rw-r--r--tests/lib/Share20/ManagerTest.php34
4 files changed, 103 insertions, 0 deletions
diff --git a/lib/private/Share20/LegacyHooks.php b/lib/private/Share20/LegacyHooks.php
index 09acf6c50e7..e7fbe7336b8 100644
--- a/lib/private/Share20/LegacyHooks.php
+++ b/lib/private/Share20/LegacyHooks.php
@@ -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();
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index 798ea937038..b90cc12fc85 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -873,6 +873,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);
}
/**
diff --git a/tests/lib/Share20/LegacyHooksTest.php b/tests/lib/Share20/LegacyHooksTest.php
index 75a77306116..22d575d26ff 100644
--- a/tests/lib/Share20/LegacyHooksTest.php
+++ b/tests/lib/Share20/LegacyHooksTest.php
@@ -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);
+ }
}
diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php
index 1cc165106d7..a764350c406 100644
--- a/tests/lib/Share20/ManagerTest.php
+++ b/tests/lib/Share20/ManagerTest.php
@@ -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'])