diff --git a/apps/federatedfilesharing/appinfo/app.php b/apps/federatedfilesharing/appinfo/app.php
index 5891b9cbbc..8abdf8cac1 100644
--- a/apps/federatedfilesharing/appinfo/app.php
+++ b/apps/federatedfilesharing/appinfo/app.php
@@ -20,7 +20,7 @@
*
*/
-$app = new \OCA\FederatedFileSharing\AppInfo\Application('federatedfilesharing');
+$app = new \OCA\FederatedFileSharing\AppInfo\Application();
use OCA\FederatedFileSharing\Notifier;
diff --git a/apps/federatedfilesharing/appinfo/routes.php b/apps/federatedfilesharing/appinfo/routes.php
new file mode 100644
index 0000000000..534733e001
--- /dev/null
+++ b/apps/federatedfilesharing/appinfo/routes.php
@@ -0,0 +1,26 @@
+
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see .
+ *
+ */
+
+return [
+ 'routes' => [
+ ['name' => 'SaveToOwnCloud#saveToOwnCloud', 'url' => '/saveToOwnCloud', 'verb' => 'POST'],
+ ]
+];
diff --git a/apps/federatedfilesharing/lib/AppInfo/Application.php b/apps/federatedfilesharing/lib/AppInfo/Application.php
index 4faebea7b0..ea5018e6a9 100644
--- a/apps/federatedfilesharing/lib/AppInfo/Application.php
+++ b/apps/federatedfilesharing/lib/AppInfo/Application.php
@@ -31,6 +31,10 @@ class Application extends App {
/** @var FederatedShareProvider */
protected $federatedShareProvider;
+ public function __construct() {
+ parent::__construct('federatedfilesharing');
+ }
+
/**
* register personal and admin settings page
*/
diff --git a/apps/federatedfilesharing/lib/Controller/SaveToOwnCloudController.php b/apps/federatedfilesharing/lib/Controller/SaveToOwnCloudController.php
new file mode 100644
index 0000000000..a20806e6ab
--- /dev/null
+++ b/apps/federatedfilesharing/lib/Controller/SaveToOwnCloudController.php
@@ -0,0 +1,88 @@
+
+ *
+ * @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
+ *
+ */
+
+
+namespace OCA\FederatedFileSharing\Controller;
+
+use OC\HintException;
+use OCA\FederatedFileSharing\AddressHandler;
+use OCA\FederatedFileSharing\FederatedShareProvider;
+use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\JSONResponse;
+use OCP\IRequest;
+use OCP\Share\IManager;
+
+class SaveToOwnCloudController extends Controller {
+
+ /** @var FederatedShareProvider */
+ private $federatedShareProvider;
+
+ /** @var AddressHandler */
+ private $addressHandler;
+
+ /** @var IManager */
+ private $shareManager;
+
+ public function __construct($appName,
+ IRequest $request,
+ FederatedShareProvider $federatedShareProvider,
+ IManager $shareManager,
+ AddressHandler $addressHandler) {
+ parent::__construct($appName, $request);
+
+ $this->federatedShareProvider = $federatedShareProvider;
+ $this->shareManager = $shareManager;
+ $this->addressHandler = $addressHandler;
+ }
+
+ /**
+ * save public link to my ownCloud by asking the owner to create a federated
+ * share with me
+ *
+ * @NoCSRFRequired
+ * @PublicPage
+ *
+ * @param string $shareWith
+ * @param string $token
+ * @return JSONResponse
+ */
+ public function saveToOwnCloud($shareWith, $token) {
+
+ try {
+ list(, $server) = $this->addressHandler->splitUserRemote($shareWith);
+ $share = $this->shareManager->getShareByToken($token);
+ } catch (HintException $e) {
+ return new JSONResponse(['message' => $e->getHint()], Http::STATUS_BAD_REQUEST);
+ }
+
+ $share->setSharedWith($shareWith);
+
+ try {
+ $this->federatedShareProvider->create($share);
+ } catch (\Exception $e) {
+ return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
+ }
+
+ return new JSONResponse(['remoteUrl' => $server]);
+ }
+
+}
diff --git a/apps/federatedfilesharing/lib/FederatedShareProvider.php b/apps/federatedfilesharing/lib/FederatedShareProvider.php
index 1ea31f2dbc..7b64b56a16 100644
--- a/apps/federatedfilesharing/lib/FederatedShareProvider.php
+++ b/apps/federatedfilesharing/lib/FederatedShareProvider.php
@@ -135,7 +135,7 @@ class FederatedShareProvider implements IShareProvider {
$itemType = $share->getNodeType();
$permissions = $share->getPermissions();
$sharedBy = $share->getSharedBy();
-
+
/*
* Check if file is not already shared with the remote user
*/
@@ -626,7 +626,7 @@ class FederatedShareProvider implements IShareProvider {
->from('share')
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)));
-
+
$cursor = $qb->execute();
$data = $cursor->fetch();
$cursor->closeCursor();
@@ -727,13 +727,13 @@ class FederatedShareProvider implements IShareProvider {
$data = $cursor->fetch();
if ($data === false) {
- throw new ShareNotFound();
+ throw new ShareNotFound('Share not found', $this->l->t('Could not find share'));
}
try {
$share = $this->createShareObject($data);
} catch (InvalidShare $e) {
- throw new ShareNotFound();
+ throw new ShareNotFound('Share not found', $this->l->t('Could not find share'));
}
return $share;
diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js
index 3befeaeda1..38dc40eeb1 100644
--- a/apps/files_sharing/js/public.js
+++ b/apps/files_sharing/js/public.js
@@ -244,10 +244,8 @@ OCA.Sharing.PublicApp = {
var remote = $(this).find('input[type="text"]').val();
var token = $('#sharingToken').val();
var owner = $('#save').data('owner');
- var ownerDisplayName = $('#save').data('owner-display-name');
var name = $('#save').data('name');
- var isProtected = $('#save').data('protected') ? 1 : 0;
- OCA.Sharing.PublicApp._saveToOwnCloud(remote, token, owner, ownerDisplayName, name, isProtected);
+ OCA.Sharing.PublicApp._saveToOwnCloud(remote, token);
});
$('#remote_address').on("keyup paste", function() {
@@ -294,50 +292,43 @@ OCA.Sharing.PublicApp = {
this.fileList.changeDirectory(params.path || params.dir, false, true);
},
- _saveToOwnCloud: function (remote, token, owner, ownerDisplayName, name, isProtected) {
- var toggleLoading = function() {
- var iconClass = $('#save-button-confirm').attr('class');
- var loading = iconClass.indexOf('icon-loading-small') !== -1;
- if(loading) {
- $('#save-button-confirm')
- .removeClass("icon-loading-small")
- .addClass("icon-confirm");
+ _saveToOwnCloud: function (remote, token) {
+
+ $.post(
+ OC.generateUrl('/apps/federatedfilesharing/saveToOwnCloud'),
+ {
+ 'shareWith': remote,
+ 'token': token
}
- else {
- $('#save-button-confirm')
- .removeClass("icon-confirm")
- .addClass("icon-loading-small");
+ ).done(
+ function (data) {
+ var url = data.remoteUrl;
- }
- };
-
- toggleLoading();
- var location = window.location.protocol + '//' + window.location.host + OC.webroot;
-
- if(remote.substr(-1) !== '/') {
- remote += '/'
- };
-
- var url = remote + 'index.php/apps/files#' + 'remote=' + encodeURIComponent(location) // our location is the remote for the other server
- + "&token=" + encodeURIComponent(token) + "&owner=" + encodeURIComponent(owner) +"&ownerDisplayName=" + encodeURIComponent(ownerDisplayName) + "&name=" + encodeURIComponent(name) + "&protected=" + isProtected;
-
-
- if (remote.indexOf('://') > 0) {
- OC.redirect(url);
- } else {
- // if no protocol is specified, we automatically detect it by testing https and http
- // this check needs to happen on the server due to the Content Security Policy directive
- $.get(OC.generateUrl('apps/files_sharing/testremote'), {remote: remote}).then(function (protocol) {
- if (protocol !== 'http' && protocol !== 'https') {
- toggleLoading();
- OC.dialogs.alert(t('files_sharing', 'No compatible server found at {remote}', {remote: remote}),
- t('files_sharing', 'Invalid server URL'));
+ if (url.indexOf('://') > 0) {
+ OC.redirect(url);
} else {
- OC.redirect(protocol + '://' + url);
+ // if no protocol is specified, we automatically detect it by testing https and http
+ // this check needs to happen on the server due to the Content Security Policy directive
+ $.get(OC.generateUrl('apps/files_sharing/testremote'), {remote: remote}).then(function (protocol) {
+ if (protocol !== 'http' && protocol !== 'https') {
+ toggleLoading();
+ OC.dialogs.alert(t('files_sharing', 'No ownCloud installation (7 or higher) found at {remote}', {remote: remote}),
+ t('files_sharing', 'Invalid ownCloud url'));
+ } else {
+ OC.redirect(protocol + '://' + url);
+ }
+ });
}
- });
- }
+ }
+ ).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 ownCloud'));
+ }
+ );
}
};
diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php
index c15001ad24..8b8267a4e3 100644
--- a/apps/files_sharing/templates/public.php
+++ b/apps/files_sharing/templates/public.php
@@ -84,7 +84,7 @@ $maxUploadFilesize = min($upload_max_filesize, $post_max_size);
data-owner-display-name="" data-owner="" data-name="">