Skip to content
Merged
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
67 changes: 37 additions & 30 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,32 @@ protected function deleteChildren(\OCP\Share\IShare $share) {
return $deletedShares;
}

protected static function formatUnshareHookParams(\OCP\Share\IShare $share) {
// Prepare hook
$shareType = $share->getShareType();
$sharedWith = '';
if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
$sharedWith = $share->getSharedWith();
} else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
$sharedWith = $share->getSharedWith();
} else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
$sharedWith = $share->getSharedWith();
}

$hookParams = [
'id' => $share->getId(),
'itemType' => $share->getNodeType(),
'itemSource' => $share->getNodeId(),
'shareType' => $shareType,
'shareWith' => $sharedWith,
'itemparent' => method_exists($share, 'getParent') ? $share->getParent() : '',
'uidOwner' => $share->getSharedBy(),
'fileSource' => $share->getNodeId(),
'fileTarget' => $share->getTarget()
];
return $hookParams;
}

/**
* Delete a share
*
Expand All @@ -779,33 +805,7 @@ public function deleteShare(\OCP\Share\IShare $share) {
throw new \InvalidArgumentException('Share does not have a full id');
}

$formatHookParams = function(\OCP\Share\IShare $share) {
// Prepare hook
$shareType = $share->getShareType();
$sharedWith = '';
if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
$sharedWith = $share->getSharedWith();
} else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
$sharedWith = $share->getSharedWith();
} else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
$sharedWith = $share->getSharedWith();
}

$hookParams = [
'id' => $share->getId(),
'itemType' => $share->getNodeType(),
'itemSource' => $share->getNodeId(),
'shareType' => $shareType,
'shareWith' => $sharedWith,
'itemparent' => method_exists($share, 'getParent') ? $share->getParent() : '',
'uidOwner' => $share->getSharedBy(),
'fileSource' => $share->getNodeId(),
'fileTarget' => $share->getTarget()
];
return $hookParams;
};

$hookParams = $formatHookParams($share);
$hookParams = self::formatUnshareHookParams($share);

// Emit pre-hook
\OC_Hook::emit('OCP\Share', 'pre_unshare', $hookParams);
Expand All @@ -821,9 +821,7 @@ public function deleteShare(\OCP\Share\IShare $share) {
$deletedShares[] = $share;

//Format hook info
$formattedDeletedShares = array_map(function($share) use ($formatHookParams) {
return $formatHookParams($share);
}, $deletedShares);
$formattedDeletedShares = array_map('self::formatUnshareHookParams', $deletedShares);

$hookParams['deletedShares'] = $formattedDeletedShares;

Expand All @@ -846,6 +844,15 @@ public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) {
$provider = $this->factory->getProvider($providerId);

$provider->deleteFromSelf($share, $recipientId);

// Emit post hook. The parameter data structure is slightly different
// from the post_unshare hook to maintain backward compatibility with
// Share 1.0: the array contains all the key-value pairs from the old
// library plus some new ones.
$hookParams = self::formatUnshareHookParams($share);
$hookParams['itemTarget'] = $hookParams['fileTarget'];
$hookParams['unsharedItems'] = [$hookParams];
\OC_Hook::emit('OCP\Share', 'post_unshareFromSelf', $hookParams);
}

/**
Expand Down