summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2014-05-09 17:06:08 +0200
committerBjoern Schiessle <schiessle@owncloud.com>2014-06-14 10:13:23 +0200
commitd7de35376d7e068abdfb49e8336feab25e313662 (patch)
treeb4d054593e20eb2f5396e06ef1c472337993a7c4 /apps/files_sharing
parent0156ef816650ec73d033ebba2107cf237d6301e3 (diff)
downloadnextcloud-server-d7de35376d7e068abdfb49e8336feab25e313662.tar.gz
nextcloud-server-d7de35376d7e068abdfb49e8336feab25e313662.zip
Add interface for accpeting external shares
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/ajax/external.php28
-rw-r--r--apps/files_sharing/appinfo/app.php3
-rw-r--r--apps/files_sharing/appinfo/routes.php2
-rw-r--r--apps/files_sharing/js/external.js53
-rw-r--r--apps/files_sharing/lib/external/manager.php1
5 files changed, 87 insertions, 0 deletions
diff --git a/apps/files_sharing/ajax/external.php b/apps/files_sharing/ajax/external.php
new file mode 100644
index 00000000000..e7bf903f705
--- /dev/null
+++ b/apps/files_sharing/ajax/external.php
@@ -0,0 +1,28 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+OCP\JSON::callCheck();
+OCP\JSON::checkLoggedIn();
+
+$token = $_POST['token'];
+$remote = $_POST['remote'];
+$owner = $_POST['owner'];
+$name = $_POST['name'];
+$password = $_POST['password'];
+
+$externalManager = new \OCA\Files_Sharing\External\Manager(
+ \OC::$server->getDatabaseConnection(),
+ \OC\Files\Filesystem::getMountManager(),
+ \OC\Files\Filesystem::getLoader(),
+ \OC::$server->getUserSession()
+);
+
+$mount = $externalManager->addShare($remote, $token, $password, $name, $owner);
+$result = $mount->getStorage()->file_exists('');
+
+echo json_encode($result);
diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php
index 9ea969f4cf3..db4e042faeb 100644
--- a/apps/files_sharing/appinfo/app.php
+++ b/apps/files_sharing/appinfo/app.php
@@ -23,7 +23,10 @@ $externalManager->setup();
OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup');
OCP\Share::registerBackend('file', 'OC_Share_Backend_File');
OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file');
+
OCP\Util::addScript('files_sharing', 'share');
+OCP\Util::addScript('files_sharing', 'external');
+
\OC_Hook::connect('OC_Filesystem', 'post_write', '\OC\Files\Cache\Shared_Updater', 'writeHook');
\OC_Hook::connect('OC_Filesystem', 'post_delete', '\OC\Files\Cache\Shared_Updater', 'postDeleteHook');
\OC_Hook::connect('OC_Filesystem', 'delete', '\OC\Files\Cache\Shared_Updater', 'deleteHook');
diff --git a/apps/files_sharing/appinfo/routes.php b/apps/files_sharing/appinfo/routes.php
index 7c2834dc9c2..2d214c879c4 100644
--- a/apps/files_sharing/appinfo/routes.php
+++ b/apps/files_sharing/appinfo/routes.php
@@ -5,6 +5,8 @@ $this->create('core_ajax_public_preview', '/publicpreview')->action(
require_once __DIR__ . '/../ajax/publicpreview.php';
});
+$this->create('sharing_external_add', '/external')->actionInclude('files_sharing/ajax/external.php');
+
// OCS API
//TODO: SET: mail notification, waiting for PR #4689 to be accepted
diff --git a/apps/files_sharing/js/external.js b/apps/files_sharing/js/external.js
new file mode 100644
index 00000000000..0fa99a1652b
--- /dev/null
+++ b/apps/files_sharing/js/external.js
@@ -0,0 +1,53 @@
+$(document).ready(function () {
+ var getParameterByName = function (query, name) {
+ name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
+ var regex = new RegExp("[\\#&]" + name + "=([^&#]*)"),
+ results = regex.exec(query);
+ return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
+ };
+
+ var addExternalShare = function (remote, token, owner, name, password) {
+ return $.post(OC.generateUrl('apps/files_sharing/external'), {
+ remote : remote,
+ token : token,
+ owner : owner,
+ name : name,
+ password: password
+ });
+ };
+
+ var showAddExternalDialog = function (remote, token, owner, name, passwordProtected) {
+ var remoteClean = (remote.substr(0, 8) === 'https://') ? remote.substr(8) : remote.substr(7);
+ var callback = function (add, password) {
+ password = password || '';
+ if (add) {
+ addExternalShare(remote, token, owner, name, password).then(function (result) {
+ if (result) {
+ FileList.reload();
+ } else {
+ OC.dialogs.alert('Error adding ' + name, 'Error adding share');
+ }
+ });
+ }
+ };
+ if (!passwordProtected) {
+ OC.dialogs.confirm('Add ' + name + ' from ' + owner + '@' + remoteClean, 'Add Share', callback, true);
+ } else {
+ OC.dialogs.prompt('Add ' + name + ' from ' + owner + '@' + remoteClean, 'Add Share', callback, true, 'Password', true);
+ }
+ };
+
+ if (window.FileList) {// only run in the files app
+ var hash = location.hash;
+ location.hash = '';
+ var remote = getParameterByName(hash, 'remote');
+ var owner = getParameterByName(hash, 'owner');
+ var name = getParameterByName(hash, 'name');
+ var token = getParameterByName(hash, 'token');
+ var passwordProtected = parseInt(getParameterByName(hash, 'protected'), 10);
+
+ if (remote && token && owner && name) {
+ showAddExternalDialog(remote, token, owner, name, passwordProtected);
+ }
+ }
+});
diff --git a/apps/files_sharing/lib/external/manager.php b/apps/files_sharing/lib/external/manager.php
index fa0005389a7..47fc220f7de 100644
--- a/apps/files_sharing/lib/external/manager.php
+++ b/apps/files_sharing/lib/external/manager.php
@@ -65,6 +65,7 @@ class Manager {
);
$mount = new Mount(self::STORAGE, $mountPoint, $options, $this->storageLoader);
$this->mountManager->addMount($mount);
+ return $mount;
}
}