Skip to content

Commit

Permalink
Merge pull request #380 from nextcloud/backport/379/stable16
Browse files Browse the repository at this point in the history
[stable16] Fix "unshare group share from self" activity
  • Loading branch information
nickvergessen authored Jun 21, 2019
2 parents 94ebfd4 + 83e2dc0 commit 4fc358a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
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);
}
}
}

0 comments on commit 4fc358a

Please sign in to comment.