Skip to content

Commit

Permalink
Merge pull request #28858 from owncloud/stable10-untangle
Browse files Browse the repository at this point in the history
[stable10] Untangle fed sharing inter-app dependencies
  • Loading branch information
Vincent Petry authored Aug 30, 2017
2 parents 4eff831 + ab67cc2 commit eb90d18
Show file tree
Hide file tree
Showing 19 changed files with 314 additions and 146 deletions.
36 changes: 36 additions & 0 deletions apps/federatedfilesharing/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/**
* @author Björn Schießle <[email protected]>
* @author Joas Schilling <[email protected]>
* @author Jörn Friedrich Dreyer <[email protected]>
*
* @copyright Copyright (c) 2017, ownCloud GmbH
* @license AGPL-3.0
Expand All @@ -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() {
Expand All @@ -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()
);
}
);
3 changes: 3 additions & 0 deletions apps/federatedfilesharing/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<namespace>FederatedFileSharing</namespace>
<use-migrations>true</use-migrations>
<category>other</category>
<types>
<filesystem/>
</types>
<dependencies>
<owncloud min-version="10.0.2.4" max-version="10.0" />
</dependencies>
Expand Down
10 changes: 10 additions & 0 deletions apps/federatedfilesharing/js/public.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$(document).ready(function() {
$('#header #details').prepend(
'<span id="save">' +
' <button id="save-button">'+t('files_sharing', 'Add to your ownCloud')+'</button>' +
' <form class="save-form hidden" action="#">' +
' <input type="text" id="remote_address" placeholder="example.com/owncloud"/>' +
' <button id="save-button-confirm" class="icon-confirm svg" disabled></button>' +
' </form>' +
'</span>');
});
37 changes: 37 additions & 0 deletions apps/federatedfilesharing/lib/HookHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* @author Jörn Friedrich Dreyer <[email protected]>
*
* @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 <http://www.gnu.org/licenses/>
*
*/

namespace OCA\FederatedFileSharing;

/**
* Class HookHandler
*
* handles hooks
*
* @package OCA\FederatedFileSharing
*/
class HookHandler {

public static function loadPublicJS () {
\OCP\Util::addScript('federatedfilesharing', 'public');
}

}
7 changes: 3 additions & 4 deletions apps/federatedfilesharing/lib/Notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand All @@ -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');
}

/**
Expand All @@ -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]);
}

/**
Expand Down Expand Up @@ -258,7 +258,6 @@ public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data =
return false;
}


/**
* return current timestamp
*
Expand Down
3 changes: 1 addition & 2 deletions apps/federatedfilesharing/lib/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down
3 changes: 1 addition & 2 deletions apps/federatedfilesharing/tests/RequestHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down
10 changes: 5 additions & 5 deletions apps/files_sharing/js/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down Expand Up @@ -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;
Expand Down
42 changes: 6 additions & 36 deletions apps/files_sharing/lib/API/Remote.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,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()
);

Expand All @@ -60,17 +55,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()
);

Expand All @@ -91,17 +81,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()
);

Expand Down Expand Up @@ -139,17 +124,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()
);

Expand All @@ -167,17 +147,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()
);

Expand All @@ -198,17 +173,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()
);

Expand Down
14 changes: 3 additions & 11 deletions apps/files_sharing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/**
* @author Björn Schießle <[email protected]>
* @author Joas Schilling <[email protected]>
* @author Jörn Friedrich Dreyer <[email protected]>
* @author Lukas Reschke <[email protected]>
* @author Robin Appelman <[email protected]>
* @author Roeland Jago Douma <[email protected]>
Expand All @@ -26,15 +27,13 @@

namespace OCA\Files_Sharing\AppInfo;

use OCA\FederatedFileSharing\DiscoveryManager;
use OCA\Files_Sharing\MountProvider;
use OCP\AppFramework\App;
use OC\AppFramework\Utility\SimpleContainer;
use OCA\Files_Sharing\Controllers\ExternalSharesController;
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 = []) {
Expand All @@ -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'),
Expand All @@ -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) {
Expand All @@ -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
);
});
Expand Down
Loading

0 comments on commit eb90d18

Please sign in to comment.