From 42a6ac89bb2b760a22e072776f4f60a15aae69b5 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 26 Apr 2021 15:52:06 +0200 Subject: [PATCH] No longer add trusted servers on federated share creation It was disabled by default for ages. And often resulted in unwanted behavior. If admins want trusted servers they just have to do it manually. Signed-off-by: Roeland Jago Douma --- apps/federation/appinfo/routes.php | 5 -- .../composer/composer/autoload_classmap.php | 1 - .../composer/composer/autoload_static.php | 1 - apps/federation/js/settings-admin.js | 24 +++----- apps/federation/lib/AppInfo/Application.php | 3 - .../lib/Controller/SettingsController.php | 10 ---- .../Listener/FederatedShareAddedListener.php | 60 ------------------- apps/federation/templates/settings-admin.php | 7 --- 8 files changed, 7 insertions(+), 104 deletions(-) delete mode 100644 apps/federation/lib/Listener/FederatedShareAddedListener.php diff --git a/apps/federation/appinfo/routes.php b/apps/federation/appinfo/routes.php index 706bbdc000..15ade1536b 100644 --- a/apps/federation/appinfo/routes.php +++ b/apps/federation/appinfo/routes.php @@ -34,11 +34,6 @@ return [ 'url' => '/trusted-servers/{id}', 'verb' => 'DELETE' ], - [ - 'name' => 'Settings#autoAddServers', - 'url' => '/auto-add-servers', - 'verb' => 'POST' - ], ], 'ocs' => [ // old endpoints, only used by Nextcloud and ownCloud diff --git a/apps/federation/composer/composer/autoload_classmap.php b/apps/federation/composer/composer/autoload_classmap.php index dbc840a455..f1599e51e2 100644 --- a/apps/federation/composer/composer/autoload_classmap.php +++ b/apps/federation/composer/composer/autoload_classmap.php @@ -15,7 +15,6 @@ return array( 'OCA\\Federation\\DAV\\FedAuth' => $baseDir . '/../lib/DAV/FedAuth.php', 'OCA\\Federation\\DbHandler' => $baseDir . '/../lib/DbHandler.php', 'OCA\\Federation\\Hooks' => $baseDir . '/../lib/Hooks.php', - 'OCA\\Federation\\Listener\\FederatedShareAddedListener' => $baseDir . '/../lib/Listener/FederatedShareAddedListener.php', 'OCA\\Federation\\Listener\\SabrePluginAuthInitListener' => $baseDir . '/../lib/Listener/SabrePluginAuthInitListener.php', 'OCA\\Federation\\Middleware\\AddServerMiddleware' => $baseDir . '/../lib/Middleware/AddServerMiddleware.php', 'OCA\\Federation\\Migration\\Version1010Date20200630191302' => $baseDir . '/../lib/Migration/Version1010Date20200630191302.php', diff --git a/apps/federation/composer/composer/autoload_static.php b/apps/federation/composer/composer/autoload_static.php index 14db3ca9f8..a429bcae51 100644 --- a/apps/federation/composer/composer/autoload_static.php +++ b/apps/federation/composer/composer/autoload_static.php @@ -30,7 +30,6 @@ class ComposerStaticInitFederation 'OCA\\Federation\\DAV\\FedAuth' => __DIR__ . '/..' . '/../lib/DAV/FedAuth.php', 'OCA\\Federation\\DbHandler' => __DIR__ . '/..' . '/../lib/DbHandler.php', 'OCA\\Federation\\Hooks' => __DIR__ . '/..' . '/../lib/Hooks.php', - 'OCA\\Federation\\Listener\\FederatedShareAddedListener' => __DIR__ . '/..' . '/../lib/Listener/FederatedShareAddedListener.php', 'OCA\\Federation\\Listener\\SabrePluginAuthInitListener' => __DIR__ . '/..' . '/../lib/Listener/SabrePluginAuthInitListener.php', 'OCA\\Federation\\Middleware\\AddServerMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/AddServerMiddleware.php', 'OCA\\Federation\\Migration\\Version1010Date20200630191302' => __DIR__ . '/..' . '/../lib/Migration/Version1010Date20200630191302.php', diff --git a/apps/federation/js/settings-admin.js b/apps/federation/js/settings-admin.js index 251ea4c4a3..d8ec194dcd 100644 --- a/apps/federation/js/settings-admin.js +++ b/apps/federation/js/settings-admin.js @@ -19,7 +19,7 @@ */ (function( $ ) { - + // ocFederationAddServer $.fn.ocFederationAddServer = function() { @@ -27,14 +27,13 @@ ========================================================================== */ var $wrapper = $(this), - + // Buttons $btnAddServer = $wrapper.find("#ocFederationAddServerButton"), $btnSubmit = $wrapper.find("#ocFederationSubmit"), - + // Inputs $inpServerUrl = $wrapper.find("#serverUrl"), - $inpAutoAddServers = $wrapper.find("#autoAddServers"), // misc $msgBox = $wrapper.find("#ocFederationAddServer .msg"), @@ -55,17 +54,8 @@ $srvList.on('click', 'li > .icon-delete', function() { var $this = $(this).parent(); var id = $this.attr('id'); - - removeServer( id ); - }); - $inpAutoAddServers.on("change", function() { - $.post( - OC.generateUrl('/apps/federation/auto-add-servers'), - { - autoAddServers: $(this).is(":checked") - } - ); + removeServer( id ); }); $btnSubmit.on("click", function() @@ -94,7 +84,7 @@ } }); }; - + /* private Functions ========================================================================== */ @@ -132,11 +122,11 @@ }); } - + })( jQuery ); window.addEventListener('DOMContentLoaded', function () { $('#ocFederationSettings').ocFederationAddServer(); - + }); diff --git a/apps/federation/lib/AppInfo/Application.php b/apps/federation/lib/AppInfo/Application.php index bab9565eba..72e96d8529 100644 --- a/apps/federation/lib/AppInfo/Application.php +++ b/apps/federation/lib/AppInfo/Application.php @@ -26,8 +26,6 @@ namespace OCA\Federation\AppInfo; use OCA\DAV\Events\SabrePluginAuthInitEvent; -use OCA\FederatedFileSharing\Events\FederatedShareAddedEvent; -use OCA\Federation\Listener\FederatedShareAddedListener; use OCA\Federation\Listener\SabrePluginAuthInitListener; use OCA\Federation\Middleware\AddServerMiddleware; use OCP\AppFramework\App; @@ -47,7 +45,6 @@ class Application extends App implements IBootstrap { public function register(IRegistrationContext $context): void { $context->registerMiddleware(AddServerMiddleware::class); - $context->registerEventListener(FederatedShareAddedEvent::class, FederatedShareAddedListener::class); $context->registerEventListener(SabrePluginAuthInitEvent::class, SabrePluginAuthInitListener::class); } diff --git a/apps/federation/lib/Controller/SettingsController.php b/apps/federation/lib/Controller/SettingsController.php index 7f68f23836..853dc2584c 100644 --- a/apps/federation/lib/Controller/SettingsController.php +++ b/apps/federation/lib/Controller/SettingsController.php @@ -87,16 +87,6 @@ class SettingsController extends Controller { return new DataResponse(); } - /** - * enable/disable to automatically add servers to the list of trusted servers - * once a federated share was created and accepted successfully - * - * @param bool $autoAddServers - */ - public function autoAddServers($autoAddServers) { - $this->trustedServers->setAutoAddServers($autoAddServers); - } - /** * check if the server should be added to the list of trusted servers or not * diff --git a/apps/federation/lib/Listener/FederatedShareAddedListener.php b/apps/federation/lib/Listener/FederatedShareAddedListener.php deleted file mode 100644 index 21eb945077..0000000000 --- a/apps/federation/lib/Listener/FederatedShareAddedListener.php +++ /dev/null @@ -1,60 +0,0 @@ - - * - * @author Morris Jobke - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * 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 - * along with this program. If not, see . - * - */ - -namespace OCA\Federation\Listener; - -use OCA\FederatedFileSharing\Events\FederatedShareAddedEvent; -use OCA\Federation\TrustedServers; -use OCP\EventDispatcher\Event; -use OCP\EventDispatcher\IEventListener; - -/** - * Automatically add new servers to the list of trusted servers. - * - * @since 20.0.0 - */ -class FederatedShareAddedListener implements IEventListener { - /** @var TrustedServers */ - private $trustedServers; - - public function __construct(TrustedServers $trustedServers) { - $this->trustedServers = $trustedServers; - } - - public function handle(Event $event): void { - if (!($event instanceof FederatedShareAddedEvent)) { - return; - } - - $server = $event->getRemote(); - if ( - $this->trustedServers->getAutoAddServers() === true && - $this->trustedServers->isTrustedServer($server) === false - ) { - $this->trustedServers->addServer($server); - } - } -} diff --git a/apps/federation/templates/settings-admin.php b/apps/federation/templates/settings-admin.php index 407a1fa944..3fa7a02a02 100644 --- a/apps/federation/templates/settings-admin.php +++ b/apps/federation/templates/settings-admin.php @@ -10,13 +10,6 @@ style('federation', 'settings-admin')

t('Trusted servers')); ?>

t('Federation allows you to connect with other trusted servers to exchange the user directory. For example this will be used to auto-complete external users for federated sharing. It is not necessary to add a server as trusted server in order to create a federated share.')); ?>

-

- /> - -

-