From fa966ebaf1f6584b927c75f3410af29885743c48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 16 Jan 2020 18:42:42 +0100 Subject: [PATCH 1/3] Remove global share accepter since auto-accepting is the default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .../composer/composer/autoload_classmap.php | 1 - .../composer/composer/autoload_static.php | 1 - .../files_sharing/lib/AppInfo/Application.php | 1 - .../GlobalShareAcceptanceListener.php | 63 ------------------- 4 files changed, 66 deletions(-) delete mode 100644 apps/files_sharing/lib/Listener/GlobalShareAcceptanceListener.php diff --git a/apps/files_sharing/composer/composer/autoload_classmap.php b/apps/files_sharing/composer/composer/autoload_classmap.php index 7259ca80d1..8f77798bb8 100644 --- a/apps/files_sharing/composer/composer/autoload_classmap.php +++ b/apps/files_sharing/composer/composer/autoload_classmap.php @@ -48,7 +48,6 @@ return array( 'OCA\\Files_Sharing\\Helper' => $baseDir . '/../lib/Helper.php', 'OCA\\Files_Sharing\\Hooks' => $baseDir . '/../lib/Hooks.php', 'OCA\\Files_Sharing\\ISharedStorage' => $baseDir . '/../lib/ISharedStorage.php', - 'OCA\\Files_Sharing\\Listener\\GlobalShareAcceptanceListener' => $baseDir . '/../lib/Listener/GlobalShareAcceptanceListener.php', 'OCA\\Files_Sharing\\Listener\\LoadAdditionalListener' => $baseDir . '/../lib/Listener/LoadAdditionalListener.php', 'OCA\\Files_Sharing\\Listener\\LoadSidebarListener' => $baseDir . '/../lib/Listener/LoadSidebarListener.php', 'OCA\\Files_Sharing\\Listener\\UserShareAcceptanceListener' => $baseDir . '/../lib/Listener/UserShareAcceptanceListener.php', diff --git a/apps/files_sharing/composer/composer/autoload_static.php b/apps/files_sharing/composer/composer/autoload_static.php index 5894f5d43d..85eb5232bd 100644 --- a/apps/files_sharing/composer/composer/autoload_static.php +++ b/apps/files_sharing/composer/composer/autoload_static.php @@ -63,7 +63,6 @@ class ComposerStaticInitFiles_Sharing 'OCA\\Files_Sharing\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php', 'OCA\\Files_Sharing\\Hooks' => __DIR__ . '/..' . '/../lib/Hooks.php', 'OCA\\Files_Sharing\\ISharedStorage' => __DIR__ . '/..' . '/../lib/ISharedStorage.php', - 'OCA\\Files_Sharing\\Listener\\GlobalShareAcceptanceListener' => __DIR__ . '/..' . '/../lib/Listener/GlobalShareAcceptanceListener.php', 'OCA\\Files_Sharing\\Listener\\LoadAdditionalListener' => __DIR__ . '/..' . '/../lib/Listener/LoadAdditionalListener.php', 'OCA\\Files_Sharing\\Listener\\LoadSidebarListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarListener.php', 'OCA\\Files_Sharing\\Listener\\UserShareAcceptanceListener' => __DIR__ . '/..' . '/../lib/Listener/UserShareAcceptanceListener.php', diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php index af80b85f22..d8019cba24 100644 --- a/apps/files_sharing/lib/AppInfo/Application.php +++ b/apps/files_sharing/lib/AppInfo/Application.php @@ -214,7 +214,6 @@ class Application extends App { $dispatcher->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function() { \OCP\Util::addScript('files_sharing', 'dist/collaboration'); }); - $dispatcher->addServiceListener(ShareCreatedEvent::class, GlobalShareAcceptanceListener::class); $dispatcher->addServiceListener(ShareCreatedEvent::class, UserShareAcceptanceListener::class); // notifications api to accept incoming user shares diff --git a/apps/files_sharing/lib/Listener/GlobalShareAcceptanceListener.php b/apps/files_sharing/lib/Listener/GlobalShareAcceptanceListener.php deleted file mode 100644 index a536646aaa..0000000000 --- a/apps/files_sharing/lib/Listener/GlobalShareAcceptanceListener.php +++ /dev/null @@ -1,63 +0,0 @@ - - * - * @author Roeland Jago Douma - * - * @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\Files_Sharing\Listener; - -use OCP\EventDispatcher\Event; -use OCP\EventDispatcher\IEventListener; -use OCP\IConfig; -use OCP\Share\Events\ShareCreatedEvent; -use OCP\Share\IManager; -use OCP\Share\IShare; - -class GlobalShareAcceptanceListener implements IEventListener { - - /** @var IConfig */ - private $config; - /** @var IManager */ - private $shareManager; - - public function __construct(IConfig $config, IManager $shareManager) { - $this->config = $config; - $this->shareManager = $shareManager; - } - - public function handle(Event $event): void { - if (!($event instanceof ShareCreatedEvent)) { - return; - } - - if ($this->config->getSystemValueBool('sharing.interal_shares_accepted', false)) { - $share = $event->getShare(); - - if ($share->getShareType() === IShare::TYPE_USER || $share->getShareType() === IShare::TYPE_GROUP) { - $share->setStatus(IShare::STATUS_ACCEPTED); - $this->shareManager->updateShare($share); - } - } - } - -} From eb4c42d3d1fda02895d35a360bceb08379f328c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 16 Jan 2020 18:42:58 +0100 Subject: [PATCH 2/3] Make auto accepting the default and provide setting to enforce the share acceptance process MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .../lib/Listener/UserShareAcceptanceListener.php | 5 ++++- apps/files_sharing/lib/Settings/Personal.php | 7 +++++-- .../src/components/PersonalSettings.vue | 8 +++----- config/config.sample.php | 13 +++++++++---- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/apps/files_sharing/lib/Listener/UserShareAcceptanceListener.php b/apps/files_sharing/lib/Listener/UserShareAcceptanceListener.php index f8ce4353c1..382f0b6179 100644 --- a/apps/files_sharing/lib/Listener/UserShareAcceptanceListener.php +++ b/apps/files_sharing/lib/Listener/UserShareAcceptanceListener.php @@ -26,6 +26,7 @@ declare(strict_types=1); namespace OCA\Files_Sharing\Listener; +use OCA\Files_Sharing\AppInfo\Application; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; use OCP\IConfig; @@ -74,7 +75,9 @@ class UserShareAcceptanceListener implements IEventListener { } private function handleAutoAccept(IShare $share, string $userId) { - if ($this->config->getUserValue($userId, 'files_sharing','default_accept','no') === 'yes') { + $defaultAcceptSystemConfig = $this->config->getSystemValueBool('sharing.enable_share_accept', false) ? 'no' : 'yes'; + $acceptDefault = $this->config->getUserValue($userId, Application::APP_ID, 'default_accept', $defaultAcceptSystemConfig) === 'yes'; + if (!$this->config->getSystemValueBool('sharing.force_share_accept', false) && $acceptDefault) { $this->shareManager->acceptShare($share, $userId); } } diff --git a/apps/files_sharing/lib/Settings/Personal.php b/apps/files_sharing/lib/Settings/Personal.php index 25740d8b4f..d6fd7f5f9c 100644 --- a/apps/files_sharing/lib/Settings/Personal.php +++ b/apps/files_sharing/lib/Settings/Personal.php @@ -48,8 +48,11 @@ class Personal implements ISettings { } public function getForm(): TemplateResponse { - $value = $this->config->getUserValue($this->userId, Application::APP_ID, 'default_accept', 'no') === 'yes'; - $this->initialState->provideInitialState(Application::APP_ID, 'accept_default', $value); + $defaultAcceptSystemConfig = $this->config->getSystemValueBool('sharing.enable_share_accept', false) ? 'no' : 'yes'; + $acceptDefault = $this->config->getUserValue($this->userId, Application::APP_ID, 'default_accept', $defaultAcceptSystemConfig) === 'yes'; + $enforceAccept = $this->config->getSystemValueBool('sharing.force_share_accept', false); + $this->initialState->provideInitialState(Application::APP_ID, 'accept_default', $acceptDefault); + $this->initialState->provideInitialState(Application::APP_ID, 'enforce_accept', $enforceAccept); return new TemplateResponse('files_sharing', 'Settings/personal'); } diff --git a/apps/files_sharing/src/components/PersonalSettings.vue b/apps/files_sharing/src/components/PersonalSettings.vue index b6cbbc180b..ec7255480e 100644 --- a/apps/files_sharing/src/components/PersonalSettings.vue +++ b/apps/files_sharing/src/components/PersonalSettings.vue @@ -20,7 +20,7 @@ -->