Skip to content

Commit

Permalink
rename SaveToNextcloudController to MountPublicLinkController
Browse files Browse the repository at this point in the history
  • Loading branch information
schiessle committed Jul 14, 2016
1 parent 51a1418 commit 03f2e5e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
4 changes: 2 additions & 2 deletions apps/federatedfilesharing/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
]
];
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@
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;
Expand All @@ -61,7 +68,7 @@ class SaveToNextcloudController extends Controller {
private $clientService;

/**
* SaveToNextcloudController constructor.
* MountPublicLinkController constructor.
*
* @param string $appName
* @param IRequest $request
Expand Down Expand Up @@ -95,8 +102,7 @@ public function __construct($appName,
}

/**
* 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
Expand All @@ -106,7 +112,7 @@ public function __construct($appName,
* @param string $password
* @return JSONResponse
*/
public function saveToNextcloud($shareWith, $token, $password = '') {
public function createFederatedShare($shareWith, $token, $password = '') {

try {
list(, $server) = $this->addressHandler->splitUserRemote($shareWith);
Expand Down Expand Up @@ -147,7 +153,7 @@ public function saveToNextcloud($shareWith, $token, $password = '') {
* @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);
Expand All @@ -158,14 +164,15 @@ public function askForFederatedShare($token, $remote, $password = '', $owner='',
$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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @copyright Copyright (c) 2016, Björn Schießle <[email protected]>
*
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
Expand All @@ -26,7 +26,7 @@

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;
Expand All @@ -35,13 +35,12 @@
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 */
Expand Down Expand Up @@ -94,7 +93,7 @@ public function setUp() {
$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,
Expand All @@ -107,7 +106,7 @@ public function setUp() {
}

/**
* @dataProvider dataTestSaveToNextcloud
* @dataProvider dataTestCreateFederatedShare
*
* @param string $shareWith
* @param bool $validShareWith
Expand All @@ -116,7 +115,7 @@ public function setUp() {
* @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(
Expand Down Expand Up @@ -153,7 +152,7 @@ function (IShare $share) use ($createSuccessful, $shareWith, $expectedReturnData
}
);

$result = $this->controller->saveToNextcloud($shareWith, $token);
$result = $this->controller->createFederatedShare($shareWith, $token);

$errorCase = !$validShareWith || !$validToken || !$createSuccessful;

Expand All @@ -170,7 +169,7 @@ function (IShare $share) use ($createSuccessful, $shareWith, $expectedReturnData

}

public function dataTestSaveToNextcloud() {
public function dataTestCreateFederatedShare() {
return [
//shareWith, validShareWith, token, validToken, createSuccessful, expectedReturnData
['user@server', true, 'token', true, true, 'server'],
Expand Down
10 changes: 5 additions & 5 deletions apps/files_sharing/js/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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');
Expand All @@ -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
Expand Down

0 comments on commit 03f2e5e

Please sign in to comment.