Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}
31 changes: 31 additions & 0 deletions lib/FilesHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
*
Expand Down
11 changes: 11 additions & 0 deletions lib/FilesHooksStatic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}