Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

OCS Share API link shares now always have an url #16535

Merged
merged 1 commit into from
Jul 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apps/files_sharing/api/local.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public static function getAllShares($params) {
}
$share['icon'] = substr(\OC_Helper::mimetypeIcon($share['mimetype']), 0, -3) . 'svg';
}

if (!is_null($share['token'])) {
$share['url'] = \OC::$server->getURLGenerator()->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share['token']]);
}
}
return new \OC_OCS_Result($shares);
}
Expand Down Expand Up @@ -142,6 +146,12 @@ private static function collectShares($params) {
if ($shares === null || empty($shares)) {
return new \OC_OCS_Result(null, 404, 'share doesn\'t exist');
} else {
foreach ($shares as &$share) {
if (!is_null($share['token'])) {
$share['url'] = \OC::$server->getURLGenerator()->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share['token']]);
}
}

return new \OC_OCS_Result($shares);
}
}
Expand Down
45 changes: 45 additions & 0 deletions apps/files_sharing/tests/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,51 @@ function testGetAllShares() {
\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
}

/**
* @medium
* @depends testCreateShare
*/
function testPublicLinkUrl() {
// simulate a post request
$_POST['path'] = $this->folder;
$_POST['shareType'] = \OCP\Share::SHARE_TYPE_LINK;

$result = \OCA\Files_Sharing\API\Local::createShare([]);
$this->assertTrue($result->succeeded());
$data = $result->getData();

// check if we have a token
$this->assertTrue(is_string($data['token']));
$id = $data['id'];

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

// check for link in getall shares
$result = \OCA\Files_Sharing\API\Local::getAllShares([]);
$this->assertTrue($result->succeeded());
$data = $result->getData();
$this->assertEquals($url, current($data)['url']);

// check for path
$_GET['path'] = $this->folder;
$result = \OCA\Files_Sharing\API\Local::getAllShares([]);
$this->assertTrue($result->succeeded());
$data = $result->getData();
$this->assertEquals($url, current($data)['url']);

// check in share id
$result = \OCA\Files_Sharing\API\Local::getShare(['id' => $id]);
$this->assertTrue($result->succeeded());
$data = $result->getData();
$this->assertEquals($url, current($data)['url']);

//Clean up share
$fileinfo = $this->view->getFileInfo($this->folder);
\OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, null);
}

/**
* @medium
* @depends testCreateShare
Expand Down