rename SaveToNextcloudController to MountPublicLinkController

This commit is contained in:
Bjoern Schiessle 2016-07-14 11:01:25 +02:00
parent 56d3100f44
commit c7f6461c53
No known key found for this signature in database
GPG Key ID: 2378A753E2BF04F6
4 changed files with 31 additions and 25 deletions

View File

@ -21,7 +21,7 @@
return [ return [
'routes' => [ 'routes' => [
['name' => 'SaveToNextcloud#saveToNextcloud', 'url' => '/saveToNextcloud', 'verb' => 'POST'], ['name' => 'MountPublicLink#createFederatedShare', 'url' => '/createFederatedShare', 'verb' => 'POST'],
['name' => 'SaveToNextcloud#askForFederatedShare', 'url' => '/askForFederatedShare', 'verb' => 'POST'], ['name' => 'MountPublicLink#askForFederatedShare', 'url' => '/askForFederatedShare', 'verb' => 'POST'],
] ]
]; ];

View File

@ -37,7 +37,14 @@ use OCP\ISession;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\Share\IManager; use OCP\Share\IManager;
class SaveToNextcloudController extends Controller { /**
* Class MountPublicLinkController
*
* convert public links to federated shares
*
* @package OCA\FederatedFileSharing\Controller
*/
class MountPublicLinkController extends Controller {
/** @var FederatedShareProvider */ /** @var FederatedShareProvider */
private $federatedShareProvider; private $federatedShareProvider;
@ -61,7 +68,7 @@ class SaveToNextcloudController extends Controller {
private $clientService; private $clientService;
/** /**
* SaveToNextcloudController constructor. * MountPublicLinkController constructor.
* *
* @param string $appName * @param string $appName
* @param IRequest $request * @param IRequest $request
@ -95,8 +102,7 @@ class SaveToNextcloudController extends Controller {
} }
/** /**
* save public link to my Nextcloud by asking the owner to create a federated * send federated share to a user of a public link
* share with me
* *
* @NoCSRFRequired * @NoCSRFRequired
* @PublicPage * @PublicPage
@ -106,7 +112,7 @@ class SaveToNextcloudController extends Controller {
* @param string $password * @param string $password
* @return JSONResponse * @return JSONResponse
*/ */
public function saveToNextcloud($shareWith, $token, $password = '') { public function createFederatedShare($shareWith, $token, $password = '') {
try { try {
list(, $server) = $this->addressHandler->splitUserRemote($shareWith); list(, $server) = $this->addressHandler->splitUserRemote($shareWith);
@ -158,14 +164,15 @@ class SaveToNextcloudController extends Controller {
$httpClient = $this->clientService->newClient(); $httpClient = $this->clientService->newClient();
try { try {
$response = $httpClient->post($remote . '/index.php/apps/federatedfilesharing/saveToNextcloud', $response = $httpClient->post($remote . '/index.php/apps/federatedfilesharing/createFederatedShare',
[ [
'body' => 'body' =>
[ [
'token' => $token, 'token' => $token,
'shareWith' => rtrim($shareWith, '/'), 'shareWith' => rtrim($shareWith, '/'),
'password' => $password 'password' => $password
] ],
'connect_timeout' => 10,
] ]
); );
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@ -26,7 +26,7 @@ namespace OCA\FederatedFileSharing\Tests\Controller;
use OC\HintException; use OC\HintException;
use OCA\FederatedFileSharing\AddressHandler; use OCA\FederatedFileSharing\AddressHandler;
use OCA\FederatedFileSharing\Controller\SaveToNextcloudController; use OCA\FederatedFileSharing\Controller\MountPublicLinkController;
use OCA\FederatedFileSharing\FederatedShareProvider; use OCA\FederatedFileSharing\FederatedShareProvider;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\Files\IRootFolder; use OCP\Files\IRootFolder;
@ -35,13 +35,12 @@ use OCP\IL10N;
use OCP\ISession; use OCP\ISession;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\Share;
use OCP\Share\IManager; use OCP\Share\IManager;
use OCP\Share\IShare; use OCP\Share\IShare;
class SaveToNextcloudControllerTest extends \Test\TestCase { class MountPublicLinkControllerTest extends \Test\TestCase {
/** @var SaveToNextcloudController */ /** @var MountPublicLinkController */
private $controller; private $controller;
/** @var \OCP\IRequest | \PHPUnit_Framework_MockObject_MockObject */ /** @var \OCP\IRequest | \PHPUnit_Framework_MockObject_MockObject */
@ -94,7 +93,7 @@ class SaveToNextcloudControllerTest extends \Test\TestCase {
$this->userSession = $this->getMockBuilder('OCP\IUserSession')->disableOriginalConstructor()->getMock(); $this->userSession = $this->getMockBuilder('OCP\IUserSession')->disableOriginalConstructor()->getMock();
$this->clientService = $this->getMockBuilder('OCP\Http\Client\IClientService')->disableOriginalConstructor()->getMock(); $this->clientService = $this->getMockBuilder('OCP\Http\Client\IClientService')->disableOriginalConstructor()->getMock();
$this->controller = new SaveToNextcloudController( $this->controller = new MountPublicLinkController(
'federatedfilesharing', $this->request, 'federatedfilesharing', $this->request,
$this->federatedShareProvider, $this->federatedShareProvider,
$this->shareManager, $this->shareManager,
@ -107,7 +106,7 @@ class SaveToNextcloudControllerTest extends \Test\TestCase {
} }
/** /**
* @dataProvider dataTestSaveToNextcloud * @dataProvider dataTestCreateFederatedShare
* *
* @param string $shareWith * @param string $shareWith
* @param bool $validShareWith * @param bool $validShareWith
@ -116,7 +115,7 @@ class SaveToNextcloudControllerTest extends \Test\TestCase {
* @param bool $createSuccessful * @param bool $createSuccessful
* @param string $expectedReturnData * @param string $expectedReturnData
*/ */
public function testSaveToNextcloud($shareWith, $validShareWith, $token, $validToken, $createSuccessful, $expectedReturnData) { public function testCreateFederatedShare($shareWith, $validShareWith, $token, $validToken, $createSuccessful, $expectedReturnData) {
$this->addressHandler->expects($this->any())->method('splitUserRemote') $this->addressHandler->expects($this->any())->method('splitUserRemote')
->with($shareWith) ->with($shareWith)
->willReturnCallback( ->willReturnCallback(
@ -153,7 +152,7 @@ class SaveToNextcloudControllerTest extends \Test\TestCase {
} }
); );
$result = $this->controller->saveToNextcloud($shareWith, $token); $result = $this->controller->createFederatedShare($shareWith, $token);
$errorCase = !$validShareWith || !$validToken || !$createSuccessful; $errorCase = !$validShareWith || !$validToken || !$createSuccessful;
@ -170,7 +169,7 @@ class SaveToNextcloudControllerTest extends \Test\TestCase {
} }
public function dataTestSaveToNextcloud() { public function dataTestCreateFederatedShare() {
return [ return [
//shareWith, validShareWith, token, validToken, createSuccessful, expectedReturnData //shareWith, validShareWith, token, validToken, createSuccessful, expectedReturnData
['user@server', true, 'token', true, true, 'server'], ['user@server', true, 'token', true, true, 'server'],

View File

@ -248,7 +248,7 @@ OCA.Sharing.PublicApp = {
var ownerDisplayName = $('#save').data('owner-display-name'); var ownerDisplayName = $('#save').data('owner-display-name');
var name = $('#save').data('name'); var name = $('#save').data('name');
var isProtected = $('#save').data('protected') ? 1 : 0; var isProtected = $('#save').data('protected') ? 1 : 0;
OCA.Sharing.PublicApp._saveToNextcloud(remote, token, owner, ownerDisplayName, name, isProtected); OCA.Sharing.PublicApp._createFederatedShare(remote, token, owner, ownerDisplayName, name, isProtected);
}); });
$('#remote_address').on("keyup paste", function() { $('#remote_address').on("keyup paste", function() {
@ -308,7 +308,7 @@ OCA.Sharing.PublicApp = {
* @param isProtected * @param isProtected
* @private * @private
*/ */
_legacySaveToNextcloud: function (remote, token, owner, ownerDisplayName, name, isProtected) { _legacyCreateFederatedShare: function (remote, token, owner, ownerDisplayName, name, isProtected) {
var location = window.location.protocol + '//' + window.location.host + OC.webroot; var location = window.location.protocol + '//' + window.location.host + OC.webroot;
@ -336,7 +336,7 @@ OCA.Sharing.PublicApp = {
} }
}, },
_saveToNextcloud: function (remote, token, owner, ownerDisplayName, name, isProtected) { _createFederatedShare: function (remote, token, owner, ownerDisplayName, name, isProtected) {
var toggleLoading = function() { var toggleLoading = function() {
var iconClass = $('#save-button-confirm').attr('class'); var iconClass = $('#save-button-confirm').attr('class');
@ -358,13 +358,13 @@ OCA.Sharing.PublicApp = {
toggleLoading(); toggleLoading();
if (remote.indexOf('@') === -1) { if (remote.indexOf('@') === -1) {
this._legacySaveToNextcloud(remote, token, owner, ownerDisplayName, name, isProtected); this._legacyCreateFederatedShare(remote, token, owner, ownerDisplayName, name, isProtected);
toggleLoading(); toggleLoading();
return; return;
} }
$.post( $.post(
OC.generateUrl('/apps/federatedfilesharing/saveToNextcloud'), OC.generateUrl('/apps/federatedfilesharing/createFederatedShare'),
{ {
'shareWith': remote, 'shareWith': remote,
'token': token 'token': token