From e10105474fbef8940fdfa96d5e2bf2f09b1f0649 Mon Sep 17 00:00:00 2001 From: Björn Schießle Date: Mon, 18 Apr 2016 18:17:08 +0200 Subject: move federated sharing settings to the federatedfilesharing app --- apps/dav/appinfo/v1/publicwebdav.php | 4 +- apps/federatedfilesharing/appinfo/app.php | 6 +- apps/federatedfilesharing/appinfo/application.php | 88 +++++++++ .../css/3rdparty/gs-share/style.css | 49 +++++ .../federatedfilesharing/css/settings-personal.css | 33 ++++ apps/federatedfilesharing/img/social-diaspora.svg | 52 ++++++ apps/federatedfilesharing/img/social-facebook.svg | 43 +++++ apps/federatedfilesharing/img/social-gnu.svg | 79 ++++++++ .../federatedfilesharing/img/social-googleplus.svg | 45 +++++ apps/federatedfilesharing/img/social-twitter.svg | 53 ++++++ .../js/3rdparty/gs-share/gs-share.js | 206 +++++++++++++++++++++ apps/federatedfilesharing/js/settings-admin.js | 12 ++ apps/federatedfilesharing/js/settings-personal.js | 19 ++ .../lib/federatedshareprovider.php | 30 ++- apps/federatedfilesharing/settings-admin.php | 34 ++++ apps/federatedfilesharing/settings-personal.php | 52 ++++++ .../templates/settings-admin.php | 28 +++ .../templates/settings-personal.php | 78 ++++++++ .../tests/federatedshareprovidertest.php | 46 ++++- apps/files_sharing/ajax/external.php | 5 +- apps/files_sharing/ajax/shareinfo.php | 5 +- apps/files_sharing/api/server2server.php | 18 +- apps/files_sharing/appinfo/app.php | 3 - apps/files_sharing/appinfo/application.php | 4 +- apps/files_sharing/css/3rdparty/gs-share/style.css | 49 ----- apps/files_sharing/css/settings-personal.css | 33 ---- apps/files_sharing/img/social-diaspora.svg | 52 ------ apps/files_sharing/img/social-facebook.svg | 43 ----- apps/files_sharing/img/social-gnu.svg | 79 -------- apps/files_sharing/img/social-googleplus.svg | 45 ----- apps/files_sharing/img/social-twitter.svg | 53 ------ .../files_sharing/js/3rdparty/gs-share/gs-share.js | 206 --------------------- apps/files_sharing/js/settings-admin.js | 12 -- apps/files_sharing/js/settings-personal.js | 19 -- .../lib/controllers/sharecontroller.php | 10 +- apps/files_sharing/lib/helper.php | 20 -- apps/files_sharing/lib/share/file.php | 16 +- apps/files_sharing/settings-admin.php | 31 ---- apps/files_sharing/settings-personal.php | 47 ----- apps/files_sharing/templates/settings-admin.php | 26 --- apps/files_sharing/templates/settings-personal.php | 78 -------- .../tests/controller/sharecontroller.php | 12 +- apps/files_sharing/tests/server2server.php | 11 +- 43 files changed, 1021 insertions(+), 813 deletions(-) create mode 100644 apps/federatedfilesharing/appinfo/application.php create mode 100644 apps/federatedfilesharing/css/3rdparty/gs-share/style.css create mode 100644 apps/federatedfilesharing/css/settings-personal.css create mode 100644 apps/federatedfilesharing/img/social-diaspora.svg create mode 100644 apps/federatedfilesharing/img/social-facebook.svg create mode 100644 apps/federatedfilesharing/img/social-gnu.svg create mode 100644 apps/federatedfilesharing/img/social-googleplus.svg create mode 100644 apps/federatedfilesharing/img/social-twitter.svg create mode 100644 apps/federatedfilesharing/js/3rdparty/gs-share/gs-share.js create mode 100644 apps/federatedfilesharing/js/settings-admin.js create mode 100644 apps/federatedfilesharing/js/settings-personal.js create mode 100644 apps/federatedfilesharing/settings-admin.php create mode 100644 apps/federatedfilesharing/settings-personal.php create mode 100644 apps/federatedfilesharing/templates/settings-admin.php create mode 100644 apps/federatedfilesharing/templates/settings-personal.php delete mode 100644 apps/files_sharing/css/3rdparty/gs-share/style.css delete mode 100644 apps/files_sharing/css/settings-personal.css delete mode 100644 apps/files_sharing/img/social-diaspora.svg delete mode 100644 apps/files_sharing/img/social-facebook.svg delete mode 100644 apps/files_sharing/img/social-gnu.svg delete mode 100644 apps/files_sharing/img/social-googleplus.svg delete mode 100644 apps/files_sharing/img/social-twitter.svg delete mode 100644 apps/files_sharing/js/3rdparty/gs-share/gs-share.js delete mode 100644 apps/files_sharing/js/settings-admin.js delete mode 100644 apps/files_sharing/js/settings-personal.js delete mode 100644 apps/files_sharing/settings-admin.php delete mode 100644 apps/files_sharing/settings-personal.php delete mode 100644 apps/files_sharing/templates/settings-admin.php delete mode 100644 apps/files_sharing/templates/settings-personal.php (limited to 'apps') diff --git a/apps/dav/appinfo/v1/publicwebdav.php b/apps/dav/appinfo/v1/publicwebdav.php index 43fedb19415..39c169728b9 100644 --- a/apps/dav/appinfo/v1/publicwebdav.php +++ b/apps/dav/appinfo/v1/publicwebdav.php @@ -55,7 +55,9 @@ $linkCheckPlugin = new \OCA\DAV\Files\Sharing\PublicLinkCheckPlugin(); $server = $serverFactory->createServer($baseuri, $requestUri, $authBackend, function (\Sabre\DAV\Server $server) use ($authBackend, $linkCheckPlugin) { $isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest'); - if (OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled() === false && !$isAjax) { + $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application('federatedfilesharing'); + $federatedShareProvider = $federatedSharingApp->getFederatedShareProvider(); + if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false && !$isAjax) { // this is what is thrown when trying to access a non-existing share throw new \Sabre\DAV\Exception\NotAuthenticated(); } diff --git a/apps/federatedfilesharing/appinfo/app.php b/apps/federatedfilesharing/appinfo/app.php index 804ab69759c..23af62037a3 100644 --- a/apps/federatedfilesharing/appinfo/app.php +++ b/apps/federatedfilesharing/appinfo/app.php @@ -21,7 +21,5 @@ namespace OCA\FederatedFileSharing\AppInfo; -use OCP\AppFramework\App; - -new App('federatedfilesharing'); - +$app = new Application('federatedfilesharing'); +$app->registerSettings(); diff --git a/apps/federatedfilesharing/appinfo/application.php b/apps/federatedfilesharing/appinfo/application.php new file mode 100644 index 00000000000..5a213aec8e2 --- /dev/null +++ b/apps/federatedfilesharing/appinfo/application.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\AppInfo; + + +use OCA\FederatedFileSharing\FederatedShareProvider; +use OCP\AppFramework\App; + +class Application extends App { + + /** @var FederatedShareProvider */ + protected $federatedShareProvider; + + /** + * register personal and admin settings page + */ + public function registerSettings() { + \OCP\App::registerAdmin('federatedfilesharing', 'settings-admin'); + \OCP\App::registerPersonal('federatedfilesharing', 'settings-personal'); + } + + /** + * get instance of federated share provider + * + * @return FederatedShareProvider + */ + public function getFederatedShareProvider() { + if ($this->federatedShareProvider === null) { + $this->initFederatedShareProvider(); + } + return $this->federatedShareProvider; + } + + /** + * initialize federated share provider + */ + protected function initFederatedShareProvider() { + $addressHandler = new \OCA\FederatedFileSharing\AddressHandler( + \OC::$server->getURLGenerator(), + \OC::$server->getL10N('federatedfilesharing') + ); + $discoveryManager = new \OCA\FederatedFileSharing\DiscoveryManager( + \OC::$server->getMemCacheFactory(), + \OC::$server->getHTTPClientService() + ); + $notifications = new \OCA\FederatedFileSharing\Notifications( + $addressHandler, + \OC::$server->getHTTPClientService(), + $discoveryManager, + \OC::$server->getJobList() + ); + $tokenHandler = new \OCA\FederatedFileSharing\TokenHandler( + \OC::$server->getSecureRandom() + ); + + $this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider( + \OC::$server->getDatabaseConnection(), + $addressHandler, + $notifications, + $tokenHandler, + \OC::$server->getL10N('federatedfilesharing'), + \OC::$server->getLogger(), + \OC::$server->getLazyRootFolder(), + \OC::$server->getConfig() + ); + } + +} diff --git a/apps/federatedfilesharing/css/3rdparty/gs-share/style.css b/apps/federatedfilesharing/css/3rdparty/gs-share/style.css new file mode 100644 index 00000000000..c699ddb3db5 --- /dev/null +++ b/apps/federatedfilesharing/css/3rdparty/gs-share/style.css @@ -0,0 +1,49 @@ +.js-gs-share, .gs-share [aria-hidden="true"], .gs-share-form[aria-hidden="true"] { + display: none; +} + +.js-gs-share-enabled .js-gs-share { + display: inline; + float: left; +} + +.gs-share .js-gs-share[href] { + display: inline; +} + +.gs-share [aria-hidden="false"], .gs-share-form[aria-hidden="false"] { + display: block; + margin-top: 40px; +} + +.gs-share { + position: relative; +} + +.gs-share-form { + background: #FFF; + border: 1px solid #000; + border-radius: 5px; + padding: 5px; + position: absolute; + z-index: 1; +} + +.gs-share [for="gs-account"], .gs-share [type="text"] { + display: block; + margin-bottom: 8px; +} + +.gs-share [type="submit"] { + display: block; + margin-top: 8px; +} + +.gs-share--icon { + border: none; + cursor: pointer; + min-height: 32px; + padding: 0; + padding-left: 33px; + background: transparent url('../../../img/gs-share.png') no-repeat left center; +} diff --git a/apps/federatedfilesharing/css/settings-personal.css b/apps/federatedfilesharing/css/settings-personal.css new file mode 100644 index 00000000000..f53365c9371 --- /dev/null +++ b/apps/federatedfilesharing/css/settings-personal.css @@ -0,0 +1,33 @@ +#fileSharingSettings img { + cursor: pointer; +} + +#fileSharingSettings xmp { + margin-top: 0; + white-space: pre-wrap; +} + +[class^="social-"], [class*=" social-"] { + background-repeat: no-repeat; + background-position: 2px; + min-width: 16px; + min-height: 16px; + padding-left: 29px; + background-size: 24px; +} + +.social-gnu { + background-image: url('../img/social-gnu.svg'); +} +.social-diaspora { + background-image: url('../img/social-diaspora.svg'); +} +.social-twitter { + background-image: url('../img/social-twitter.svg'); +} +.social-facebook { + background-image: url('../img/social-facebook.svg'); +} +.social-googleplus { + background-image: url('../img/social-googleplus.svg'); +} diff --git a/apps/federatedfilesharing/img/social-diaspora.svg b/apps/federatedfilesharing/img/social-diaspora.svg new file mode 100644 index 00000000000..1d5131129a9 --- /dev/null +++ b/apps/federatedfilesharing/img/social-diaspora.svg @@ -0,0 +1,52 @@ + + + + + + image/svg+xml + + + + + + + + + diff --git a/apps/federatedfilesharing/img/social-facebook.svg b/apps/federatedfilesharing/img/social-facebook.svg new file mode 100644 index 00000000000..aad02bc3853 --- /dev/null +++ b/apps/federatedfilesharing/img/social-facebook.svg @@ -0,0 +1,43 @@ + +image/svg+xml \ No newline at end of file diff --git a/apps/federatedfilesharing/img/social-gnu.svg b/apps/federatedfilesharing/img/social-gnu.svg new file mode 100644 index 00000000000..24556aaa024 --- /dev/null +++ b/apps/federatedfilesharing/img/social-gnu.svg @@ -0,0 +1,79 @@ + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/apps/federatedfilesharing/img/social-googleplus.svg b/apps/federatedfilesharing/img/social-googleplus.svg new file mode 100644 index 00000000000..123273f2d38 --- /dev/null +++ b/apps/federatedfilesharing/img/social-googleplus.svg @@ -0,0 +1,45 @@ + +image/svg+xml \ No newline at end of file diff --git a/apps/federatedfilesharing/img/social-twitter.svg b/apps/federatedfilesharing/img/social-twitter.svg new file mode 100644 index 00000000000..00ce390de6b --- /dev/null +++ b/apps/federatedfilesharing/img/social-twitter.svg @@ -0,0 +1,53 @@ + + + + + + image/svg+xml + + + + + + + + + diff --git a/apps/federatedfilesharing/js/3rdparty/gs-share/gs-share.js b/apps/federatedfilesharing/js/3rdparty/gs-share/gs-share.js new file mode 100644 index 00000000000..fd4442708a4 --- /dev/null +++ b/apps/federatedfilesharing/js/3rdparty/gs-share/gs-share.js @@ -0,0 +1,206 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// @license magnet:?xt=urn:btih:3877d6d54b3accd4bc32f8a48bf32ebc0901502a&dn=mpl-2.0.txt MPL 2.0 +document.addEventListener('DOMContentLoaded', function () { + 'use strict'; + /** + * 'Share' widget for GNU social + * http://code.chromic.org/project/view/2/ + * + * We make a few assumptions about the target instance: + * 1) The API root is in the default location + * 2) Fancy URLs are enabled + * 3) CORS is allowed + * 4) The Bookmark plugin is enabled + * + * If 1), 3) or 4) are wrong, we fall back to a regular + * notice (instead of a bookmark notice) + * + * If 2) is wrong the user will be directed to a 404 :( + */ + + // TODO: input sanitation [1], [2] + // TODO: server-side fallback if JS is disabled + + var createForm, + bindClicks, + frm, + shareAsNotice, + shareAsBookmark, + extractURLParams, + shareURL, + shareTitle, + closest, + i18n = window.i18n; + + /** + * Internationalization + */ + if (i18n === undefined) { + i18n = { + invalidId: 'The account id provided is invalid', + yourAcctId: 'Your account ID:', + idPlaceholder: 'user@example.org', + shareAsBookmark: 'Share as a bookmark' + }; + } + + shareAsNotice = function (title, url, domain) { + window.open('http://' + domain + '/notice/new?status_textarea=' + title + ' ' + url); // [1] + }; + + shareAsBookmark = function (title, url, domain) { + window.open('http://' + domain + '/main/bookmark/new?url=' + url + '&title=' + title); // [2] + }; + + /** + * Extract parameters from query string + * + * ex: + * ?foo=bar&baz=test + * will return: + * {foo: 'bar', baz: 'test'} + */ + extractURLParams = function (queryStr) { + var parts = queryStr.substr(1).split('&'), + i, len, keyVal, params = {}; + + for (i = 0, len = parts.length; i < len; i += 1) { + keyVal = parts[i].split('='); + params[keyVal[0]] = keyVal[1]; + } + + return params; + }; + + // Create the form that we'll re-use throughout the page + createForm = function () { + var err = document.createElement('div'); + err.setAttribute('class', 'gs-share-err'); + err.setAttribute('tabindex', '-1'); + err.setAttribute('aria-hidden', 'true'); + err.textContent = i18n.invalidId; + + frm = document.createElement('form'); + + frm.setAttribute('class', 'gs-share-form'); + frm.setAttribute('tabindex', '-1'); + frm.setAttribute('aria-hidden', 'true'); + + frm.innerHTML = '' + + '' + + ' ' + + ''; + frm.insertBefore(err, frm.firstChild); + + // Submit handler + frm.addEventListener('submit', function (e) { + e.preventDefault(); + + var accountParts = document.getElementById('gs-account').value.split('@'), + username, domain, xhr, bookmarkURL; + + if (accountParts.length === 2) { + err.setAttribute('aria-hidden', 'true'); + + username = accountParts[0]; + domain = accountParts[1]; + bookmarkURL = 'http://' + domain + '/api/bookmarks/' + username + '.json'; + + // Try bookmark + if (document.getElementById('gs-bookmark').checked) { + xhr = new XMLHttpRequest(); + + xhr.onreadystatechange = function () { + if (xhr.readyState === 4) { + if (xhr.status === 200) { // Success + shareAsBookmark(shareTitle, shareURL, domain); + } else { // Failure, fallback to regular notice + shareAsNotice(shareTitle, shareURL, domain); + } + } + }; + + xhr.open('GET', bookmarkURL, true); + xhr.send(); + } else { // Regular notice + shareAsNotice(shareTitle, shareURL, domain); + } + } else { // Invalid account id + err.setAttribute('aria-hidden', 'false'); + err.focus(); + } + }); + + // Keydown handler + frm.addEventListener('keydown', function (e) { + if (e.keyCode === 27) { // Escape key closes the dialog + frm.parentElement.getElementsByClassName('js-gs-share')[0].focus(); + frm.setAttribute('aria-hidden', 'true'); + } + }); + + document.body.appendChild(frm); + }; + + /** + * Something similar to jQuery.closest + * + * Given `elm`, return the closest parent with class `cls` + * or false if there is no matching ancestor. + */ + closest = function (elm, cls) { + while (elm !== document) { + if (elm.classList.contains(cls)) { + return elm; + } + + elm = elm.parentNode; + } + + return false; + }; + + bindClicks = function () { + document.addEventListener('click', function (e) { + var target = e.target, + urlParams, + lnk = closest(target, 'js-gs-share'); + + // Don't do anything on right/middle click or if ctrl or shift was pressed while left-clicking + if (!e.button && !e.ctrlKey && !e.shiftKey && lnk) { + e.preventDefault(); + + // Check for submission information in href first + if (lnk.search !== undefined) { + urlParams = extractURLParams(lnk.search); + shareURL = urlParams.url; + shareTitle = urlParams.title; + } else { // If it's not there, try data-* attributes. If not, use current document url and title + shareURL = lnk.getAttribute('data-url') || window.location.href; + shareTitle = lnk.getAttribute('data-title') || document.title; + } + + // Move form after the clicked link + lnk.parentNode.appendChild(frm); + + // Show form + frm.setAttribute('aria-hidden', 'false'); + + // Focus on form + frm.focus(); + } else if (!frm.contains(target)) { + frm.setAttribute('aria-hidden', 'true'); + } + }); + }; + + // Flag that js is enabled + document.body.classList.add('js-gs-share-enabled'); + + createForm(); + bindClicks(); +}); +// @license-end diff --git a/apps/federatedfilesharing/js/settings-admin.js b/apps/federatedfilesharing/js/settings-admin.js new file mode 100644 index 00000000000..95578bff548 --- /dev/null +++ b/apps/federatedfilesharing/js/settings-admin.js @@ -0,0 +1,12 @@ +$(document).ready(function() { + + $('#fileSharingSettings input').change(function() { + var value = 'no'; + if (this.checked) { + value = 'yes'; + } + OC.AppConfig.setValue('files_sharing', $(this).attr('name'), value); + }); + + $('.section .icon-info').tipsy({gravity: 'w'}); +}); diff --git a/apps/federatedfilesharing/js/settings-personal.js b/apps/federatedfilesharing/js/settings-personal.js new file mode 100644 index 00000000000..14a9b7bbfa7 --- /dev/null +++ b/apps/federatedfilesharing/js/settings-personal.js @@ -0,0 +1,19 @@ +$(document).ready(function() { + + $('#fileSharingSettings button.pop-up').click(function() { + var url = $(this).data('url'); + if (url) { + var width = 600; + var height = 400; + var left = (screen.width/2)-(width/2); + var top = (screen.height/2)-(height/2); + + window.open(url, 'name', 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left); + } + }); + + $('#oca-files-sharing-add-to-your-website').click(function() { + $('#oca-files-sharing-add-to-your-website-expanded').slideDown(); + }); + +}); diff --git a/apps/federatedfilesharing/lib/federatedshareprovider.php b/apps/federatedfilesharing/lib/federatedshareprovider.php index 78b0b664204..d014a6219a3 100644 --- a/apps/federatedfilesharing/lib/federatedshareprovider.php +++ b/apps/federatedfilesharing/lib/federatedshareprovider.php @@ -25,6 +25,8 @@ namespace OCA\FederatedFileSharing; use OC\Share20\Share; use OCP\Files\IRootFolder; +use OCP\IAppConfig; +use OCP\IConfig; use OCP\IL10N; use OCP\ILogger; use OCP\Share\IShare; @@ -65,6 +67,9 @@ class FederatedShareProvider implements IShareProvider { /** @var IRootFolder */ private $rootFolder; + /** @var IConfig */ + private $config; + /** * DefaultShareProvider constructor. * @@ -75,6 +80,7 @@ class FederatedShareProvider implements IShareProvider { * @param IL10N $l10n * @param ILogger $logger * @param IRootFolder $rootFolder + * @param IConfig $config */ public function __construct( IDBConnection $connection, @@ -83,7 +89,8 @@ class FederatedShareProvider implements IShareProvider { TokenHandler $tokenHandler, IL10N $l10n, ILogger $logger, - IRootFolder $rootFolder + IRootFolder $rootFolder, + IConfig $config ) { $this->dbConnection = $connection; $this->addressHandler = $addressHandler; @@ -92,6 +99,7 @@ class FederatedShareProvider implements IShareProvider { $this->l = $l10n; $this->logger = $logger; $this->rootFolder = $rootFolder; + $this->config = $config; } /** @@ -601,4 +609,24 @@ class FederatedShareProvider implements IShareProvider { // We don't handle groups here return; } + + /** + * check if users from other ownCloud instances are allowed to mount public links share by this instance + * + * @return bool + */ + public function isOutgoingServer2serverShareEnabled() { + $result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes'); + return ($result === 'yes') ? true : false; + } + + /** + * check if users are allowed to mount public links from other ownClouds + * + * @return bool + */ + public function isIncomingServer2serverShareEnabled() { + $result = $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes'); + return ($result === 'yes') ? true : false; + } } diff --git a/apps/federatedfilesharing/settings-admin.php b/apps/federatedfilesharing/settings-admin.php new file mode 100644 index 00000000000..9dd21281fda --- /dev/null +++ b/apps/federatedfilesharing/settings-admin.php @@ -0,0 +1,34 @@ + + * @author Morris Jobke + * + * @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 + * + */ + +use OCA\FederatedFileSharing\AppInfo\Application; + +\OC_Util::checkAdminUser(); + +$app = new Application('federatedfilesharing'); +$federatedShareProvider = $app->getFederatedShareProvider(); + +$tmpl = new OCP\Template('federatedfilesharing', 'settings-admin'); +$tmpl->assign('outgoingServer2serverShareEnabled', $federatedShareProvider->isOutgoingServer2serverShareEnabled()); +$tmpl->assign('incomingServer2serverShareEnabled', $federatedShareProvider->isIncomingServer2serverShareEnabled()); + +return $tmpl->fetchPage(); diff --git a/apps/federatedfilesharing/settings-personal.php b/apps/federatedfilesharing/settings-personal.php new file mode 100644 index 00000000000..385d3971146 --- /dev/null +++ b/apps/federatedfilesharing/settings-personal.php @@ -0,0 +1,52 @@ + + * @author Jan-Christoph Borchardt + * @author Thomas Müller + * + * @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 + * + */ + +use OCA\FederatedFileSharing\AppInfo\Application; + +\OC_Util::checkLoggedIn(); + +$l = \OC::$server->getL10N('federatedfilesharing'); + +$app = new Application('federatedfilesharing'); +$federatedShareProvider = $app->getFederatedShareProvider(); + +$isIE8 = false; +preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches); +if (count($matches) > 0 && $matches[1] <= 9) { + $isIE8 = true; +} + +$cloudID = \OC::$server->getUserSession()->getUser()->getCloudId(); +$url = 'https://owncloud.org/federation#' . $cloudID; +$ownCloudLogoPath = \OC::$server->getURLGenerator()->imagePath('core', 'logo-icon.svg'); + +$tmpl = new OCP\Template('federatedfilesharing', 'settings-personal'); +$tmpl->assign('outgoingServer2serverShareEnabled', $federatedShareProvider->isOutgoingServer2serverShareEnabled()); +$tmpl->assign('message_with_URL', $l->t('Share with me through my #ownCloud Federated Cloud ID, see %s', [$url])); +$tmpl->assign('message_without_URL', $l->t('Share with me through my #ownCloud Federated Cloud ID', [$cloudID])); +$tmpl->assign('owncloud_logo_path', $ownCloudLogoPath); +$tmpl->assign('reference', $url); +$tmpl->assign('cloudId', $cloudID); +$tmpl->assign('showShareIT', !$isIE8); + +return $tmpl->fetchPage(); diff --git a/apps/federatedfilesharing/templates/settings-admin.php b/apps/federatedfilesharing/templates/settings-admin.php new file mode 100644 index 00000000000..5d2eb04c170 --- /dev/null +++ b/apps/federatedfilesharing/templates/settings-admin.php @@ -0,0 +1,28 @@ + + +
+

t('Federated Cloud Sharing'));?>

+ + +

+ /> + +

+ +

+ /> +
+

+
diff --git a/apps/federatedfilesharing/templates/settings-personal.php b/apps/federatedfilesharing/templates/settings-personal.php new file mode 100644 index 00000000000..87b524af3e8 --- /dev/null +++ b/apps/federatedfilesharing/templates/settings-personal.php @@ -0,0 +1,78 @@ + + + +
+

t('Federated Cloud')); ?>

