Skip to content

Commit f4ca386

Browse files
committed
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 <[email protected]>
1 parent 3b8fbf1 commit f4ca386

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

apps/files_sharing/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
'OCA\\Files_Sharing\\Listener\\GlobalShareAcceptanceListener' => $baseDir . '/../lib/Listener/GlobalShareAcceptanceListener.php',
5050
'OCA\\Files_Sharing\\Listener\\LoadAdditionalListener' => $baseDir . '/../lib/Listener/LoadAdditionalListener.php',
5151
'OCA\\Files_Sharing\\Listener\\LoadSidebarListener' => $baseDir . '/../lib/Listener/LoadSidebarListener.php',
52+
'OCA\\Files_Sharing\\Listener\\UserShareAcceptanceListener' => $baseDir . '/../lib/Listener/UserShareAcceptanceListener.php',
5253
'OCA\\Files_Sharing\\Middleware\\OCSShareAPIMiddleware' => $baseDir . '/../lib/Middleware/OCSShareAPIMiddleware.php',
5354
'OCA\\Files_Sharing\\Middleware\\ShareInfoMiddleware' => $baseDir . '/../lib/Middleware/ShareInfoMiddleware.php',
5455
'OCA\\Files_Sharing\\Middleware\\SharingCheckMiddleware' => $baseDir . '/../lib/Middleware/SharingCheckMiddleware.php',

apps/files_sharing/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class ComposerStaticInitFiles_Sharing
6464
'OCA\\Files_Sharing\\Listener\\GlobalShareAcceptanceListener' => __DIR__ . '/..' . '/../lib/Listener/GlobalShareAcceptanceListener.php',
6565
'OCA\\Files_Sharing\\Listener\\LoadAdditionalListener' => __DIR__ . '/..' . '/../lib/Listener/LoadAdditionalListener.php',
6666
'OCA\\Files_Sharing\\Listener\\LoadSidebarListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarListener.php',
67+
'OCA\\Files_Sharing\\Listener\\UserShareAcceptanceListener' => __DIR__ . '/..' . '/../lib/Listener/UserShareAcceptanceListener.php',
6768
'OCA\\Files_Sharing\\Middleware\\OCSShareAPIMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/OCSShareAPIMiddleware.php',
6869
'OCA\\Files_Sharing\\Middleware\\ShareInfoMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/ShareInfoMiddleware.php',
6970
'OCA\\Files_Sharing\\Middleware\\SharingCheckMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/SharingCheckMiddleware.php',

apps/files_sharing/lib/AppInfo/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use OCA\Files_Sharing\Listener\GlobalShareAcceptanceListener;
3939
use OCA\Files_Sharing\Listener\LoadAdditionalListener;
4040
use OCA\Files_Sharing\Listener\LoadSidebarListener;
41+
use OCA\Files_Sharing\Listener\UserShareAcceptanceListener;
4142
use OCA\Files_Sharing\Middleware\OCSShareAPIMiddleware;
4243
use OCA\Files_Sharing\Middleware\ShareInfoMiddleware;
4344
use OCA\Files_Sharing\Middleware\SharingCheckMiddleware;
@@ -213,6 +214,7 @@ protected function registerEventsScripts(IEventDispatcher $dispatcher) {
213214
\OCP\Util::addScript('files_sharing', 'dist/collaboration');
214215
});
215216
$dispatcher->addServiceListener(ShareCreatedEvent::class, GlobalShareAcceptanceListener::class);
217+
$dispatcher->addServiceListener(ShareCreatedEvent::class, UserShareAcceptanceListener::class);
216218

217219
// notifications api to accept incoming user shares
218220
$dispatcher->addListener('OCP\Share::postShare', function(GenericEvent $event) {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* @copyright Copyright (c) 2019, Roeland Jago Douma <[email protected]>
5+
*
6+
* @author Roeland Jago Douma <[email protected]>
7+
*
8+
* @license GNU AGPL version 3 or any later version
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Affero General Public License as
12+
* published by the Free Software Foundation, either version 3 of the
13+
* License, or (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Affero General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*
23+
*/
24+
25+
namespace OCA\Files_Sharing\Listener;
26+
27+
use OCP\EventDispatcher\Event;
28+
use OCP\EventDispatcher\IEventListener;
29+
use OCP\IConfig;
30+
use OCP\Share\Events\SharedEvent;
31+
use OCP\Share\IManager;
32+
33+
class UserShareAcceptanceListener implements IEventListener {
34+
35+
/** @var IConfig */
36+
private $config;
37+
/** @var IManager */
38+
private $shareManager;
39+
/** @var string */
40+
private $userId;
41+
42+
public function __construct(IConfig $config, IManager $shareManager, string $userId) {
43+
$this->config = $config;
44+
$this->shareManager = $shareManager;
45+
$this->userId = $userId;
46+
}
47+
48+
public function handle(Event $event): void {
49+
if (!($event instanceof SharedEvent)) {
50+
return;
51+
}
52+
53+
if ($this->config->getUserValue($this->userId, 'files_sharing','default_accept','no') === 'yes') {
54+
$share = $event->getShare();
55+
$this->shareManager->acceptShare($share, $this->userId);
56+
}
57+
}
58+
59+
}

0 commit comments

Comments
 (0)