diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2019-12-12 21:45:59 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2019-12-17 10:49:29 +0100 |
commit | e7dc91002f87385547528f8ac507b037c0f6be93 (patch) | |
tree | a8605f6bd53ea44817daa1f343f45debcb89ff08 /apps/files_sharing/lib | |
parent | 76895b6945f64b25d56a55c70585c441743eb226 (diff) | |
download | nextcloud-server-e7dc91002f87385547528f8ac507b037c0f6be93.tar.gz nextcloud-server-e7dc91002f87385547528f8ac507b037c0f6be93.zip |
Allow users to specify to accept (internal) shares by default
Fixes #18255
A new user setting allows a user to always accept (internal) shares. For
example if they don't like accepting shares manually ;)
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/files_sharing/lib')
4 files changed, 177 insertions, 0 deletions
diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php index 840f8a809ff..48802617b4f 100644 --- a/apps/files_sharing/lib/AppInfo/Application.php +++ b/apps/files_sharing/lib/AppInfo/Application.php @@ -38,6 +38,7 @@ use OCA\Files_Sharing\External\Manager; use OCA\Files_Sharing\Listener\GlobalShareAcceptanceListener; use OCA\Files_Sharing\Listener\LoadAdditionalListener; use OCA\Files_Sharing\Listener\LoadSidebarListener; +use OCA\Files_Sharing\Listener\UserShareAcceptanceListener; use OCA\Files_Sharing\Middleware\OCSShareAPIMiddleware; use OCA\Files_Sharing\Middleware\ShareInfoMiddleware; use OCA\Files_Sharing\Middleware\SharingCheckMiddleware; @@ -213,6 +214,7 @@ class Application extends App { \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 $dispatcher->addListener('OCP\Share::postShare', function(GenericEvent $event) { diff --git a/apps/files_sharing/lib/Controller/SettingsController.php b/apps/files_sharing/lib/Controller/SettingsController.php new file mode 100644 index 00000000000..9846e7750de --- /dev/null +++ b/apps/files_sharing/lib/Controller/SettingsController.php @@ -0,0 +1,54 @@ +<?php +declare(strict_types=1); +/** + * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl> + * + * @author Roeland Jago Douma <roeland@famdouma.nl> + * + * @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 <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\Files_Sharing\Controller; + +use OCA\Files_Sharing\AppInfo\Application; +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\JSONResponse; +use OCP\IConfig; +use OCP\IRequest; + +class SettingsController extends Controller { + + /** @var IConfig */ + private $config; + /** @var string */ + private $userId; + + public function __construct(IRequest $request, IConfig $config, string $userId) { + parent::__construct(Application::APP_ID, $request); + + $this->config = $config; + $this->userId = $userId; + } + + /** + * @NoAdminRequired + */ + public function setDefaultAccept(bool $accept): JSONResponse { + $this->config->setUserValue($this->userId, Application::APP_ID, 'default_accept', $accept ? 'yes' : 'no'); + return new JSONResponse(); + } +} diff --git a/apps/files_sharing/lib/Listener/UserShareAcceptanceListener.php b/apps/files_sharing/lib/Listener/UserShareAcceptanceListener.php new file mode 100644 index 00000000000..041f66c54e7 --- /dev/null +++ b/apps/files_sharing/lib/Listener/UserShareAcceptanceListener.php @@ -0,0 +1,59 @@ +<?php +declare(strict_types=1); +/** + * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl> + * + * @author Roeland Jago Douma <roeland@famdouma.nl> + * + * @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 <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\Files_Sharing\Listener; + +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\IConfig; +use OCP\Share\Events\SharedEvent; +use OCP\Share\IManager; + +class UserShareAcceptanceListener implements IEventListener { + + /** @var IConfig */ + private $config; + /** @var IManager */ + private $shareManager; + /** @var string */ + private $userId; + + public function __construct(IConfig $config, IManager $shareManager, string $userId) { + $this->config = $config; + $this->shareManager = $shareManager; + $this->userId = $userId; + } + + public function handle(Event $event): void { + if (!($event instanceof SharedEvent)) { + return; + } + + if ($this->config->getUserValue($this->userId, 'files_sharing','default_accept','no') === 'yes') { + $share = $event->getShare(); + $this->shareManager->acceptShare($share, $this->userId); + } + } + +} diff --git a/apps/files_sharing/lib/Settings/Personal.php b/apps/files_sharing/lib/Settings/Personal.php new file mode 100644 index 00000000000..73caa47bf42 --- /dev/null +++ b/apps/files_sharing/lib/Settings/Personal.php @@ -0,0 +1,62 @@ +<?php +declare(strict_types=1); +/** + * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl> + * + * @author Roeland Jago Douma <roeland@famdouma.nl> + * + * @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 <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\Files_Sharing\Settings; + +use OCA\Files_Sharing\AppInfo\Application; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use OCP\IInitialStateService; +use OCP\Settings\ISettings; + +class Personal implements ISettings { + + /** @var IConfig */ + private $config; + /** @var IInitialStateService */ + private $initialState; + /** @var string */ + private $userId; + + public function __construct(IConfig $config, IInitialStateService $initialState, string $userId) { + $this->config = $config; + $this->initialState = $initialState; + $this->userId = $userId; + } + + 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); + return new TemplateResponse('files_sharing', 'Settings/personal'); + } + + public function getSection(): string { + return 'sharing'; + } + + public function getPriority(): int { + return 90; + } + +} |