+ +

+ t('Your Federated Cloud ID:')); ?> + +

+ +
+ + +

+ t('Share it:')); ?> +

+ +
+ + + + + +

+ + + + +
+ diff --git a/apps/federatedfilesharing/tests/federatedshareprovidertest.php b/apps/federatedfilesharing/tests/federatedshareprovidertest.php index 92e9f10c3cd..1fbae90a46f 100644 --- a/apps/federatedfilesharing/tests/federatedshareprovidertest.php +++ b/apps/federatedfilesharing/tests/federatedshareprovidertest.php @@ -26,6 +26,7 @@ use OCA\FederatedFileSharing\FederatedShareProvider; use OCA\FederatedFileSharing\Notifications; use OCA\FederatedFileSharing\TokenHandler; use OCP\Files\IRootFolder; +use OCP\IConfig; use OCP\IDBConnection; use OCP\IL10N; use OCP\ILogger; @@ -54,6 +55,8 @@ class FederatedShareProviderTest extends TestCase { protected $logger; /** @var IRootFolder | \PHPUnit_Framework_MockObject_MockObject */ protected $rootFolder; + /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */ + protected $config; /** @var IManager */ protected $shareManager; @@ -78,6 +81,7 @@ class FederatedShareProviderTest extends TestCase { })); $this->logger = $this->getMock('OCP\ILogger'); $this->rootFolder = $this->getMock('OCP\Files\IRootFolder'); + $this->config = $this->getMock('OCP\IConfig'); $this->addressHandler = new AddressHandler(\OC::$server->getURLGenerator(), $this->l); $this->provider = new FederatedShareProvider( @@ -87,7 +91,8 @@ class FederatedShareProviderTest extends TestCase { $this->tokenHandler, $this->l, $this->logger, - $this->rootFolder + $this->rootFolder, + $this->config ); $this->shareManager = \OC::$server->getShareManager(); @@ -510,4 +515,43 @@ class FederatedShareProviderTest extends TestCase { $this->assertCount($rowDeleted ? 0 : 1, $data); } + + /** + * @dataProvider dataTestFederatedSharingSettings + * + * @param string $isEnabled + * @param bool $expected + */ + public function testIsOutgoingServer2serverShareEnabled($isEnabled, $expected) { + $this->config->expects($this->once())->method('getAppValue') + ->with('files_sharing', 'outgoing_server2server_share_enabled', 'yes') + ->willReturn($isEnabled); + + $this->assertSame($expected, + $this->provider->isOutgoingServer2serverShareEnabled() + ); + } + + /** + * @dataProvider dataTestFederatedSharingSettings + * + * @param string $isEnabled + * @param bool $expected + */ + public function testIsIncomingServer2serverShareEnabled($isEnabled, $expected) { + $this->config->expects($this->once())->method('getAppValue') + ->with('files_sharing', 'incoming_server2server_share_enabled', 'yes') + ->willReturn($isEnabled); + + $this->assertSame($expected, + $this->provider->isIncomingServer2serverShareEnabled() + ); + } + + public function dataTestFederatedSharingSettings() { + return [ + ['yes', true], + ['no', false] + ]; + } } diff --git a/apps/files_sharing/ajax/external.php b/apps/files_sharing/ajax/external.php index 76f9d5d7668..78e648618be 100644 --- a/apps/files_sharing/ajax/external.php +++ b/apps/files_sharing/ajax/external.php @@ -31,8 +31,11 @@ OCP\JSON::checkAppEnabled('files_sharing'); $l = \OC::$server->getL10N('files_sharing'); +$federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application('federatedfilesharing'); +$federatedShareProvider = $federatedSharingApp->getFederatedShareProvider(); + // check if server admin allows to mount public links from other servers -if (OCA\Files_Sharing\Helper::isIncomingServer2serverShareEnabled() === false) { +if ($federatedShareProvider->isIncomingServer2serverShareEnabled() === false) { \OCP\JSON::error(array('data' => array('message' => $l->t('Server to server sharing is not enabled on this server')))); exit(); } diff --git a/apps/files_sharing/ajax/shareinfo.php b/apps/files_sharing/ajax/shareinfo.php index 47bc061c136..d7f756b0039 100644 --- a/apps/files_sharing/ajax/shareinfo.php +++ b/apps/files_sharing/ajax/shareinfo.php @@ -29,7 +29,10 @@ if (!isset($_GET['t'])) { exit; } -if (OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled() === false) { +$federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application('federatedfilesharing'); +$federatedShareProvider = $federatedSharingApp->getFederatedShareProvider(); + +if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false) { \OC_Response::setStatus(404); // 404 not found exit; } diff --git a/apps/files_sharing/api/server2server.php b/apps/files_sharing/api/server2server.php index 11b24d9148b..034ec5105e4 100644 --- a/apps/files_sharing/api/server2server.php +++ b/apps/files_sharing/api/server2server.php @@ -26,11 +26,25 @@ namespace OCA\Files_Sharing\API; use OCA\FederatedFileSharing\DiscoveryManager; +use OCA\FederatedFileSharing\FederatedShareProvider; use OCA\Files_Sharing\Activity; use OCP\Files\NotFoundException; class Server2Server { + /** @var FederatedShareProvider */ + private $federatedShareProvider; + + + /** + * Server2Server constructor. + * + * @param FederatedShareProvider $federatedShareProvider + */ + public function __construct(FederatedShareProvider $federatedShareProvider) { + $this->federatedShareProvider = $federatedShareProvider; + } + /** * create a new share * @@ -300,9 +314,9 @@ class Server2Server { $result = \OCP\App::isEnabled('files_sharing'); if ($incoming) { - $result = $result && \OCA\Files_Sharing\Helper::isIncomingServer2serverShareEnabled(); + $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled(); } else { - $result = $result && \OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled(); + $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); } return $result; diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index 29202c15b22..e0cbfd7f5ba 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -44,9 +44,6 @@ $l = \OC::$server->getL10N('files_sharing'); $application = new Application(); $application->registerMountProviders(); -\OCP\App::registerAdmin('files_sharing', 'settings-admin'); -\OCP\App::registerPersonal('files_sharing', 'settings-personal'); - \OCA\Files_Sharing\Helper::registerHooks(); \OCP\Share::registerBackend('file', 'OC_Share_Backend_File'); diff --git a/apps/files_sharing/appinfo/application.php b/apps/files_sharing/appinfo/application.php index 5233b343830..b17e213e2e2 100644 --- a/apps/files_sharing/appinfo/application.php +++ b/apps/files_sharing/appinfo/application.php @@ -45,6 +45,7 @@ class Application extends App { * 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'), @@ -56,7 +57,8 @@ class Application extends App { $server->getShareManager(), $server->getSession(), $server->getPreviewManager(), - $server->getRootFolder() + $server->getRootFolder(), + $federatedSharingApp->getFederatedShareProvider() ); }); $container->registerService('ExternalSharesController', function (SimpleContainer $c) { diff --git a/apps/files_sharing/css/3rdparty/gs-share/style.css b/apps/files_sharing/css/3rdparty/gs-share/style.css deleted file mode 100644 index c699ddb3db5..00000000000 --- a/apps/files_sharing/css/3rdparty/gs-share/style.css +++ /dev/null @@ -1,49 +0,0 @@ -.js-gs-share, .gs-share [aria-hidden="true"], .gs-share-form[aria-hidden="true"] { - display: none; -} - -.js-gs-share-enabled .js-gs-share { - display: inline; - float: left; -} - -.gs-share .js-gs-share[href] { - display: inline; -} - -.gs-share [aria-hidden="false"], .gs-share-form[aria-hidden="false"] { - display: block; - margin-top: 40px; -} - -.gs-share { - position: relative; -} - -.gs-share-form { - background: #FFF; - border: 1px solid #000; - border-radius: 5px; - padding: 5px; - position: absolute; - z-index: 1; -} - -.gs-share [for="gs-account"], .gs-share [type="text"] { - display: block; - margin-bottom: 8px; -} - -.gs-share [type="submit"] { - display: block; - margin-top: 8px; -} - -.gs-share--icon { - border: none; - cursor: pointer; - min-height: 32px; - padding: 0; - padding-left: 33px; - background: transparent url('../../../img/gs-share.png') no-repeat left center; -} diff --git a/apps/files_sharing/css/settings-personal.css b/apps/files_sharing/css/settings-personal.css deleted file mode 100644 index f53365c9371..00000000000 --- a/apps/files_sharing/css/settings-personal.css +++ /dev/null @@ -1,33 +0,0 @@ -#fileSharingSettings img { - cursor: pointer; -} - -#fileSharingSettings xmp { - margin-top: 0; - white-space: pre-wrap; -} - -[class^="social-"], [class*=" social-"] { - background-repeat: no-repeat; - background-position: 2px; - min-width: 16px; - min-height: 16px; - padding-left: 29px; - background-size: 24px; -} - -.social-gnu { - background-image: url('../img/social-gnu.svg'); -} -.social-diaspora { - background-image: url('../img/social-diaspora.svg'); -} -.social-twitter { - background-image: url('../img/social-twitter.svg'); -} -.social-facebook { - background-image: url('../img/social-facebook.svg'); -} -.social-googleplus { - background-image: url('../img/social-googleplus.svg'); -} diff --git a/apps/files_sharing/img/social-diaspora.svg b/apps/files_sharing/img/social-diaspora.svg deleted file mode 100644 index 1d5131129a9..00000000000 --- a/apps/files_sharing/img/social-diaspora.svg +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - image/svg+xml - - - - - - - - - diff --git a/apps/files_sharing/img/social-facebook.svg b/apps/files_sharing/img/social-facebook.svg deleted file mode 100644 index aad02bc3853..00000000000 --- a/apps/files_sharing/img/social-facebook.svg +++ /dev/null @@ -1,43 +0,0 @@ - -image/svg+xml \ No newline at end of file diff --git a/apps/files_sharing/img/social-gnu.svg b/apps/files_sharing/img/social-gnu.svg deleted file mode 100644 index 24556aaa024..00000000000 --- a/apps/files_sharing/img/social-gnu.svg +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - - - - - - - - image/svg+xml - - - - - - - - - diff --git a/apps/files_sharing/img/social-googleplus.svg b/apps/files_sharing/img/social-googleplus.svg deleted file mode 100644 index 123273f2d38..00000000000 --- a/apps/files_sharing/img/social-googleplus.svg +++ /dev/null @@ -1,45 +0,0 @@ - -image/svg+xml \ No newline at end of file diff --git a/apps/files_sharing/img/social-twitter.svg b/apps/files_sharing/img/social-twitter.svg deleted file mode 100644 index 00ce390de6b..00000000000 --- a/apps/files_sharing/img/social-twitter.svg +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - image/svg+xml - - - - - - - - - diff --git a/apps/files_sharing/js/3rdparty/gs-share/gs-share.js b/apps/files_sharing/js/3rdparty/gs-share/gs-share.js deleted file mode 100644 index fd4442708a4..00000000000 --- a/apps/files_sharing/js/3rdparty/gs-share/gs-share.js +++ /dev/null @@ -1,206 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// @license magnet:?xt=urn:btih:3877d6d54b3accd4bc32f8a48bf32ebc0901502a&dn=mpl-2.0.txt MPL 2.0 -document.addEventListener('DOMContentLoaded', function () { - 'use strict'; - /** - * 'Share' widget for GNU social - * http://code.chromic.org/project/view/2/ - * - * We make a few assumptions about the target instance: - * 1) The API root is in the default location - * 2) Fancy URLs are enabled - * 3) CORS is allowed - * 4) The Bookmark plugin is enabled - * - * If 1), 3) or 4) are wrong, we fall back to a regular - * notice (instead of a bookmark notice) - * - * If 2) is wrong the user will be directed to a 404 :( - */ - - // TODO: input sanitation [1], [2] - // TODO: server-side fallback if JS is disabled - - var createForm, - bindClicks, - frm, - shareAsNotice, - shareAsBookmark, - extractURLParams, - shareURL, - shareTitle, - closest, - i18n = window.i18n; - - /** - * Internationalization - */ - if (i18n === undefined) { - i18n = { - invalidId: 'The account id provided is invalid', - yourAcctId: 'Your account ID:', - idPlaceholder: 'user@example.org', - shareAsBookmark: 'Share as a bookmark' - }; - } - - shareAsNotice = function (title, url, domain) { - window.open('http://' + domain + '/notice/new?status_textarea=' + title + ' ' + url); // [1] - }; - - shareAsBookmark = function (title, url, domain) { - window.open('http://' + domain + '/main/bookmark/new?url=' + url + '&title=' + title); // [2] - }; - - /** - * Extract parameters from query string - * - * ex: - * ?foo=bar&baz=test - * will return: - * {foo: 'bar', baz: 'test'} - */ - extractURLParams = function (queryStr) { - var parts = queryStr.substr(1).split('&'), - i, len, keyVal, params = {}; - - for (i = 0, len = parts.length; i < len; i += 1) { - keyVal = parts[i].split('='); - params[keyVal[0]] = keyVal[1]; - } - - return params; - }; - - // Create the form that we'll re-use throughout the page - createForm = function () { - var err = document.createElement('div'); - err.setAttribute('class', 'gs-share-err'); - err.setAttribute('tabindex', '-1'); - err.setAttribute('aria-hidden', 'true'); - err.textContent = i18n.invalidId; - - frm = document.createElement('form'); - - frm.setAttribute('class', 'gs-share-form'); - frm.setAttribute('tabindex', '-1'); - frm.setAttribute('aria-hidden', 'true'); - - frm.innerHTML = '' + - '' + - ' ' + - ''; - frm.insertBefore(err, frm.firstChild); - - // Submit handler - frm.addEventListener('submit', function (e) { - e.preventDefault(); - - var accountParts = document.getElementById('gs-account').value.split('@'), - username, domain, xhr, bookmarkURL; - - if (accountParts.length === 2) { - err.setAttribute('aria-hidden', 'true'); - - username = accountParts[0]; - domain = accountParts[1]; - bookmarkURL = 'http://' + domain + '/api/bookmarks/' + username + '.json'; - - // Try bookmark - if (document.getElementById('gs-bookmark').checked) { - xhr = new XMLHttpRequest(); - - xhr.onreadystatechange = function () { - if (xhr.readyState === 4) { - if (xhr.status === 200) { // Success - shareAsBookmark(shareTitle, shareURL, domain); - } else { // Failure, fallback to regular notice - shareAsNotice(shareTitle, shareURL, domain); - } - } - }; - - xhr.open('GET', bookmarkURL, true); - xhr.send(); - } else { // Regular notice - shareAsNotice(shareTitle, shareURL, domain); - } - } else { // Invalid account id - err.setAttribute('aria-hidden', 'false'); - err.focus(); - } - }); - - // Keydown handler - frm.addEventListener('keydown', function (e) { - if (e.keyCode === 27) { // Escape key closes the dialog - frm.parentElement.getElementsByClassName('js-gs-share')[0].focus(); - frm.setAttribute('aria-hidden', 'true'); - } - }); - - document.body.appendChild(frm); - }; - - /** - * Something similar to jQuery.closest - * - * Given `elm`, return the closest parent with class `cls` - * or false if there is no matching ancestor. - */ - closest = function (elm, cls) { - while (elm !== document) { - if (elm.classList.contains(cls)) { - return elm; - } - - elm = elm.parentNode; - } - - return false; - }; - - bindClicks = function () { - document.addEventListener('click', function (e) { - var target = e.target, - urlParams, - lnk = closest(target, 'js-gs-share'); - - // Don't do anything on right/middle click or if ctrl or shift was pressed while left-clicking - if (!e.button && !e.ctrlKey && !e.shiftKey && lnk) { - e.preventDefault(); - - // Check for submission information in href first - if (lnk.search !== undefined) { - urlParams = extractURLParams(lnk.search); - shareURL = urlParams.url; - shareTitle = urlParams.title; - } else { // If it's not there, try data-* attributes. If not, use current document url and title - shareURL = lnk.getAttribute('data-url') || window.location.href; - shareTitle = lnk.getAttribute('data-title') || document.title; - } - - // Move form after the clicked link - lnk.parentNode.appendChild(frm); - - // Show form - frm.setAttribute('aria-hidden', 'false'); - - // Focus on form - frm.focus(); - } else if (!frm.contains(target)) { - frm.setAttribute('aria-hidden', 'true'); - } - }); - }; - - // Flag that js is enabled - document.body.classList.add('js-gs-share-enabled'); - - createForm(); - bindClicks(); -}); -// @license-end diff --git a/apps/files_sharing/js/settings-admin.js b/apps/files_sharing/js/settings-admin.js deleted file mode 100644 index 95578bff548..00000000000 --- a/apps/files_sharing/js/settings-admin.js +++ /dev/null @@ -1,12 +0,0 @@ -$(document).ready(function() { - - $('#fileSharingSettings input').change(function() { - var value = 'no'; - if (this.checked) { - value = 'yes'; - } - OC.AppConfig.setValue('files_sharing', $(this).attr('name'), value); - }); - - $('.section .icon-info').tipsy({gravity: 'w'}); -}); diff --git a/apps/files_sharing/js/settings-personal.js b/apps/files_sharing/js/settings-personal.js deleted file mode 100644 index 14a9b7bbfa7..00000000000 --- a/apps/files_sharing/js/settings-personal.js +++ /dev/null @@ -1,19 +0,0 @@ -$(document).ready(function() { - - $('#fileSharingSettings button.pop-up').click(function() { - var url = $(this).data('url'); - if (url) { - var width = 600; - var height = 400; - var left = (screen.width/2)-(width/2); - var top = (screen.height/2)-(height/2); - - window.open(url, 'name', 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left); - } - }); - - $('#oca-files-sharing-add-to-your-website').click(function() { - $('#oca-files-sharing-add-to-your-website-expanded').slideDown(); - }); - -}); diff --git a/apps/files_sharing/lib/controllers/sharecontroller.php b/apps/files_sharing/lib/controllers/sharecontroller.php index ea024b6016a..72294f6b26f 100644 --- a/apps/files_sharing/lib/controllers/sharecontroller.php +++ b/apps/files_sharing/lib/controllers/sharecontroller.php @@ -33,6 +33,7 @@ namespace OCA\Files_Sharing\Controllers; use OC; use OC_Files; use OC_Util; +use OCA\FederatedFileSharing\FederatedShareProvider; use OCP; use OCP\Template; use OCP\Share; @@ -79,6 +80,8 @@ class ShareController extends Controller { protected $previewManager; /** @var IRootFolder */ protected $rootFolder; + /** @var FederatedShareProvider */ + protected $federatedShareProvider; /** * @param string $appName @@ -92,6 +95,7 @@ class ShareController extends Controller { * @param ISession $session * @param IPreview $previewManager * @param IRootFolder $rootFolder + * @param FederatedShareProvider $federatedShareProvider */ public function __construct($appName, IRequest $request, @@ -103,7 +107,8 @@ class ShareController extends Controller { \OCP\Share\IManager $shareManager, ISession $session, IPreview $previewManager, - IRootFolder $rootFolder) { + IRootFolder $rootFolder, + FederatedShareProvider $federatedShareProvider) { parent::__construct($appName, $request); $this->config = $config; @@ -115,6 +120,7 @@ class ShareController extends Controller { $this->session = $session; $this->previewManager = $previewManager; $this->rootFolder = $rootFolder; + $this->federatedShareProvider = $federatedShareProvider; } /** @@ -300,7 +306,7 @@ class ShareController extends Controller { $shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($share->getNode()->getMimetype()); $shareTmpl['dirToken'] = $token; $shareTmpl['sharingToken'] = $token; - $shareTmpl['server2serversharing'] = Helper::isOutgoingServer2serverShareEnabled(); + $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/helper.php b/apps/files_sharing/lib/helper.php index e857974ae74..c09694e9888 100644 --- a/apps/files_sharing/lib/helper.php +++ b/apps/files_sharing/lib/helper.php @@ -279,26 +279,6 @@ class Helper { return $path; } - /** - * allow users from other ownCloud instances to mount public links share by this instance - * @return bool - */ - public static function isOutgoingServer2serverShareEnabled() { - $appConfig = \OC::$server->getAppConfig(); - $result = $appConfig->getValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes'); - return ($result === 'yes') ? true : false; - } - - /** - * allow user to mount public links from onther ownClouds - * @return bool - */ - public static function isIncomingServer2serverShareEnabled() { - $appConfig = \OC::$server->getAppConfig(); - $result = $appConfig->getValue('files_sharing', 'incoming_server2server_share_enabled', 'yes'); - return ($result === 'yes') ? true : false; - } - /** * get default share folder * diff --git a/apps/files_sharing/lib/share/file.php b/apps/files_sharing/lib/share/file.php index 113675508fb..38605def73a 100644 --- a/apps/files_sharing/lib/share/file.php +++ b/apps/files_sharing/lib/share/file.php @@ -1,4 +1,6 @@ * @author Bart Visscher @@ -40,6 +42,18 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { private $path; + /** @var FederatedShareProvider */ + private $federatedShareProvider; + + public function __construct(FederatedShareProvider $federatedShareProvider = null) { + if ($federatedShareProvider) { + $this->federatedShareProvider = $federatedShareProvider; + } else { + $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application('federatedfilesharing'); + $this->federatedShareProvider = $federatedSharingApp->getFederatedShareProvider(); + } + } + public function isValidSource($itemSource, $uidOwner) { try { $path = \OC\Files\Filesystem::getPath($itemSource); @@ -173,7 +187,7 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent { */ public function isShareTypeAllowed($shareType) { if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { - return \OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled(); + return $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); } return true; diff --git a/apps/files_sharing/settings-admin.php b/apps/files_sharing/settings-admin.php deleted file mode 100644 index b2a305ebcdb..00000000000 --- a/apps/files_sharing/settings-admin.php +++ /dev/null @@ -1,31 +0,0 @@ - - * @author Morris Jobke - * - * @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 - * - */ - -\OC_Util::checkAdminUser(); - -\OCP\Util::addScript('files_sharing', 'settings-admin'); - -$tmpl = new OCP\Template('files_sharing', 'settings-admin'); -$tmpl->assign('outgoingServer2serverShareEnabled', OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled()); -$tmpl->assign('incomingServer2serverShareEnabled', OCA\Files_Sharing\Helper::isIncomingServer2serverShareEnabled()); - -return $tmpl->fetchPage(); diff --git a/apps/files_sharing/settings-personal.php b/apps/files_sharing/settings-personal.php deleted file mode 100644 index 982a8b05c15..00000000000 --- a/apps/files_sharing/settings-personal.php +++ /dev/null @@ -1,47 +0,0 @@ - - * @author Jan-Christoph Borchardt - * @author Thomas Müller - * - * @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 - * - */ - -\OC_Util::checkLoggedIn(); - -$l = \OC::$server->getL10N('files_sharing'); - -$isIE8 = false; -preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches); -if (count($matches) > 0 && $matches[1] <= 9) { - $isIE8 = true; -} - -$cloudID = \OC::$server->getUserSession()->getUser()->getCloudId(); -$url = 'https://owncloud.org/federation#' . $cloudID; -$ownCloudLogoPath = \OC::$server->getURLGenerator()->imagePath('core', 'logo-icon.svg'); - -$tmpl = new OCP\Template('files_sharing', 'settings-personal'); -$tmpl->assign('outgoingServer2serverShareEnabled', \OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled()); -$tmpl->assign('message_with_URL', $l->t('Share with me through my #ownCloud Federated Cloud ID, see %s', [$url])); -$tmpl->assign('message_without_URL', $l->t('Share with me through my #ownCloud Federated Cloud ID', [$cloudID])); -$tmpl->assign('owncloud_logo_path', $ownCloudLogoPath); -$tmpl->assign('reference', $url); -$tmpl->assign('cloudId', $cloudID); -$tmpl->assign('showShareIT', !$isIE8); - -return $tmpl->fetchPage(); diff --git a/apps/files_sharing/templates/settings-admin.php b/apps/files_sharing/templates/settings-admin.php deleted file mode 100644 index 64b6b8e72a3..00000000000 --- a/apps/files_sharing/templates/settings-admin.php +++ /dev/null @@ -1,26 +0,0 @@ - -
-

