Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable16] Fix "unshare group share from self" activity #380

Merged
merged 1 commit into from
Jun 21, 2019
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);
}
}
}