Browse Source

move some stuff over to the federatedfilesharing app

tags/v10.0RC1
Bjoern Schiessle 8 years ago
parent
commit
5bbba490c4
No account linked to committer's email address

+ 13
- 2
apps/federatedfilesharing/appinfo/app.php View File

@@ -20,11 +20,11 @@
*
*/

$app = new \OCA\FederatedFileSharing\AppInfo\Application();

use OCA\FederatedFileSharing\Notifier;

$app = new \OCA\FederatedFileSharing\AppInfo\Application();
$l = \OC::$server->getL10N('files_sharing');
$eventDispatcher = \OC::$server->getEventDispatcher();

$app->registerSettings();

@@ -39,3 +39,14 @@ $manager->registerNotifier(function() {
'name' => $l->t('Federated sharing'),
];
});

$federatedShareProvider = $app->getFederatedShareProvider();

$eventDispatcher->addListener(
'OCA\Files::loadAdditionalScripts',
function() use ($federatedShareProvider) {
if ($federatedShareProvider->isIncomingServer2serverShareEnabled()) {
\OCP\Util::addScript('federatedfilesharing', 'external');
}
}
);

+ 1
- 0
apps/federatedfilesharing/appinfo/routes.php View File

@@ -22,5 +22,6 @@
return [
'routes' => [
['name' => 'SaveToNextcloud#saveToNextcloud', 'url' => '/saveToNextcloud', 'verb' => 'POST'],
['name' => 'SaveToNextcloud#askForFederatedShare', 'url' => '/askForFederatedShare', 'verb' => 'POST'],
]
];

apps/files_sharing/js/external.js → apps/federatedfilesharing/js/external.js View File

@@ -91,7 +91,6 @@
* through the URL
*/
processIncomingShareFromUrl: function() {
var fileList = this.filesApp.fileList;
var params = OC.Util.History.parseUrlQuery();
//manually add server-to-server share
if (params.remote && params.token && params.owner && params.name) {
@@ -99,15 +98,25 @@
var callbackAddShare = function(result, share) {
var password = share.password || '';
if (result) {
$.post(OC.generateUrl('apps/files_sharing/external'), {
remote: share.remote,
token: share.token,
owner: share.owner,
ownerDisplayName: share.ownerDisplayName || share.owner,
name: share.name,
password: password}, function(result) {
OC.Notification.showTemporary(result.data.message);
});
$.post(
OC.generateUrl('apps/federatedfilesharing/askForFederatedShare'),
{
remote: share.remote,
token: share.token,
owner: share.owner,
ownerDisplayName: share.ownerDisplayName || share.owner,
name: share.name,
password: password
}
).done(
function(data) {
OC.Notification.showTemporary(data.message);
}
).fail(
function(data) {
OC.Notification.showTemporary(JSON.parse(data.responseText).message);
}
);
}
};

@@ -161,4 +170,3 @@
})();

OC.Plugins.register('OCA.Files.App', OCA.Sharing.ExternalShareDialogPlugin);


+ 70
- 5
apps/federatedfilesharing/lib/Controller/SaveToNextcloudController.php View File

@@ -28,8 +28,11 @@ use OCA\FederatedFileSharing\FederatedShareProvider;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\Http\Client\IClientService;
use OCP\IL10N;
use OCP\IRequest;
use OCP\ISession;
use OCP\IUserSession;
use OCP\Share\IManager;

