Merge pull request #21703 from owncloud/fix_share_create_hooks
[Share 2.0] Fix pre_share and post_share hooks
This commit is contained in:
commit
03c08bea9d
|
@ -204,7 +204,7 @@ Feature: sharing
|
||||||
When sending "GET" to "/apps/files_sharing/api/v1/shares"
|
When sending "GET" to "/apps/files_sharing/api/v1/shares"
|
||||||
Then the OCS status code should be "100"
|
Then the OCS status code should be "100"
|
||||||
And the HTTP status code should be "200"
|
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
|
Scenario: getting all shares of a user using another user
|
||||||
Given user "user0" exists
|
Given user "user0" exists
|
||||||
|
@ -264,7 +264,7 @@ Feature: sharing
|
||||||
| share_type | 0 |
|
| share_type | 0 |
|
||||||
| share_with | user1 |
|
| share_with | user1 |
|
||||||
| file_source | A_NUMBER |
|
| file_source | A_NUMBER |
|
||||||
| file_target | /textfile0.txt |
|
| file_target | /textfile0 (2).txt |
|
||||||
| path | /textfile0.txt |
|
| path | /textfile0.txt |
|
||||||
| permissions | 19 |
|
| permissions | 19 |
|
||||||
| stime | A_NUMBER |
|
| stime | A_NUMBER |
|
||||||
|
|
|
@ -452,6 +452,16 @@ class Manager {
|
||||||
$target = \OC\Files\Filesystem::normalizePath($target);
|
$target = \OC\Files\Filesystem::normalizePath($target);
|
||||||
$share->setTarget($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
|
// Pre share hook
|
||||||
$run = true;
|
$run = true;
|
||||||
$error = '';
|
$error = '';
|
||||||
|
@ -464,8 +474,10 @@ class Manager {
|
||||||
'fileSource' => $share->getPath()->getId(),
|
'fileSource' => $share->getPath()->getId(),
|
||||||
'expiration' => $share->getExpirationDate(),
|
'expiration' => $share->getExpirationDate(),
|
||||||
'token' => $share->getToken(),
|
'token' => $share->getToken(),
|
||||||
|
'itemTarget' => $share->getTarget(),
|
||||||
|
'shareWith' => $sharedWith,
|
||||||
'run' => &$run,
|
'run' => &$run,
|
||||||
'error' => &$error
|
'error' => &$error,
|
||||||
];
|
];
|
||||||
\OC_Hook::emit('OCP\Share', 'pre_shared', $preHookData);
|
\OC_Hook::emit('OCP\Share', 'pre_shared', $preHookData);
|
||||||
|
|
||||||
|
@ -488,7 +500,11 @@ class Manager {
|
||||||
'expiration' => $share->getExpirationDate(),
|
'expiration' => $share->getExpirationDate(),
|
||||||
'token' => $share->getToken(),
|
'token' => $share->getToken(),
|
||||||
'id' => $share->getId(),
|
'id' => $share->getId(),
|
||||||
|
'shareWith' => $sharedWith,
|
||||||
|
'itemTarget' => $share->getTarget(),
|
||||||
|
'fileTarget' => $share->getTarget(),
|
||||||
];
|
];
|
||||||
|
|
||||||
\OC_Hook::emit('OCP\Share', 'post_shared', $postHookData);
|
\OC_Hook::emit('OCP\Share', 'post_shared', $postHookData);
|
||||||
|
|
||||||
return $share;
|
return $share;
|
||||||
|
|
|
@ -1364,6 +1364,8 @@ class ManagerTest extends \Test\TestCase {
|
||||||
$share->expects($this->once())
|
$share->expects($this->once())
|
||||||
->method('setTarget')
|
->method('setTarget')
|
||||||
->with('/target');
|
->with('/target');
|
||||||
|
$share->method('getTarget')
|
||||||
|
->willReturn('/target');
|
||||||
$share->expects($this->once())
|
$share->expects($this->once())
|
||||||
->method('setExpirationDate')
|
->method('setExpirationDate')
|
||||||
->with($date);
|
->with($date);
|
||||||
|
@ -1388,6 +1390,8 @@ class ManagerTest extends \Test\TestCase {
|
||||||
'token' => 'token',
|
'token' => 'token',
|
||||||
'run' => true,
|
'run' => true,
|
||||||
'error' => '',
|
'error' => '',
|
||||||
|
'itemTarget' => '/target',
|
||||||
|
'shareWith' => null,
|
||||||
];
|
];
|
||||||
|
|
||||||
$hookListnerExpectsPost = [
|
$hookListnerExpectsPost = [
|
||||||
|
@ -1400,6 +1404,9 @@ class ManagerTest extends \Test\TestCase {
|
||||||
'expiration' => $date,
|
'expiration' => $date,
|
||||||
'token' => 'token',
|
'token' => 'token',
|
||||||
'id' => 42,
|
'id' => 42,
|
||||||
|
'itemTarget' => '/target',
|
||||||
|
'fileTarget' => '/target',
|
||||||
|
'shareWith' => null,
|
||||||
];
|
];
|
||||||
|
|
||||||
$share->method('getId')->willReturn(42);
|
$share->method('getId')->willReturn(42);
|
||||||
|
|
Loading…
Reference in New Issue