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 [
'routes' => [
['name' => 'SaveToNextcloud#saveToNextcloud', 'url' => '/saveToNextcloud', 'verb' => 'POST'],
['name' => 'SaveToNextcloud#askForFederatedShare', 'url' => '/askForFederatedShare', 'verb' => 'POST'],
['name' => 'MountPublicLink#createFederatedShare', 'url' => '/createFederatedShare', 'verb' => 'POST'],
['name' => 'MountPublicLink#askForFederatedShare', 'url' => '/askForFederatedShare', 'verb' => 'POST'],
]
];

View File

@ -37,7 +37,14 @@ use OCP\ISession;
use OCP\IUserSession;
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 */
private $federatedShareProvider;
@ -61,7 +68,7 @@ class SaveToNextcloudController extends Controller {
private $clientService;
/**
* SaveToNextcloudController constructor.
* MountPublicLinkController constructor.
*
* @param string $appName
* @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
* share with me
* send federated share to a user of a public link
*
* @NoCSRFRequired
* @PublicPage
@ -106,7 +112,7 @@ class SaveToNextcloudController extends Controller {
* @param string $password
* @return JSONResponse
*/
public function saveToNextcloud($shareWith, $token, $password = '') {
public function createFederatedShare($shareWith, $token, $password = '') {
try {
list(, $server) = $this->addressHandler->splitUserRemote($shareWith);
@ -147,7 +153,7 @@ class SaveToNextcloudController extends Controller {
* @param string $name (only for legacy reasons, can be removed with legacyMountPublicLink())
* @return JSONResponse
*/
public function askForFederatedShare($token, $remote, $password = '', $owner='', $ownerDisplayName = '', $name = '') {
public function askForFederatedShare($token, $remote, $password = '', $owner = '', $ownerDisplayName = '', $name = '') {
// check if server admin allows to mount public links from other servers
if ($this->federatedShareProvider->isIncomingServer2serverShareEnabled() === false) {
return new JSONResponse(['message' => $this->l->t('Server to server sharing is not enabled on this server')], Http::STATUS_BAD_REQUEST);
@ -158,14 +164,15 @@ class SaveToNextcloudController extends Controller {
$httpClient = $this->clientService->newClient();
try {
$response = $httpClient->post($remote . '/index.php/apps/federatedfilesharing/saveToNextcloud',
$response = $httpClient->post($remote . '/index.php/apps/federatedfilesharing/createFederatedShare',
[
'body' =>
[
'token' => $token,
'shareWith' => rtrim($shareWith, '/'),
'password' => $password
]
],
'connect_timeout' => 10,
]
);
} catch (\Exception $e) {

View File

@ -4,7 +4,7 @@
*
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @copyright Copyright (c) 2016, Björn Schießle <bjoern@schiessle.org>
*
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
@ -26,7 +26,7 @@ namespace OCA\FederatedFileSharing\Tests\Controller;
use OC\HintException;
use OCA\FederatedFileSharing\AddressHandler;
use OCA\FederatedFileSharing\Controller\SaveToNextcloudController;
use OCA\FederatedFileSharing\Controller\MountPublicLinkController;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCP\AppFramework\Http;
use OCP\Files\IRootFolder;
@ -35,13 +35,12 @@ use OCP\IL10N;
use OCP\ISession;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Share;
use OCP\Share\IManager;
use OCP\Share\IShare;
class SaveToNextcloudControllerTest extends \Test\TestCase {
class MountPublicLinkControllerTest extends \Test\TestCase {
/** @var SaveToNextcloudController */
/** @var MountPublicLinkController */
private $controller;
/** @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->clientService = $this->getMockBuilder('OCP\Http\Client\IClientService')->disableOriginalConstructor()->getMock();
$this->controller = new SaveToNextcloudController(
$this->controller = new MountPublicLinkController(
'federatedfilesharing', $this->request,
$this->federatedShareProvider,
$this->shareManager,
@ -107,7 +106,7 @@ class SaveToNextcloudControllerTest extends \Test\TestCase {
}
/**
* @dataProvider dataTestSaveToNextcloud
* @dataProvider dataTestCreateFederatedShare
*
* @param string $shareWith
* @param bool $validShareWith
@ -116,7 +115,7 @@ class SaveToNextcloudControllerTest extends \Test\TestCase {
* @param bool $createSuccessful
* @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')
->with($shareWith)
->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;
@ -170,7 +169,7 @@ class SaveToNextcloudControllerTest extends \Test\TestCase {
}
public function dataTestSaveToNextcloud() {
public function dataTestCreateFederatedShare() {
return [
//shareWith, validShareWith, token, validToken, createSuccessful, expectedReturnData
['user@server', true, 'token', true, true, 'server'],

View File

@ -248,7 +248,7 @@ OCA.Sharing.PublicApp = {
var ownerDisplayName = $('#save').data('owner-display-name');
var name = $('#save').data('name');
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() {
@ -308,7 +308,7 @@ OCA.Sharing.PublicApp = {
* @param isProtected
* @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;
@ -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 iconClass = $('#save-button-confirm').attr('class');
@ -358,13 +358,13 @@ OCA.Sharing.PublicApp = {
toggleLoading();
if (remote.indexOf('@') === -1) {
this._legacySaveToNextcloud(remote, token, owner, ownerDisplayName, name, isProtected);
this._legacyCreateFederatedShare(remote, token, owner, ownerDisplayName, name, isProtected);
toggleLoading();
return;
}
$.post(
OC.generateUrl('/apps/federatedfilesharing/saveToNextcloud'),
OC.generateUrl('/apps/federatedfilesharing/createFederatedShare'),
{
'shareWith': remote,
'token': token