class SaveToNextcloudController extends Controller {
@@ -46,6 +49,15 @@ class SaveToNextcloudController extends Controller {
/** @var ISession */
private $session;

/** @var IL10N */
private $l;

/** @var IUserSession */
private $userSession;

/** @var IClientService */
private $clientService;

/**
* SaveToNextcloudController constructor.
*
@@ -55,13 +67,19 @@ class SaveToNextcloudController extends Controller {
* @param IManager $shareManager
* @param AddressHandler $addressHandler
* @param ISession $session
* @param IL10N $l
* @param IUserSession $userSession
* @param IClientService $clientService
*/
public function __construct($appName,
IRequest $request,
FederatedShareProvider $federatedShareProvider,
IManager $shareManager,
AddressHandler $addressHandler,
ISession $session
IRequest $request,
FederatedShareProvider $federatedShareProvider,
IManager $shareManager,
AddressHandler $addressHandler,
ISession $session,
IL10N $l,
IUserSession $userSession,
IClientService $clientService
) {
parent::__construct($appName, $request);

@@ -69,6 +87,9 @@ class SaveToNextcloudController extends Controller {
$this->shareManager = $shareManager;
$this->addressHandler = $addressHandler;
$this->session = $session;
$this->l = $l;
$this->userSession = $userSession;
$this->clientService = $clientService;
}

/**
@@ -111,4 +132,48 @@ class SaveToNextcloudController extends Controller {
return new JSONResponse(['remoteUrl' => $server]);
}

/**
* ask other server to get a federated share
*
* @NoAdminRequired
*
* @param string $token
* @param string $remote
* @param string $password
* @return JSONResponse
*/
public function askForFederatedShare($token, $remote, $password = '') {
// 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);
}

$shareWith = $this->userSession->getUser()->getUID() . '@' . $this->addressHandler->generateRemoteURL();

$httpClient = $this->clientService->newClient();

try {
$httpClient->post($remote . '/index.php/apps/federatedfilesharing/saveToNextcloud',
[
'body' =>
[
'token' => $token,
'shareWith' => rtrim($shareWith, '/'),
'password' => $password
]
]
);
} catch (\Exception $e) {
if (empty($password)) {
$message = $this->l->t("Couldn't establish a federated share.");
} else {
$message = $this->l->t("Couldn't establish a federated share, maybe the password was wrong.");
}
return new JSONResponse(['message' => $message], Http::STATUS_BAD_REQUEST);
}

return new JSONResponse(['message' => $this->l->t('Federated Share request was successful, you will receive a invitation. Check your notifications.')]);

}

}

+ 24
- 6
apps/federatedfilesharing/tests/Controller/SaveToNextcloudControllerTest.php View File

@@ -28,8 +28,11 @@ use OCA\FederatedFileSharing\Controller\SaveToNextcloudController;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCP\AppFramework\Http;
use OCP\Files\IRootFolder;
use OCP\Http\Client\IClientService;
use OCP\IL10N;
use OCP\ISession;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Share;
use OCP\Share\IManager;
use OCP\Share\IShare;
@@ -60,29 +63,44 @@ class SaveToNextcloudControllerTest extends \Test\TestCase {
/** @var ISession | \PHPUnit_Framework_MockObject_MockObject */
private $session;

/** @var IL10N | \PHPUnit_Framework_MockObject_MockObject */
private $l10n;

/** @var IUserSession | \PHPUnit_Framework_MockObject_MockObject */
private $userSession;

/** @var IClientService | \PHPUnit_Framework_MockObject_MockObject */
private $clientService;

/** @var IShare */
private $share;

public function setUp() {
parent::setUp();

$this->request = $this->getMock('OCP\IRequest');
$this->request = $this->getMockBuilder('OCP\IRequest')->disableOriginalConstructor()->getMock();
$this->federatedShareProvider = $this->getMockBuilder('OCA\FederatedFileSharing\FederatedShareProvider')
->disableOriginalConstructor()->getMock();
$this->shareManager = $this->getMock('OCP\Share\IManager');
$this->shareManager = $this->getMockBuilder('OCP\Share\IManager')->disableOriginalConstructor()->getMock();
$this->addressHandler = $this->getMockBuilder('OCA\FederatedFileSharing\AddressHandler')
->disableOriginalConstructor()->getMock();
$this->rootFolder = $this->getMock('OCP\Files\IRootFolder');
$this->userManager = $this->getMock('OCP\IUserManager');
$this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')->disableOriginalConstructor()->getMock();
$this->userManager = $this->getMockBuilder('OCP\IUserManager')->disableOriginalConstructor()->getMock();
$this->share = new \OC\Share20\Share($this->rootFolder, $this->userManager);
$this->session = $this->getMock('OCP\ISession');
$this->session = $this->getMockBuilder('OCP\ISession')->disableOriginalConstructor()->getMock();
$this->l10n = $this->getMockBuilder('OCP\IL10N')->disableOriginalConstructor()->getMock();
$this->userSession = $this->getMockBuilder('OCP\IUserSession')->disableOriginalConstructor()->getMock();
$this->clientService = $this->getMockBuilder('OCP\Http\Client\IClientService')->disableOriginalConstructor()->getMock();

$this->controller = new SaveToNextcloudController(
'federatedfilesharing', $this->request,
$this->federatedShareProvider,
$this->shareManager,
$this->addressHandler,
$this->session
$this->session,
$this->l10n,
$this->userSession,
$this->clientService
);
}


apps/files_sharing/tests/js/externalSpec.js → apps/federatedfilesharing/tests/js/externalSpec.js View File


+ 0
- 74
apps/files_sharing/ajax/external.php View File

@@ -1,74 +0,0 @@
<?php
/**
* @author Björn Schießle <bjoern@schiessle.org>
* @author Joas Schilling <nickvergessen@owncloud.com>
* @author Lukas Reschke <lukas@statuscode.ch>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin Appelman <icewind@owncloud.com>
* @author Roeland Jago Douma <rullzer@owncloud.com>
* @author Vincent Petry <pvince81@owncloud.com>
*
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

OCP\JSON::callCheck();
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('files_sharing');

$l = \OC::$server->getL10N('files_sharing');

$federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application('federatedfilesharing');
$federatedShareProvider = $federatedSharingApp->getFederatedShareProvider();

// check if server admin allows to mount public links from other servers
if ($federatedShareProvider->isIncomingServer2serverShareEnabled() === false) {
\OCP\JSON::error(array('data' => array('message' => $l->t('Server to server sharing is not enabled on this server'))));
exit();
}

$token = $_POST['token'];
$remote = $_POST['remote'];
$password = isset($_POST['password']) ? $_POST['password'] : '';

$urlGenerator = \OC::$server->getURLGenerator();

$shareWith = \OCP\User::getUser() . '@' . $urlGenerator->getAbsoluteURL('/');

$httpClient = \OC::$server->getHTTPClientService()->newClient();

try {
$response = $httpClient->post($remote . '/index.php/apps/federatedfilesharing/saveToNextcloud',
[
'body' =>
[
'token' => $token,
'shareWith' => rtrim($shareWith, '/'),
'password' => $password
]
]
);
} catch (\Exception $e) {
if (empty($password)) {
$message = $l->t("Couldn't establish a federated share.");
} else {
$message = $l->t("Couldn't establish a federated share, maybe the password was wrong.");
}
\OCP\JSON::error(array('data' => array('message' => $message)));
exit();
}

\OCP\JSON::success(array('data' => array('message' => $l->t('Federated Share request was successful, you will receive a invitation. Check your notifications.'))));

+ 0
- 3
apps/files_sharing/appinfo/app.php View File

@@ -46,9 +46,6 @@ $eventDispatcher->addListener(
function() {
\OCP\Util::addScript('files_sharing', 'share');
\OCP\Util::addScript('files_sharing', 'sharetabview');
if (\OC::$server->getConfig()->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes') {
\OCP\Util::addScript('files_sharing', 'external');
}
\OCP\Util::addStyle('files_sharing', 'sharetabview');
}
);

+ 0
- 2
apps/files_sharing/appinfo/routes.php View File

@@ -53,8 +53,6 @@ $this->create('files_sharing_ajax_publicpreview', 'ajax/publicpreview.php')
->actionInclude('files_sharing/ajax/publicpreview.php');
$this->create('sharing_external_shareinfo', '/shareinfo')
->actionInclude('files_sharing/ajax/shareinfo.php');
$this->create('sharing_external_add', '/external')
->actionInclude('files_sharing/ajax/external.php');

// OCS API


+ 1
- 3
apps/files_sharing/js/public.js View File

@@ -356,7 +356,7 @@ OCA.Sharing.PublicApp = {

toggleLoading();

if (remote.indexOf('@') == -1) {
if (remote.indexOf('@') === -1) {
this._legacySaveToNextcloud(remote, token, owner, ownerDisplayName, name, isProtected);
toggleLoading();
return;
@@ -380,8 +380,6 @@ OCA.Sharing.PublicApp = {
}
).fail(
function (jqXHR) {
console.log("ERROR!");
console.log(jqXHR);
OC.dialogs.alert(JSON.parse(jqXHR.responseText).message,
t('files_sharing', 'Failed to add the public link to your Nextcloud'));
toggleLoading();

Loading…
Cancel
Save