Skip to content

Commit

Permalink
Merge pull request #18631 from owncloud/more_ocs_share_data
Browse files Browse the repository at this point in the history
Return permissions and expiration on create share responses
  • Loading branch information
Vincent Petry committed Sep 1, 2015
2 parents 85b62c7 + d54b497 commit 0d4562c
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 22 deletions.
4 changes: 4 additions & 0 deletions apps/files_sharing/api/local.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,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");
Expand Down
138 changes: 116 additions & 22 deletions apps/files_sharing/tests/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

Expand Down Expand Up @@ -287,7 +376,7 @@ function testSharePermissions() {

/**
* @medium
* @depends testCreateShare
* @depends testCreateShareUserFile
*/
function testGetAllShares() {

Expand Down Expand Up @@ -334,7 +423,7 @@ function testGetAllSharesWithMe() {

/**
* @medium
* @depends testCreateShare
* @depends testCreateShareLink
*/
function testPublicLinkUrl() {
// simulate a post request
Expand Down Expand Up @@ -379,7 +468,8 @@ function testPublicLinkUrl() {

/**
* @medium
* @depends testCreateShare
* @depends testCreateShareUserFile
* @depends testCreateShareLink
*/
function testGetShareFromSource() {

Expand Down Expand Up @@ -409,7 +499,8 @@ function testGetShareFromSource() {

/**
* @medium
* @depends testCreateShare
* @depends testCreateShareUserFile
* @depends testCreateShareLink
*/
function testGetShareFromSourceWithReshares() {

Expand Down Expand Up @@ -463,7 +554,7 @@ function testGetShareFromSourceWithReshares() {

/**
* @medium
* @depends testCreateShare
* @depends testCreateShareUserFile
*/
function testGetShareFromId() {

Expand Down Expand Up @@ -911,7 +1002,8 @@ function testGetShareFromUnknownId() {

/**
* @medium
* @depends testCreateShare
* @depends testCreateShareUserFile
* @depends testCreateShareLink
*/
function testUpdateShare() {

Expand Down Expand Up @@ -1037,7 +1129,7 @@ function testUpdateShare() {

/**
* @medium
* @depends testCreateShare
* @depends testCreateShareUserFile
*/
public function testUpdateShareInvalidPermissions() {

Expand Down Expand Up @@ -1232,7 +1324,7 @@ function testUpdateShareExpireDate() {

/**
* @medium
* @depends testCreateShare
* @depends testCreateShareUserFile
*/
function testDeleteShare() {

Expand Down Expand Up @@ -1526,6 +1618,7 @@ public function testPublicLinkExpireDate($date, $valid) {

$data = $result->getData();
$this->assertTrue(is_string($data['token']));
$this->assertEquals($date, substr($data['expiration'], 0, 10));

// check for correct link
$url = \OC::$server->getURLGenerator()->getAbsoluteURL('/index.php/s/' . $data['token']);
Expand Down Expand Up @@ -1564,6 +1657,7 @@ public function testCreatePublicLinkExpireDateValid() {

$data = $result->getData();
$this->assertTrue(is_string($data['token']));
$this->assertEquals($date->format('Y-m-d') . ' 00:00:00', $data['expiration']);

// check for correct link
$url = \OC::$server->getURLGenerator()->getAbsoluteURL('/index.php/s/' . $data['token']);
Expand Down

0 comments on commit 0d4562c

Please sign in to comment.