diff --git a/apps/files_sharing/api/local.php b/apps/files_sharing/api/local.php index eb0e0e0d846d..a336bf0ca3e2 100644 --- a/apps/files_sharing/api/local.php +++ b/apps/files_sharing/api/local.php @@ -332,6 +332,10 @@ public static function createShare($params) { } } } + + $data['permissions'] = $share['permissions']; + $data['expiration'] = $share['expiration']; + return new \OC_OCS_Result($data); } else { return new \OC_OCS_Result(null, 404, "couldn't share file"); diff --git a/apps/files_sharing/tests/api.php b/apps/files_sharing/tests/api.php index 3bd568e47af9..9863fee99374 100644 --- a/apps/files_sharing/tests/api.php +++ b/apps/files_sharing/tests/api.php @@ -73,40 +73,108 @@ protected function tearDown() { /** * @medium */ - function testCreateShare() { + function testCreateShareUserFile() { + // simulate a post request + $_POST['path'] = $this->filename; + $_POST['shareWith'] = \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2; + $_POST['shareType'] = \OCP\Share::SHARE_TYPE_USER; + + $result = \OCA\Files_Sharing\API\Local::createShare([]); + + $this->assertTrue($result->succeeded()); + $data = $result->getData(); + $this->assertEquals(23, $data['permissions']); + $this->assertEmpty($data['expiration']); + + $share = $this->getShareFromId($data['id']); + $items = \OCP\Share::getItemShared('file', $share['item_source']); + $this->assertTrue(!empty($items)); - // share to user + $fileinfo = $this->view->getFileInfo($this->filename); + \OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, + \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2); + } + function testCreateShareUserFolder() { // simulate a post request - $_POST['path'] = $this->filename; + $_POST['path'] = $this->folder; $_POST['shareWith'] = \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2; $_POST['shareType'] = \OCP\Share::SHARE_TYPE_USER; - $result = \OCA\Files_Sharing\API\Local::createShare(array()); + $result = \OCA\Files_Sharing\API\Local::createShare([]); $this->assertTrue($result->succeeded()); $data = $result->getData(); + $this->assertEquals(31, $data['permissions']); + $this->assertEmpty($data['expiration']); $share = $this->getShareFromId($data['id']); + $items = \OCP\Share::getItemShared('file', $share['item_source']); + $this->assertTrue(!empty($items)); + + $fileinfo = $this->view->getFileInfo($this->folder); + \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, + \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2); + } + + + function testCreateShareGroupFile() { + // simulate a post request + $_POST['path'] = $this->filename; + $_POST['shareWith'] = \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_GROUP1; + $_POST['shareType'] = \OCP\Share::SHARE_TYPE_GROUP; + + $result = \OCA\Files_Sharing\API\Local::createShare([]); + $this->assertTrue($result->succeeded()); + $data = $result->getData(); + $this->assertEquals(23, $data['permissions']); + $this->assertEmpty($data['expiration']); + + $share = $this->getShareFromId($data['id']); $items = \OCP\Share::getItemShared('file', $share['item_source']); + $this->assertTrue(!empty($items)); + + $fileinfo = $this->view->getFileInfo($this->filename); + \OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, + \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_GROUP1); + } + + function testCreateShareGroupFolder() { + // simulate a post request + $_POST['path'] = $this->folder; + $_POST['shareWith'] = \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_GROUP1; + $_POST['shareType'] = \OCP\Share::SHARE_TYPE_GROUP; + + $result = \OCA\Files_Sharing\API\Local::createShare([]); + + $this->assertTrue($result->succeeded()); + $data = $result->getData(); + $this->assertEquals(31, $data['permissions']); + $this->assertEmpty($data['expiration']); + $share = $this->getShareFromId($data['id']); + $items = \OCP\Share::getItemShared('file', $share['item_source']); $this->assertTrue(!empty($items)); - // share link + $fileinfo = $this->view->getFileInfo($this->folder); + \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, + \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_GROUP1); + } + public function testCreateShareLink() { // simulate a post request $_POST['path'] = $this->folder; $_POST['shareType'] = \OCP\Share::SHARE_TYPE_LINK; - $result = \OCA\Files_Sharing\API\Local::createShare(array()); + $result = \OCA\Files_Sharing\API\Local::createShare([]); // check if API call was successful $this->assertTrue($result->succeeded()); $data = $result->getData(); - - // check if we have a token + $this->assertEquals(1, $data['permissions']); + $this->assertEmpty($data['expiration']); $this->assertTrue(is_string($data['token'])); // check for correct link @@ -115,18 +183,39 @@ function testCreateShare() { $share = $this->getShareFromId($data['id']); - $items = \OCP\Share::getItemShared('file', $share['item_source']); - $this->assertTrue(!empty($items)); - $fileinfo = $this->view->getFileInfo($this->filename); + $fileinfo = $this->view->getFileInfo($this->folder); + \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, null); + } - \OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, - \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2); + public function testCreateShareLinkPublicUpload() { + // simulate a post request + $_POST['path'] = $this->folder; + $_POST['shareType'] = \OCP\Share::SHARE_TYPE_LINK; + $_POST['publicUpload'] = 'true'; - $fileinfo = $this->view->getFileInfo($this->folder); + $result = \OCA\Files_Sharing\API\Local::createShare(array()); + + // check if API call was successful + $this->assertTrue($result->succeeded()); + + $data = $result->getData(); + $this->assertEquals(7, $data['permissions']); + $this->assertEmpty($data['expiration']); + $this->assertTrue(is_string($data['token'])); + // check for correct link + $url = \OC::$server->getURLGenerator()->getAbsoluteURL('/index.php/s/' . $data['token']); + $this->assertEquals($url, $data['url']); + + + $share = $this->getShareFromId($data['id']); + $items = \OCP\Share::getItemShared('file', $share['item_source']); + $this->assertTrue(!empty($items)); + + $fileinfo = $this->view->getFileInfo($this->folder); \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, null); } @@ -287,7 +376,7 @@ function testSharePermissions() { /** * @medium - * @depends testCreateShare + * @depends testCreateShareUserFile */ function testGetAllShares() { @@ -334,7 +423,7 @@ function testGetAllSharesWithMe() { /** * @medium - * @depends testCreateShare + * @depends testCreateShareLink */ function testPublicLinkUrl() { // simulate a post request @@ -379,7 +468,8 @@ function testPublicLinkUrl() { /** * @medium - * @depends testCreateShare + * @depends testCreateShareUserFile + * @depends testCreateShareLink */ function testGetShareFromSource() { @@ -409,7 +499,8 @@ function testGetShareFromSource() { /** * @medium - * @depends testCreateShare + * @depends testCreateShareUserFile + * @depends testCreateShareLink */ function testGetShareFromSourceWithReshares() { @@ -463,7 +554,7 @@ function testGetShareFromSourceWithReshares() { /** * @medium - * @depends testCreateShare + * @depends testCreateShareUserFile */ function testGetShareFromId() { @@ -911,7 +1002,8 @@ function testGetShareFromUnknownId() { /** * @medium - * @depends testCreateShare + * @depends testCreateShareUserFile + * @depends testCreateShareLink */ function testUpdateShare() { @@ -1037,7 +1129,7 @@ function testUpdateShare() { /** * @medium - * @depends testCreateShare + * @depends testCreateShareUserFile */ public function testUpdateShareInvalidPermissions() { @@ -1232,7 +1324,7 @@ function testUpdateShareExpireDate() { /** * @medium - * @depends testCreateShare + * @depends testCreateShareUserFile */ function testDeleteShare() {