]> source.dussan.org Git - nextcloud-server.git/commitdiff
[Share 2.0] Fix pre_share and post_share hooks
authorRoeland Jago Douma <rullzer@owncloud.com>
Wed, 13 Jan 2016 20:48:53 +0000 (21:48 +0100)
committerRoeland Jago Douma <rullzer@owncloud.com>
Wed, 13 Jan 2016 20:56:04 +0000 (21:56 +0100)
lib/private/share20/manager.php
tests/lib/share20/managertest.php

index 0c6f9cb59dbf6d8380df99ef7b1840d25adb61ee..035026b47ea3effef2583616138b54f8ab794dc1 100644 (file)
@@ -452,6 +452,16 @@ class Manager {
                $target = \OC\Files\Filesystem::normalizePath($target);
                $share->setTarget($target);
 
+               //Get sharewith for hooks
+               $sharedWith = null;
+               if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
+                       $sharedWith = $share->getSharedWith()->getUID();
+               } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
+                       $sharedWith = $share->getSharedWith()->getGID();
+               } else {
+                       $sharedWith = $share->getSharedWith();
+               }
+
                // Pre share hook
                $run = true;
                $error = '';
@@ -464,8 +474,10 @@ class Manager {
                        'fileSource' => $share->getPath()->getId(),
                        'expiration' => $share->getExpirationDate(),
                        'token' => $share->getToken(),
+                       'itemTarget' => $share->getTarget(),
+                       'shareWith' => $sharedWith,
                        'run' => &$run,
-                       'error' => &$error
+                       'error' => &$error,
                ];
                \OC_Hook::emit('OCP\Share', 'pre_shared', $preHookData);
 
@@ -488,7 +500,11 @@ class Manager {
                        'expiration' => $share->getExpirationDate(),
                        'token' => $share->getToken(),
                        'id' => $share->getId(),
+                       'shareWith' => $sharedWith,
+                       'itemTarget' => $share->getTarget(),
+                       'fileTarget' => $share->getTarget(),
                ];
+
                \OC_Hook::emit('OCP\Share', 'post_shared', $postHookData);
 
                return $share;
index 170a1d02af26bb12c224651ff6851e8915fbc308..bfee9c39593e02196640b834617c701d68d5400c 100644 (file)
@@ -1364,6 +1364,8 @@ class ManagerTest extends \Test\TestCase {
                $share->expects($this->once())
                        ->method('setTarget')
                        ->with('/target');
+               $share->method('getTarget')
+                       ->willReturn('/target');
                $share->expects($this->once())
                        ->method('setExpirationDate')
                        ->with($date);
@@ -1388,6 +1390,8 @@ class ManagerTest extends \Test\TestCase {
                        'token' => 'token',
                        'run' => true,
                        'error' => '',
+                       'itemTarget' => '/target',
+                       'shareWith' => null,
                ];
 
                $hookListnerExpectsPost = [
@@ -1400,6 +1404,9 @@ class ManagerTest extends \Test\TestCase {
                        'expiration' => $date,
                        'token' => 'token',
                        'id' => 42,
+                       'itemTarget' => '/target',
+                       'fileTarget' => '/target',
+                       'shareWith' => null,
                ];
 
                $share->method('getId')->willReturn(42);