diff options
author | Roeland Jago Douma <rullzer@owncloud.com> | 2015-11-02 21:06:55 +0100 |
---|---|---|
committer | Roeland Jago Douma <rullzer@owncloud.com> | 2015-11-05 15:59:09 +0100 |
commit | 0be05fdddd06866a55f168d44ad792066235ad96 (patch) | |
tree | 1ae4db9549b365afbf98bdbe5f56962545e00405 /lib | |
parent | 0c566698a161b0385ddce34293f98e040ba4d660 (diff) | |
download | nextcloud-server-0be05fdddd06866a55f168d44ad792066235ad96.tar.gz nextcloud-server-0be05fdddd06866a55f168d44ad792066235ad96.zip |
Add unshare hooks
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/share20/defaultshareprovider.php | 31 | ||||
-rw-r--r-- | lib/private/share20/ishare.php | 7 | ||||
-rw-r--r-- | lib/private/share20/share.php | 23 |
3 files changed, 59 insertions, 2 deletions
diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php index 41de81cf346..79bc809b9b2 100644 --- a/lib/private/share20/defaultshareprovider.php +++ b/lib/private/share20/defaultshareprovider.php @@ -112,8 +112,32 @@ class DefaultShareProvider implements IShareProvider { public function delete(IShare $share) { $this->deleteChildren($share); - $qb = $this->dbConn->getQueryBuilder(); + // Fetch share to make sure it exists + $share = $this->getShareById($share->getId()); + + $shareType = $share->getShareType(); + $sharedWith = ''; + if ($shareType === \OCP\Share::SHARE_TYPE_USER) { + $sharedWith = $share->getSharedWith()->getUID(); + } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { + $sharedWith = $share->getSharedWith()->getGID(); + } + + $hookParams = [ + 'id' => $share->getId(), + 'itemType' => $share->getPath() instanceof \OCP\Files\File ? 'file' : 'folder', + 'itemSource' => $share->getPath()->getId(), + 'shareType' => $shareType, + 'shareWith' => $sharedWith, + 'itemparent' => $share->getParent(), + 'uidOwner' => $share->getSharedBy()->getUID(), + 'fileSource' => $share->getPath()->getId(), + 'fileTarget' => $share->getTarget() + ]; + \OC_Hook::emit('OCP\Share', 'pre_unshare', $hookParams); + + $qb = $this->dbConn->getQueryBuilder(); $qb->delete('share') ->where($qb->expr()->eq('id', $qb->createParameter('id'))) ->setParameter(':id', $share->getId()); @@ -123,6 +147,8 @@ class DefaultShareProvider implements IShareProvider { } catch (\Exception $e) { throw new BackendError(); } + + \OC_Hook::emit('OCP\Share', 'post_unshare', $hookParams); } /** @@ -208,7 +234,8 @@ class DefaultShareProvider implements IShareProvider { $share = new Share(); $share->setId((int)$data['id']) ->setShareType((int)$data['share_type']) - ->setPermissions((int)$data['permissions']); + ->setPermissions((int)$data['permissions']) + ->setTarget($data['file_target']); if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { $share->setSharedWith($this->userManager->get($data['share_with'])); diff --git a/lib/private/share20/ishare.php b/lib/private/share20/ishare.php index 7c5cce9b21e..fa7c1ea614c 100644 --- a/lib/private/share20/ishare.php +++ b/lib/private/share20/ishare.php @@ -146,4 +146,11 @@ interface IShare { * @return int */ public function getParent(); + + /** + * Get the target of this share + * + * @return string + */ + public function getTarget(); } diff --git a/lib/private/share20/share.php b/lib/private/share20/share.php index 380526fd281..989edd3c079 100644 --- a/lib/private/share20/share.php +++ b/lib/private/share20/share.php @@ -59,6 +59,9 @@ class Share implements IShare { /** @var int */ private $parent; + /** @var string */ + private $target; + /** * Set the id of the share * @@ -292,4 +295,24 @@ class Share implements IShare { public function getParent() { return $this->parent; } + + /** + * Set the target of this share + * + * @param string target + * @return Share The modified object + */ + public function setTarget($target) { + $this->target = $target; + return $this; + } + + /** + * Get the target of this share + * + * @return string + */ + public function getTarget() { + return $this->target; + } } |