diff --git a/apps/federatedfilesharing/appinfo/app.php b/apps/federatedfilesharing/appinfo/app.php index 885b2be699cc..644a9c0dbbac 100644 --- a/apps/federatedfilesharing/appinfo/app.php +++ b/apps/federatedfilesharing/appinfo/app.php @@ -2,6 +2,7 @@ /** * @author Björn Schießle * @author Joas Schilling + * @author Jörn Friedrich Dreyer * * @copyright Copyright (c) 2017, ownCloud GmbH * @license AGPL-3.0 @@ -23,6 +24,8 @@ $app = new \OCA\FederatedFileSharing\AppInfo\Application('federatedfilesharing'); use OCA\FederatedFileSharing\Notifier; +use OCP\Share\Events\AcceptShare; +use OCP\Share\Events\DeclineShare; $manager = \OC::$server->getNotificationManager(); $manager->registerNotifier(function() { @@ -36,3 +39,36 @@ 'name' => $l->t('Federated sharing'), ]; }); + +// add 'Add to your ownCloud' button to public pages +// FIXME the OCA\Files::loadAdditionalScripts event is only fired by the ViewController of the files app ... but we are nowadays using webdav. +// FIXME versions, comments, tags and sharing ui still uses it https://github.com/owncloud/core/search?utf8=%E2%9C%93&q=loadAdditionalScripts&type= +OCP\Util::connectHook('OCP\Share', 'share_link_access', 'OCA\FederatedFileSharing\HookHandler', 'loadPublicJS'); + +// react to accept and decline share events +$eventDispatcher = \OC::$server->getEventDispatcher(); +$eventDispatcher->addListener( + AcceptShare::class, + function(AcceptShare $event) use ($app) { + /** @var \OCA\FederatedFileSharing\Notifications $notifications */ + $notifications = $app->getContainer()->query('OCA\FederatedFileSharing\Notifications'); + $notifications->sendAcceptShare( + $event->getRemote(), + $event->getRemoteId(), + $event->getShareToken() + ); + } +); + +$eventDispatcher->addListener( + DeclineShare::class, + function(DeclineShare $event) use ($app) { + /** @var \OCA\FederatedFileSharing\Notifications $notifications */ + $notifications = $app->getContainer()->query('OCA\FederatedFileSharing\Notifications'); + $notifications->sendDeclineShare( + $event->getRemote(), + $event->getRemoteId(), + $event->getShareToken() + ); + } +); diff --git a/apps/federatedfilesharing/appinfo/info.xml b/apps/federatedfilesharing/appinfo/info.xml index db92e77c0294..d8e59212e01a 100644 --- a/apps/federatedfilesharing/appinfo/info.xml +++ b/apps/federatedfilesharing/appinfo/info.xml @@ -9,6 +9,9 @@ FederatedFileSharing true other + + + diff --git a/apps/federatedfilesharing/js/public.js b/apps/federatedfilesharing/js/public.js new file mode 100644 index 000000000000..9959c5536288 --- /dev/null +++ b/apps/federatedfilesharing/js/public.js @@ -0,0 +1,10 @@ +$(document).ready(function() { + $('#header #details').prepend( + '' + + ' ' + + ' ' + + ''); +}); diff --git a/apps/federatedfilesharing/lib/HookHandler.php b/apps/federatedfilesharing/lib/HookHandler.php new file mode 100644 index 000000000000..30f41ef51967 --- /dev/null +++ b/apps/federatedfilesharing/lib/HookHandler.php @@ -0,0 +1,37 @@ + + * + * @copyright Copyright (c) 2017, ownCloud GmbH + * @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; + +/** + * Class HookHandler + * + * handles hooks + * + * @package OCA\FederatedFileSharing + */ +class HookHandler { + + public static function loadPublicJS () { + \OCP\Util::addScript('federatedfilesharing', 'public'); + } + +} diff --git a/apps/federatedfilesharing/lib/Notifications.php b/apps/federatedfilesharing/lib/Notifications.php index aff6ecb81f1c..ef0534fec3a5 100644 --- a/apps/federatedfilesharing/lib/Notifications.php +++ b/apps/federatedfilesharing/lib/Notifications.php @@ -162,7 +162,7 @@ public function requestReShare($token, $id, $shareId, $remote, $shareWith, $perm * @return bool */ public function sendRemoteUnShare($remote, $id, $token) { - $this->sendUpdateToRemote($remote, $id, $token, 'unshare'); + return $this->sendUpdateToRemote($remote, $id, $token, 'unshare'); } /** @@ -174,7 +174,7 @@ public function sendRemoteUnShare($remote, $id, $token) { * @return bool */ public function sendRevokeShare($remote, $id, $token) { - $this->sendUpdateToRemote($remote, $id, $token, 'revoke'); + return $this->sendUpdateToRemote($remote, $id, $token, 'revoke'); } /** @@ -187,7 +187,7 @@ public function sendRevokeShare($remote, $id, $token) { * @return bool */ public function sendPermissionChange($remote, $remoteId, $token, $permissions) { - $this->sendUpdateToRemote($remote, $remoteId, $token, 'permissions', ['permissions' => $permissions]); + return $this->sendUpdateToRemote($remote, $remoteId, $token, 'permissions', ['permissions' => $permissions]); } /** @@ -258,7 +258,6 @@ public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = return false; } - /** * return current timestamp * diff --git a/apps/federatedfilesharing/lib/RequestHandler.php b/apps/federatedfilesharing/lib/RequestHandler.php index f11bd4d60cae..108ba0adc3f2 100644 --- a/apps/federatedfilesharing/lib/RequestHandler.php +++ b/apps/federatedfilesharing/lib/RequestHandler.php @@ -147,9 +147,8 @@ public function createShare($params) { \OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), - \OC::$server->getHTTPHelper(), \OC::$server->getNotificationManager(), - $discoveryManager, + \OC::$server->getEventDispatcher(), $shareWith ); diff --git a/apps/federatedfilesharing/tests/RequestHandlerTest.php b/apps/federatedfilesharing/tests/RequestHandlerTest.php index 58c0f3cfc3d5..affcb525d8a1 100644 --- a/apps/federatedfilesharing/tests/RequestHandlerTest.php +++ b/apps/federatedfilesharing/tests/RequestHandlerTest.php @@ -249,9 +249,8 @@ function testDeleteUser($toDelete, $expected, $remainingUsers) { \OC::$server->getDatabaseConnection(), Filesystem::getMountManager(), Filesystem::getLoader(), - \OC::$server->getHTTPHelper(), \OC::$server->getNotificationManager(), - $discoveryManager, + \OC::$server->getEventDispatcher(), $toDelete ); diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index b451a16b7e79..2864c19b6fd6 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -261,10 +261,10 @@ 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; + var owner = $('#header').data('owner'); + var ownerDisplayName = $('#header').data('owner-display-name'); + var name = $('#header').data('name'); + var isProtected = $('#header').data('protected') ? 1 : 0; OCA.Sharing.PublicApp._saveToOwnCloud(remote, token, owner, ownerDisplayName, name, isProtected); }); @@ -335,7 +335,7 @@ OCA.Sharing.PublicApp = { 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; diff --git a/apps/files_sharing/lib/API/Remote.php b/apps/files_sharing/lib/API/Remote.php index b0177807bdb1..ba831777cd98 100644 --- a/apps/files_sharing/lib/API/Remote.php +++ b/apps/files_sharing/lib/API/Remote.php @@ -37,17 +37,12 @@ class Remote { * @return \OC_OCS_Result */ public static function getOpenShares($params) { - $discoveryManager = new DiscoveryManager( - \OC::$server->getMemCacheFactory(), - \OC::$server->getHTTPClientService() - ); $externalManager = new Manager( \OC::$server->getDatabaseConnection(), Filesystem::getMountManager(), Filesystem::getLoader(), - \OC::$server->getHTTPHelper(), \OC::$server->getNotificationManager(), - $discoveryManager, + \OC::$server->getEventDispatcher(), \OC_User::getUser() ); @@ -61,17 +56,12 @@ public static function getOpenShares($params) { * @return \OC_OCS_Result */ public static function acceptShare($params) { - $discoveryManager = new DiscoveryManager( - \OC::$server->getMemCacheFactory(), - \OC::$server->getHTTPClientService() - ); $externalManager = new Manager( \OC::$server->getDatabaseConnection(), Filesystem::getMountManager(), Filesystem::getLoader(), - \OC::$server->getHTTPHelper(), \OC::$server->getNotificationManager(), - $discoveryManager, + \OC::$server->getEventDispatcher(), \OC_User::getUser() ); @@ -103,17 +93,12 @@ public static function acceptShare($params) { * @return \OC_OCS_Result */ public static function declineShare($params) { - $discoveryManager = new DiscoveryManager( - \OC::$server->getMemCacheFactory(), - \OC::$server->getHTTPClientService() - ); $externalManager = new Manager( \OC::$server->getDatabaseConnection(), Filesystem::getMountManager(), Filesystem::getLoader(), - \OC::$server->getHTTPHelper(), \OC::$server->getNotificationManager(), - $discoveryManager, + \OC::$server->getEventDispatcher(), \OC_User::getUser() ); @@ -162,17 +147,12 @@ private static function extendShareInfo($share) { * @return \OC_OCS_Result */ public static function getShares($params) { - $discoveryManager = new DiscoveryManager( - \OC::$server->getMemCacheFactory(), - \OC::$server->getHTTPClientService() - ); $externalManager = new Manager( \OC::$server->getDatabaseConnection(), Filesystem::getMountManager(), Filesystem::getLoader(), - \OC::$server->getHTTPHelper(), \OC::$server->getNotificationManager(), - $discoveryManager, + \OC::$server->getEventDispatcher(), \OC_User::getUser() ); @@ -190,17 +170,12 @@ public static function getShares($params) { * @return \OC_OCS_Result */ public static function getShare($params) { - $discoveryManager = new DiscoveryManager( - \OC::$server->getMemCacheFactory(), - \OC::$server->getHTTPClientService() - ); $externalManager = new Manager( \OC::$server->getDatabaseConnection(), Filesystem::getMountManager(), Filesystem::getLoader(), - \OC::$server->getHTTPHelper(), \OC::$server->getNotificationManager(), - $discoveryManager, + \OC::$server->getEventDispatcher(), \OC_User::getUser() ); @@ -221,17 +196,12 @@ public static function getShare($params) { * @return \OC_OCS_Result */ public static function unshare($params) { - $discoveryManager = new DiscoveryManager( - \OC::$server->getMemCacheFactory(), - \OC::$server->getHTTPClientService() - ); $externalManager = new Manager( \OC::$server->getDatabaseConnection(), Filesystem::getMountManager(), Filesystem::getLoader(), - \OC::$server->getHTTPHelper(), \OC::$server->getNotificationManager(), - $discoveryManager, + \OC::$server->getEventDispatcher(), \OC_User::getUser() ); diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php index 5cc6903a96d8..14ab784d0cf1 100644 --- a/apps/files_sharing/lib/AppInfo/Application.php +++ b/apps/files_sharing/lib/AppInfo/Application.php @@ -2,6 +2,7 @@ /** * @author Björn Schießle * @author Joas Schilling + * @author Jörn Friedrich Dreyer * @author Lukas Reschke * @author Robin Appelman * @author Roeland Jago Douma @@ -26,7 +27,6 @@ namespace OCA\Files_Sharing\AppInfo; -use OCA\FederatedFileSharing\DiscoveryManager; use OCA\Files_Sharing\MountProvider; use OCP\AppFramework\App; use OC\AppFramework\Utility\SimpleContainer; @@ -34,7 +34,6 @@ use OCA\Files_Sharing\Controllers\ShareController; use OCA\Files_Sharing\Middleware\SharingCheckMiddleware; use \OCP\IContainer; -use OCA\Files_Sharing\Capabilities; class Application extends App { public function __construct(array $urlParams = []) { @@ -47,7 +46,6 @@ public function __construct(array $urlParams = []) { * Controllers */ $container->registerService('ShareController', function (SimpleContainer $c) use ($server) { - $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application('federatedfilesharing'); return new ShareController( $c->query('AppName'), $c->query('Request'), @@ -59,8 +57,7 @@ public function __construct(array $urlParams = []) { $server->getShareManager(), $server->getSession(), $server->getPreviewManager(), - $server->getRootFolder(), - $federatedSharingApp->getFederatedShareProvider() + $server->getRootFolder() ); }); $container->registerService('ExternalSharesController', function (SimpleContainer $c) { @@ -81,17 +78,12 @@ public function __construct(array $urlParams = []) { $container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) { $user = $server->getUserSession()->getUser(); $uid = $user ? $user->getUID() : null; - $discoveryManager = new DiscoveryManager( - \OC::$server->getMemCacheFactory(), - \OC::$server->getHTTPClientService() - ); return new \OCA\Files_Sharing\External\Manager( $server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), - $server->getHTTPHelper(), $server->getNotificationManager(), - $discoveryManager, + $server->getEventDispatcher(), $uid ); }); diff --git a/apps/files_sharing/lib/Controllers/ShareController.php b/apps/files_sharing/lib/Controllers/ShareController.php index 51c6c909344b..08b79ad9ff69 100644 --- a/apps/files_sharing/lib/Controllers/ShareController.php +++ b/apps/files_sharing/lib/Controllers/ShareController.php @@ -4,6 +4,7 @@ * @author Björn Schießle * @author Georg Ehrke * @author Joas Schilling + * @author Jörn Friedrich Dreyer * @author Lukas Reschke * @author Morris Jobke * @author Piotr Filiciak @@ -34,7 +35,6 @@ use OC; use OC_Files; use OC_Util; -use OCA\FederatedFileSharing\FederatedShareProvider; use OCP; use OCP\Template; use OCP\Share; @@ -49,8 +49,6 @@ use OCP\IUserManager; use OCP\ISession; use OCP\IPreview; -use OCA\Files_Sharing\Helper; -use OCP\Util; use OCA\Files_Sharing\Activity; use \OCP\Files\NotFoundException; use OCP\Files\IRootFolder; @@ -81,8 +79,6 @@ class ShareController extends Controller { protected $previewManager; /** @var IRootFolder */ protected $rootFolder; - /** @var FederatedShareProvider */ - protected $federatedShareProvider; /** * @param string $appName @@ -96,7 +92,6 @@ class ShareController extends Controller { * @param ISession $session * @param IPreview $previewManager * @param IRootFolder $rootFolder - * @param FederatedShareProvider $federatedShareProvider */ public function __construct($appName, IRequest $request, @@ -108,8 +103,7 @@ public function __construct($appName, \OCP\Share\IManager $shareManager, ISession $session, IPreview $previewManager, - IRootFolder $rootFolder, - FederatedShareProvider $federatedShareProvider) { + IRootFolder $rootFolder) { parent::__construct($appName, $request); $this->config = $config; @@ -121,7 +115,6 @@ public function __construct($appName, $this->session = $session; $this->previewManager = $previewManager; $this->rootFolder = $rootFolder; - $this->federatedShareProvider = $federatedShareProvider; } /** @@ -307,7 +300,6 @@ public function showShare($token, $path = '') { $shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($share->getNode()->getMimetype()); $shareTmpl['dirToken'] = $token; $shareTmpl['sharingToken'] = $token; - $shareTmpl['server2serversharing'] = $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); $shareTmpl['protected'] = $share->getPassword() !== null ? 'true' : 'false'; $shareTmpl['dir'] = ''; $shareTmpl['nonHumanFileSize'] = $share->getNode()->getSize(); diff --git a/apps/files_sharing/lib/External/Manager.php b/apps/files_sharing/lib/External/Manager.php index 3b703ac6f8bf..07aee4d860b1 100644 --- a/apps/files_sharing/lib/External/Manager.php +++ b/apps/files_sharing/lib/External/Manager.php @@ -30,9 +30,11 @@ namespace OCA\Files_Sharing\External; use OC\Files\Filesystem; -use OCA\FederatedFileSharing\DiscoveryManager; use OCP\Files; use OCP\Notification\IManager; +use OCP\Share\Events\AcceptShare; +use OCP\Share\Events\DeclineShare; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; class Manager { const STORAGE = '\OCA\Files_Sharing\External\Storage'; @@ -58,40 +60,35 @@ class Manager { private $storageLoader; /** - * @var \OC\HTTPHelper + * @var IManager */ - private $httpHelper; + private $notificationManager; /** - * @var IManager + * @var EventDispatcherInterface */ - private $notificationManager; - /** @var DiscoveryManager */ - private $discoveryManager; + private $eventDispatcher; /** * @param \OCP\IDBConnection $connection * @param \OC\Files\Mount\Manager $mountManager * @param \OCP\Files\Storage\IStorageFactory $storageLoader - * @param \OC\HTTPHelper $httpHelper * @param IManager $notificationManager - * @param DiscoveryManager $discoveryManager + * @param EventDispatcherInterface $eventDispatcher * @param string $uid */ public function __construct(\OCP\IDBConnection $connection, \OC\Files\Mount\Manager $mountManager, \OCP\Files\Storage\IStorageFactory $storageLoader, - \OC\HTTPHelper $httpHelper, IManager $notificationManager, - DiscoveryManager $discoveryManager, + EventDispatcherInterface $eventDispatcher, $uid) { $this->connection = $connection; $this->mountManager = $mountManager; $this->storageLoader = $storageLoader; - $this->httpHelper = $httpHelper; $this->uid = $uid; $this->notificationManager = $notificationManager; - $this->discoveryManager = $discoveryManager; + $this->eventDispatcher = $eventDispatcher; } /** @@ -203,7 +200,10 @@ public function acceptShare($id) { `mountpoint_hash` = ? WHERE `id` = ? AND `user` = ?'); $acceptShare->execute([1, $mountPoint, $hash, $id, $this->uid]); - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept'); + + $this->eventDispatcher->dispatch( + AcceptShare::class, new AcceptShare($share) + ); \OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $share['remote']]); @@ -228,7 +228,11 @@ public function declineShare($id) { $removeShare = $this->connection->prepare(' DELETE FROM `*PREFIX*share_external` WHERE `id` = ? AND `user` = ?'); $removeShare->execute([$id, $this->uid]); - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); + + $this->eventDispatcher->dispatch( + DeclineShare::class, + new DeclineShare($share) + ); $this->processNotification($id); return true; @@ -248,26 +252,6 @@ public function processNotification($remoteShare) { $this->notificationManager->markProcessed($filter); } - /** - * inform remote server whether server-to-server share was accepted/declined - * - * @param string $remote - * @param string $token - * @param int $remoteId Share id on the remote host - * @param string $feedback - * @return boolean - */ - private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) { - - $url = rtrim($remote, '/') . $this->discoveryManager->getShareEndpoint($remote) . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT; - $fields = ['token' => $token]; - - $result = $this->httpHelper->post($url, $fields); - $status = json_decode($result['result'], true); - - return ($result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200)); - } - /** * remove '/user/files' from the path and trailing slashes * @@ -342,7 +326,10 @@ public function removeShare($mountPoint) { if ($result) { $share = $getShare->fetch(); - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); + $this->eventDispatcher->dispatch( + DeclineShare::class, + new DeclineShare($share) + ); } $getShare->closeCursor(); @@ -399,7 +386,10 @@ public function removeUserShares($uid) { if ($result) { $shares = $getShare->fetchAll(); foreach($shares as $share) { - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); + $this->eventDispatcher->dispatch( + DeclineShare::class, + new DeclineShare($share) + ); } } diff --git a/apps/files_sharing/lib/Hooks.php b/apps/files_sharing/lib/Hooks.php index e9cd3275b283..54bc9fbbafa0 100644 --- a/apps/files_sharing/lib/Hooks.php +++ b/apps/files_sharing/lib/Hooks.php @@ -39,9 +39,8 @@ public static function deleteUser($params) { \OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), - \OC::$server->getHTTPHelper(), \OC::$server->getNotificationManager(), - $discoveryManager, + \OC::$server->getEventDispatcher(), $params['uid']); $manager->removeUserShares($params['uid']); diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php index 762f7653ea96..0f2a05bf41cd 100644 --- a/apps/files_sharing/templates/public.php +++ b/apps/files_sharing/templates/public.php @@ -51,9 +51,9 @@ -
-