diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index c5274f278..60766c567 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -110,6 +110,6 @@ public function registerFilesActivity() { $eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher(); $eventDispatcher->addListener('OCP\Share::preUnshare', [FilesHooksStatic::class, 'unShare']); - $eventDispatcher->addListener('OCP\Share::postUnshareFromSelf', [FilesHooksStatic::class, 'unShare']); + $eventDispatcher->addListener('OCP\Share::postUnshareFromSelf', [FilesHooksStatic::class, 'unShareSelf']); } } diff --git a/lib/FilesHooks.php b/lib/FilesHooks.php index 44d4ea5ed..e3237a3c5 100755 --- a/lib/FilesHooks.php +++ b/lib/FilesHooks.php @@ -781,6 +781,21 @@ public function unShare(IShare $share) { } } + /** + * Manage unsharing a share from self only events + * @param IShare $share + * @throws \OCP\Files\NotFoundException + */ + public function unShareSelf(IShare $share) { + if (in_array($share->getNodeType(), ['file', 'folder'], true)) { + if ($share->getShareType() === Share::SHARE_TYPE_GROUP) { + $this->unshareFromSelfGroup($share); + } else { + $this->unShare($share); + } + } + } + /** * Unharing a file or folder from a user * @@ -854,6 +869,22 @@ protected function unshareFromGroup(IShare $share) { } } + /** + * Unsharing a file or folder from self from a group share + * + * @param IShare $share + * @throws \OCP\Files\NotFoundException + */ + protected function unshareFromSelfGroup(IShare $share) { + // User performing the unshare + $this->shareNotificationForSharer('self_unshared', $this->currentUser->getUID(), $share->getNodeId(), $share->getNodeType()); + + // Owner + if ($this->currentUser->getUID() !== null) { + $this->shareNotificationForOriginalOwners($this->currentUser->getUID(), 'self_unshared_by', $this->currentUser->getUID(), $share->getNodeId(), $share->getNodeType()); + } + } + /** * Sharing a file or folder via link/public * diff --git a/lib/FilesHooksStatic.php b/lib/FilesHooksStatic.php index 9ff307391..6398edfc9 100755 --- a/lib/FilesHooksStatic.php +++ b/lib/FilesHooksStatic.php @@ -105,4 +105,15 @@ public static function unShare(GenericEvent $event) { self::getHooks()->unShare($share); } } + + /** + * "Unsharing a share from self only" event + * @param GenericEvent $event + */ + public static function unShareSelf(GenericEvent $event) { + $share = $event->getSubject(); + if ($share instanceof IShare) { + self::getHooks()->unShareSelf($share); + } + } }