aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-01-14 09:56:37 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-01-14 09:56:37 +0100
commit03c08bea9d80038305a9ffedeaef606774042bc4 (patch)
tree29fc979ea00145f320e842fa7ef311d180c8a827
parent205fbcbfa3cf221fad23cfd3379a412aba0dd314 (diff)
parente081c866916b564520620c3e363b58ad4a76723b (diff)
downloadnextcloud-server-03c08bea9d80038305a9ffedeaef606774042bc4.tar.gz
nextcloud-server-03c08bea9d80038305a9ffedeaef606774042bc4.zip
Merge pull request #21703 from owncloud/fix_share_create_hooks
[Share 2.0] Fix pre_share and post_share hooks
-rw-r--r--build/integration/features/sharing-v1.feature4
-rw-r--r--lib/private/share20/manager.php18
-rw-r--r--tests/lib/share20/managertest.php7
3 files changed, 26 insertions, 3 deletions
diff --git a/build/integration/features/sharing-v1.feature b/build/integration/features/sharing-v1.feature
index 65a8459e9a1..1287a2daf86 100644
--- a/build/integration/features/sharing-v1.feature
+++ b/build/integration/features/sharing-v1.feature
@@ -204,7 +204,7 @@ Feature: sharing
When sending "GET" to "/apps/files_sharing/api/v1/shares"
Then the OCS status code should be "100"
And the HTTP status code should be "200"
- And File "textfile0.txt" should be included in the response
+ And File "textfile0 (2).txt" should be included in the response
Scenario: getting all shares of a user using another user
Given user "user0" exists
@@ -264,7 +264,7 @@ Feature: sharing
| share_type | 0 |
| share_with | user1 |
| file_source | A_NUMBER |
- | file_target | /textfile0.txt |
+ | file_target | /textfile0 (2).txt |
| path | /textfile0.txt |
| permissions | 19 |
| stime | A_NUMBER |
diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php
index 0c6f9cb59db..035026b47ea 100644
--- a/lib/private/share20/manager.php
+++ b/lib/private/share20/manager.php
@@ -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;
diff --git a/tests/lib/share20/managertest.php b/tests/lib/share20/managertest.php
index 170a1d02af2..bfee9c39593 100644
--- a/tests/lib/share20/managertest.php
+++ b/tests/lib/share20/managertest.php
@@ -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);