2015-06-01 16:05:04 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-22 10:45:36 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2016-07-22 10:45:36 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2015-06-01 16:05:04 +03:00
|
|
|
*
|
|
|
|
* @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/>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Files_Sharing\API;
|
|
|
|
|
|
|
|
use OC\Files\Filesystem;
|
2016-02-25 22:46:01 +03:00
|
|
|
use OCA\FederatedFileSharing\DiscoveryManager;
|
2015-06-01 16:05:04 +03:00
|
|
|
use OCA\Files_Sharing\External\Manager;
|
|
|
|
|
|
|
|
class Remote {
|
|
|
|
|
|
|
|
/**
|
2015-09-26 10:55:59 +03:00
|
|
|
* Get list of pending remote shares
|
2015-06-01 16:05:04 +03:00
|
|
|
*
|
2015-09-26 10:55:59 +03:00
|
|
|
* @param array $params empty
|
2015-06-01 16:05:04 +03:00
|
|
|
* @return \OC_OCS_Result
|
|
|
|
*/
|
|
|
|
public static function getOpenShares($params) {
|
2016-02-25 22:46:01 +03:00
|
|
|
$discoveryManager = new DiscoveryManager(
|
|
|
|
\OC::$server->getMemCacheFactory(),
|
|
|
|
\OC::$server->getHTTPClientService()
|
|
|
|
);
|
2015-06-01 16:05:04 +03:00
|
|
|
$externalManager = new Manager(
|
|
|
|
\OC::$server->getDatabaseConnection(),
|
|
|
|
Filesystem::getMountManager(),
|
|
|
|
Filesystem::getLoader(),
|
|
|
|
\OC::$server->getHTTPHelper(),
|
2015-09-01 19:56:09 +03:00
|
|
|
\OC::$server->getNotificationManager(),
|
2016-02-25 22:46:01 +03:00
|
|
|
$discoveryManager,
|
2015-06-01 16:05:04 +03:00
|
|
|
\OC_User::getUser()
|
|
|
|
);
|
|
|
|
|
|
|
|
return new \OC_OCS_Result($externalManager->getOpenShares());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Accept a remote share
|
|
|
|
*
|
|
|
|
* @param array $params contains the shareID 'id' which should be accepted
|
|
|
|
* @return \OC_OCS_Result
|
|
|
|
*/
|
|
|
|
public static function acceptShare($params) {
|
2016-02-25 22:46:01 +03:00
|
|
|
$discoveryManager = new DiscoveryManager(
|
|
|
|
\OC::$server->getMemCacheFactory(),
|
|
|
|
\OC::$server->getHTTPClientService()
|
|
|
|
);
|
2015-06-01 16:05:04 +03:00
|
|
|
$externalManager = new Manager(
|
|
|
|
\OC::$server->getDatabaseConnection(),
|
|
|
|
Filesystem::getMountManager(),
|
|
|
|
Filesystem::getLoader(),
|
|
|
|
\OC::$server->getHTTPHelper(),
|
2015-09-01 19:56:09 +03:00
|
|
|
\OC::$server->getNotificationManager(),
|
2016-02-25 22:46:01 +03:00
|
|
|
$discoveryManager,
|
2015-06-01 16:05:04 +03:00
|
|
|
\OC_User::getUser()
|
|
|
|
);
|
|
|
|
|
2016-02-09 18:32:59 +03:00
|
|
|
if ($externalManager->acceptShare((int) $params['id'])) {
|
2015-06-01 16:05:04 +03:00
|
|
|
return new \OC_OCS_Result();
|
|
|
|
}
|
|
|
|
|
2016-02-11 12:11:42 +03:00
|
|
|
// Make sure the user has no notification for something that does not exist anymore.
|
|
|
|
$externalManager->processNotification((int) $params['id']);
|
|
|
|
|
2015-06-01 16:05:04 +03:00
|
|
|
return new \OC_OCS_Result(null, 404, "wrong share ID, share doesn't exist.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decline a remote share
|
|
|
|
*
|
|
|
|
* @param array $params contains the shareID 'id' which should be declined
|
|
|
|
* @return \OC_OCS_Result
|
|
|
|
*/
|
|
|
|
public static function declineShare($params) {
|
2016-02-25 22:46:01 +03:00
|
|
|
$discoveryManager = new DiscoveryManager(
|
|
|
|
\OC::$server->getMemCacheFactory(),
|
|
|
|
\OC::$server->getHTTPClientService()
|
|
|
|
);
|
2015-06-01 16:05:04 +03:00
|
|
|
$externalManager = new Manager(
|
|
|
|
\OC::$server->getDatabaseConnection(),
|
|
|
|
Filesystem::getMountManager(),
|
|
|
|
Filesystem::getLoader(),
|
|
|
|
\OC::$server->getHTTPHelper(),
|
2015-09-01 19:56:09 +03:00
|
|
|
\OC::$server->getNotificationManager(),
|
2016-02-25 22:46:01 +03:00
|
|
|
$discoveryManager,
|
2015-06-01 16:05:04 +03:00
|
|
|
\OC_User::getUser()
|
|
|
|
);
|
|
|
|
|
2016-02-09 18:32:59 +03:00
|
|
|
if ($externalManager->declineShare((int) $params['id'])) {
|
2015-06-01 16:05:04 +03:00
|
|
|
return new \OC_OCS_Result();
|
|
|
|
}
|
|
|
|
|
2016-02-11 12:11:42 +03:00
|
|
|
// Make sure the user has no notification for something that does not exist anymore.
|
|
|
|
$externalManager->processNotification((int) $params['id']);
|
|
|
|
|
2015-06-01 16:05:04 +03:00
|
|
|
return new \OC_OCS_Result(null, 404, "wrong share ID, share doesn't exist.");
|
|
|
|
}
|
2015-09-26 10:55:59 +03:00
|
|
|
|
2015-10-01 16:41:24 +03:00
|
|
|
/**
|
|
|
|
* @param array $share Share with info from the share_external table
|
2016-02-11 12:11:42 +03:00
|
|
|
* @return array enriched share info with data from the filecache
|
2015-10-01 16:41:24 +03:00
|
|
|
*/
|
|
|
|
private static function extendShareInfo($share) {
|
|
|
|
$view = new \OC\Files\View('/' . \OC_User::getUser() . '/files/');
|
2015-11-19 00:28:48 +03:00
|
|
|
$info = $view->getFileInfo($share['mountpoint']);
|
2015-10-01 16:41:24 +03:00
|
|
|
|
|
|
|
$share['mimetype'] = $info->getMimetype();
|
|
|
|
$share['mtime'] = $info->getMtime();
|
|
|
|
$share['permissions'] = $info->getPermissions();
|
|
|
|
$share['type'] = $info->getType();
|
|
|
|
$share['file_id'] = $info->getId();
|
|
|
|
|
|
|
|
return $share;
|
|
|
|
}
|
|
|
|
|
2015-09-26 10:55:59 +03:00
|
|
|
/**
|
|
|
|
* List accepted remote shares
|
|
|
|
*
|
|
|
|
* @param array $params
|
|
|
|
* @return \OC_OCS_Result
|
|
|
|
*/
|
|
|
|
public static function getShares($params) {
|
2016-02-25 22:46:01 +03:00
|
|
|
$discoveryManager = new DiscoveryManager(
|
|
|
|
\OC::$server->getMemCacheFactory(),
|
|
|
|
\OC::$server->getHTTPClientService()
|
|
|
|
);
|
2015-09-26 10:55:59 +03:00
|
|
|
$externalManager = new Manager(
|
|
|
|
\OC::$server->getDatabaseConnection(),
|
|
|
|
Filesystem::getMountManager(),
|
|
|
|
Filesystem::getLoader(),
|
|
|
|
\OC::$server->getHTTPHelper(),
|
|
|
|
\OC::$server->getNotificationManager(),
|
2016-02-25 22:46:01 +03:00
|
|
|
$discoveryManager,
|
2015-09-26 10:55:59 +03:00
|
|
|
\OC_User::getUser()
|
|
|
|
);
|
2015-10-01 16:41:24 +03:00
|
|
|
|
|
|
|
$shares = $externalManager->getAcceptedShares();
|
|
|
|
|
|
|
|
$shares = array_map('self::extendShareInfo', $shares);
|
2015-09-26 10:55:59 +03:00
|
|
|
|
2015-10-01 16:41:24 +03:00
|
|
|
return new \OC_OCS_Result($shares);
|
2015-09-26 10:55:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get info of a remote share
|
|
|
|
*
|
|
|
|
* @param array $params contains the shareID 'id'
|
|
|
|
* @return \OC_OCS_Result
|
|
|
|
*/
|
|
|
|
public static function getShare($params) {
|
2016-02-25 22:46:01 +03:00
|
|
|
$discoveryManager = new DiscoveryManager(
|
|
|
|
\OC::$server->getMemCacheFactory(),
|
|
|
|
\OC::$server->getHTTPClientService()
|
|
|
|
);
|
2015-09-26 10:55:59 +03:00
|
|
|
$externalManager = new Manager(
|
|
|
|
\OC::$server->getDatabaseConnection(),
|
|
|
|
Filesystem::getMountManager(),
|
|
|
|
Filesystem::getLoader(),
|
|
|
|
\OC::$server->getHTTPHelper(),
|
|
|
|
\OC::$server->getNotificationManager(),
|
2016-02-25 22:46:01 +03:00
|
|
|
$discoveryManager,
|
2015-09-26 10:55:59 +03:00
|
|
|
\OC_User::getUser()
|
|
|
|
);
|
|
|
|
|
|
|
|
$shareInfo = $externalManager->getShare($params['id']);
|
|
|
|
|
|
|
|
if ($shareInfo === false) {
|
|
|
|
return new \OC_OCS_Result(null, 404, 'share does not exist');
|
|
|
|
} else {
|
2015-10-01 16:41:24 +03:00
|
|
|
$shareInfo = self::extendShareInfo($shareInfo);
|
2015-09-26 10:55:59 +03:00
|
|
|
return new \OC_OCS_Result($shareInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unshare a remote share
|
|
|
|
*
|
|
|
|
* @param array $params contains the shareID 'id' which should be unshared
|
|
|
|
* @return \OC_OCS_Result
|
|
|
|
*/
|
|
|
|
public static function unshare($params) {
|
2016-02-25 22:46:01 +03:00
|
|
|
$discoveryManager = new DiscoveryManager(
|
|
|
|
\OC::$server->getMemCacheFactory(),
|
|
|
|
\OC::$server->getHTTPClientService()
|
|
|
|
);
|
2015-09-26 10:55:59 +03:00
|
|
|
$externalManager = new Manager(
|
|
|
|
\OC::$server->getDatabaseConnection(),
|
|
|
|
Filesystem::getMountManager(),
|
|
|
|
Filesystem::getLoader(),
|
|
|
|
\OC::$server->getHTTPHelper(),
|
|
|
|
\OC::$server->getNotificationManager(),
|
2016-02-25 22:46:01 +03:00
|
|
|
$discoveryManager,
|
2015-09-26 10:55:59 +03:00
|
|
|
\OC_User::getUser()
|
|
|
|
);
|
|
|
|
|
|
|
|
$shareInfo = $externalManager->getShare($params['id']);
|
|
|
|
|
|
|
|
if ($shareInfo === false) {
|
|
|
|
return new \OC_OCS_Result(null, 404, 'Share does not exist');
|
|
|
|
}
|
|
|
|
|
|
|
|
$mountPoint = '/' . \OC_User::getUser() . '/files' . $shareInfo['mountpoint'];
|
|
|
|
|
|
|
|
if ($externalManager->removeShare($mountPoint) === true) {
|
|
|
|
return new \OC_OCS_Result(null);
|
|
|
|
} else {
|
|
|
|
return new \OC_OCS_Result(null, 403, 'Could not unshare');
|
|
|
|
}
|
|
|
|
}
|
2015-06-01 16:05:04 +03:00
|
|
|
}
|