t('Federated Cloud Sharing'));?>

- - -

- /> - -

- -

- /> -
-

-
diff --git a/apps/files_sharing/templates/settings-personal.php b/apps/files_sharing/templates/settings-personal.php deleted file mode 100644 index ea9aae038a7..00000000000 --- a/apps/files_sharing/templates/settings-personal.php +++ /dev/null @@ -1,78 +0,0 @@ - - - -
-

t('Federated Cloud')); ?>

- -

- t('Your Federated Cloud ID:')); ?> - -

- -
- - -

- t('Share it:')); ?> -

- -
- - - - - -

- - - - -
- diff --git a/apps/files_sharing/tests/controller/sharecontroller.php b/apps/files_sharing/tests/controller/sharecontroller.php index db8c7fe553c..df3973099fb 100644 --- a/apps/files_sharing/tests/controller/sharecontroller.php +++ b/apps/files_sharing/tests/controller/sharecontroller.php @@ -29,6 +29,7 @@ namespace OCA\Files_Sharing\Controllers; use OC\Files\Filesystem; +use OCA\FederatedFileSharing\FederatedShareProvider; use OCP\Share\Exceptions\ShareNotFound; use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Http\RedirectResponse; @@ -66,6 +67,8 @@ class ShareControllerTest extends \Test\TestCase { private $shareManager; /** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject */ private $userManager; + /** @var FederatedShareProvider | \PHPUnit_Framework_MockObject_MockObject */ + private $federatedShareProvider; protected function setUp() { $this->appName = 'files_sharing'; @@ -76,6 +79,12 @@ class ShareControllerTest extends \Test\TestCase { $this->previewManager = $this->getMock('\OCP\IPreview'); $this->config = $this->getMock('\OCP\IConfig'); $this->userManager = $this->getMock('\OCP\IUserManager'); + $this->federatedShareProvider = $this->getMockBuilder('OCA\FederatedFileSharing\FederatedShareProvider') + ->disableOriginalConstructor()->getMock(); + $this->federatedShareProvider->expects($this->any()) + ->method('isOutgoingServer2serverShareEnabled')->willReturn(true); + $this->federatedShareProvider->expects($this->any()) + ->method('isIncomingServer2serverShareEnabled')->willReturn(true); $this->shareController = new \OCA\Files_Sharing\Controllers\ShareController( $this->appName, @@ -88,7 +97,8 @@ class ShareControllerTest extends \Test\TestCase { $this->shareManager, $this->session, $this->previewManager, - $this->getMock('\OCP\Files\IRootFolder') + $this->getMock('\OCP\Files\IRootFolder'), + $this->federatedShareProvider ); diff --git a/apps/files_sharing/tests/server2server.php b/apps/files_sharing/tests/server2server.php index 7714f274c6d..1d047916ca9 100644 --- a/apps/files_sharing/tests/server2server.php +++ b/apps/files_sharing/tests/server2server.php @@ -44,6 +44,9 @@ class Test_Files_Sharing_S2S_OCS_API extends TestCase { */ private $s2s; + /** @var \OCA\FederatedFileSharing\FederatedShareProvider | PHPUnit_Framework_MockObject_MockObject */ + private $federatedShareProvider; + protected function setUp() { parent::setUp(); @@ -57,10 +60,16 @@ class Test_Files_Sharing_S2S_OCS_API extends TestCase { ->setConstructorArgs([$config, $clientService]) ->getMock(); $httpHelperMock->expects($this->any())->method('post')->with($this->anything())->will($this->returnValue(true)); + $this->federatedShareProvider = $this->getMockBuilder('OCA\FederatedFileSharing\FederatedShareProvider') + ->disableOriginalConstructor()->getMock(); + $this->federatedShareProvider->expects($this->any()) + ->method('isOutgoingServer2serverShareEnabled')->willReturn(true); + $this->federatedShareProvider->expects($this->any()) + ->method('isIncomingServer2serverShareEnabled')->willReturn(true); $this->registerHttpHelper($httpHelperMock); - $this->s2s = new \OCA\Files_Sharing\API\Server2Server(); + $this->s2s = new \OCA\Files_Sharing\API\Server2Server($this->federatedShareProvider); $this->connection = \OC::$server->getDatabaseConnection(); } -- cgit v1.2.3