config.php setting to always accept internal shares
Part of #18255 Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
87104ce510
commit
bb4264c565
|
@ -46,6 +46,7 @@ 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\\Middleware\\OCSShareAPIMiddleware' => $baseDir . '/../lib/Middleware/OCSShareAPIMiddleware.php',
|
||||
|
|
|
@ -61,6 +61,7 @@ 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\\Middleware\\OCSShareAPIMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/OCSShareAPIMiddleware.php',
|
||||
|
|
|
@ -35,6 +35,7 @@ use OCA\Files_Sharing\Capabilities;
|
|||
use OCA\Files_Sharing\Controller\ExternalSharesController;
|
||||
use OCA\Files_Sharing\Controller\ShareController;
|
||||
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\Middleware\OCSShareAPIMiddleware;
|
||||
|
@ -54,6 +55,7 @@ use OCP\Files\Config\IMountProviderCollection;
|
|||
use OCP\IContainer;
|
||||
use OCP\IGroup;
|
||||
use OCP\IServerContainer;
|
||||
use OCP\Share\Events\ShareCreatedEvent;
|
||||
use OCP\Util;
|
||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||
|
||||
|
@ -210,6 +212,7 @@ class Application extends App {
|
|||
$dispatcher->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function() {
|
||||
\OCP\Util::addScript('files_sharing', 'dist/collaboration');
|
||||
});
|
||||
$dispatcher->addServiceListener(ShareCreatedEvent::class, GlobalShareAcceptanceListener::class);
|
||||
|
||||
// notifications api to accept incoming user shares
|
||||
$dispatcher->addListener('OCP\Share::postShare', function(GenericEvent $event) {
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
<?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\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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1338,6 +1338,13 @@ $CONFIG = array(
|
|||
*/
|
||||
'sharing.minSearchStringLength' => 0,
|
||||
|
||||
/**
|
||||
* Starting with Nextcloud 18 also internal shares have to be accepted. Setting
|
||||
* this setting to true forces all internal shares to be accepted directly.
|
||||
* (resulting in pre 18 behavior).
|
||||
*/
|
||||
'sharing.interal_shares_accepted' => false,
|
||||
|
||||
/**
|
||||
* All other configuration options
|
||||
*/
|
||||
|
|
|
@ -418,6 +418,7 @@ return array(
|
|||
'OCP\\Settings\\ISettings' => $baseDir . '/lib/public/Settings/ISettings.php',
|
||||
'OCP\\Settings\\ISubAdminSettings' => $baseDir . '/lib/public/Settings/ISubAdminSettings.php',
|
||||
'OCP\\Share' => $baseDir . '/lib/public/Share.php',
|
||||
'OCP\\Share\\Events\\ShareCreatedEvent' => $baseDir . '/lib/public/Share/Events/ShareCreatedEvent.php',
|
||||
'OCP\\Share\\Exceptions\\GenericShareException' => $baseDir . '/lib/public/Share/Exceptions/GenericShareException.php',
|
||||
'OCP\\Share\\Exceptions\\IllegalIDChangeException' => $baseDir . '/lib/public/Share/Exceptions/IllegalIDChangeException.php',
|
||||
'OCP\\Share\\Exceptions\\ShareNotFound' => $baseDir . '/lib/public/Share/Exceptions/ShareNotFound.php',
|
||||
|
|
|
@ -447,6 +447,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
|
|||
'OCP\\Settings\\ISettings' => __DIR__ . '/../../..' . '/lib/public/Settings/ISettings.php',
|
||||
'OCP\\Settings\\ISubAdminSettings' => __DIR__ . '/../../..' . '/lib/public/Settings/ISubAdminSettings.php',
|
||||
'OCP\\Share' => __DIR__ . '/../../..' . '/lib/public/Share.php',
|
||||
'OCP\\Share\\Events\\ShareCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/Share/Events/ShareCreatedEvent.php',
|
||||
'OCP\\Share\\Exceptions\\GenericShareException' => __DIR__ . '/../../..' . '/lib/public/Share/Exceptions/GenericShareException.php',
|
||||
'OCP\\Share\\Exceptions\\IllegalIDChangeException' => __DIR__ . '/../../..' . '/lib/public/Share/Exceptions/IllegalIDChangeException.php',
|
||||
'OCP\\Share\\Exceptions\\ShareNotFound' => __DIR__ . '/../../..' . '/lib/public/Share/Exceptions/ShareNotFound.php',
|
||||
|
|
|
@ -1171,7 +1171,8 @@ class Server extends ServerContainer implements IServerContainer {
|
|||
$c->getEventDispatcher(),
|
||||
$c->getMailer(),
|
||||
$c->getURLGenerator(),
|
||||
$c->getThemingDefaults()
|
||||
$c->getThemingDefaults(),
|
||||
$c->query(IEventDispatcher::class)
|
||||
);
|
||||
|
||||
return $manager;
|
||||
|
|
|
@ -44,6 +44,7 @@ use OC\Cache\CappedMemoryCache;
|
|||
use OC\Files\Mount\MoveableMount;
|
||||
use OC\HintException;
|
||||
use OC\Share20\Exception\ProviderException;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Files\File;
|
||||
use OCP\Files\Folder;
|
||||
use OCP\Files\IRootFolder;
|
||||
|
@ -101,7 +102,7 @@ class Manager implements IManager {
|
|||
/** @var CappedMemoryCache */
|
||||
private $sharingDisabledForUsersCache;
|
||||
/** @var EventDispatcherInterface */
|
||||
private $eventDispatcher;
|
||||
private $legacyDispatcher;
|
||||
/** @var LegacyHooks */
|
||||
private $legacyHooks;
|
||||
/** @var IMailer */
|
||||
|
@ -110,6 +111,8 @@ class Manager implements IManager {
|
|||
private $urlGenerator;
|
||||
/** @var \OC_Defaults */
|
||||
private $defaults;
|
||||
/** @var IEventDispatcher */
|
||||
private $dispatcher;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -143,10 +146,11 @@ class Manager implements IManager {
|
|||
IProviderFactory $factory,
|
||||
IUserManager $userManager,
|
||||
IRootFolder $rootFolder,
|
||||
EventDispatcherInterface $eventDispatcher,
|
||||
EventDispatcherInterface $legacyDispatcher,
|
||||
IMailer $mailer,
|
||||
IURLGenerator $urlGenerator,
|
||||
\OC_Defaults $defaults
|
||||
\OC_Defaults $defaults,
|
||||
IEventDispatcher $dispatcher
|
||||
) {
|
||||
$this->logger = $logger;
|
||||
$this->config = $config;
|
||||
|
@ -159,12 +163,13 @@ class Manager implements IManager {
|
|||
$this->factory = $factory;
|
||||
$this->userManager = $userManager;
|
||||
$this->rootFolder = $rootFolder;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
$this->legacyDispatcher = $legacyDispatcher;
|
||||
$this->sharingDisabledForUsersCache = new CappedMemoryCache();
|
||||
$this->legacyHooks = new LegacyHooks($this->eventDispatcher);
|
||||
$this->legacyHooks = new LegacyHooks($this->legacyDispatcher);
|
||||
$this->mailer = $mailer;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->defaults = $defaults;
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -195,7 +200,7 @@ class Manager implements IManager {
|
|||
|
||||
// Let others verify the password
|
||||
try {
|
||||
$this->eventDispatcher->dispatch(new ValidatePasswordPolicyEvent($password));
|
||||
$this->legacyDispatcher->dispatch(new ValidatePasswordPolicyEvent($password));
|
||||
} catch (HintException $e) {
|
||||
throw new \Exception($e->getHint());
|
||||
}
|
||||
|
@ -766,7 +771,7 @@ class Manager implements IManager {
|
|||
|
||||
// Pre share event
|
||||
$event = new GenericEvent($share);
|
||||
$this->eventDispatcher->dispatch('OCP\Share::preShare', $event);
|
||||
$this->legacyDispatcher->dispatch('OCP\Share::preShare', $event);
|
||||
if ($event->isPropagationStopped() && $event->hasArgument('error')) {
|
||||
throw new \Exception($event->getArgument('error'));
|
||||
}
|
||||
|
@ -779,7 +784,9 @@ class Manager implements IManager {
|
|||
|
||||
// Post share event
|
||||
$event = new GenericEvent($share);
|
||||
$this->eventDispatcher->dispatch('OCP\Share::postShare', $event);
|
||||
$this->legacyDispatcher->dispatch('OCP\Share::postShare', $event);
|
||||
|
||||
$this->dispatcher->dispatchTyped(new Share\Events\ShareCreatedEvent($share));
|
||||
|
||||
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
|
||||
$mailSend = $share->getMailSend();
|
||||
|
@ -1041,7 +1048,7 @@ class Manager implements IManager {
|
|||
}
|
||||
$provider->acceptShare($share, $recipientId);
|
||||
$event = new GenericEvent($share);
|
||||
$this->eventDispatcher->dispatch('OCP\Share::postAcceptShare', $event);
|
||||
$this->legacyDispatcher->dispatch('OCP\Share::postAcceptShare', $event);
|
||||
|
||||
return $share;
|
||||
}
|
||||
|
@ -1111,7 +1118,7 @@ class Manager implements IManager {
|
|||
}
|
||||
|
||||
$event = new GenericEvent($share);
|
||||
$this->eventDispatcher->dispatch('OCP\Share::preUnshare', $event);
|
||||
$this->legacyDispatcher->dispatch('OCP\Share::preUnshare', $event);
|
||||
|
||||
// Get all children and delete them as well
|
||||
$deletedShares = $this->deleteChildren($share);
|
||||
|
@ -1125,7 +1132,7 @@ class Manager implements IManager {
|
|||
|
||||
// Emit post hook
|
||||
$event->setArgument('deletedShares', $deletedShares);
|
||||
$this->eventDispatcher->dispatch('OCP\Share::postUnshare', $event);
|
||||
$this->legacyDispatcher->dispatch('OCP\Share::postUnshare', $event);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1144,7 +1151,7 @@ class Manager implements IManager {
|
|||
|
||||
$provider->deleteFromSelf($share, $recipientId);
|
||||
$event = new GenericEvent($share);
|
||||
$this->eventDispatcher->dispatch('OCP\Share::postUnshareFromSelf', $event);
|
||||
$this->legacyDispatcher->dispatch('OCP\Share::postUnshareFromSelf', $event);
|
||||
}
|
||||
|
||||
public function restoreShare(IShare $share, string $recipientId): IShare {
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
<?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 OCP\Share\Events;
|
||||
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\Share\IShare;
|
||||
|
||||
/**
|
||||
* @since 18.0.0
|
||||
*/
|
||||
class ShareCreatedEvent extends Event {
|
||||
|
||||
/** @var IShare */
|
||||
private $share;
|
||||
|
||||
/**
|
||||
* @since 18.0.0
|
||||
*/
|
||||
public function __construct(IShare $share) {
|
||||
parent::__construct();
|
||||
|
||||
$this->share = $share;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 18.0.0
|
||||
*/
|
||||
public function getShare(): IShare {
|
||||
return $this->share;
|
||||
}
|
||||
}
|
|
@ -28,6 +28,7 @@ use OC\Share20\Exception;
|
|||
use OC\Share20\Manager;
|
||||
use OC\Share20\Share;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Files\File;
|
||||
use OCP\Files\Folder;
|
||||
use OCP\Files\IRootFolder;
|
||||
|
@ -94,6 +95,8 @@ class ManagerTest extends \Test\TestCase {
|
|||
protected $rootFolder;
|
||||
/** @var EventDispatcherInterface | MockObject */
|
||||
protected $eventDispatcher;
|
||||
/** @var IEventDispatcher|MockObject */
|
||||
protected $dispatcher;
|
||||
/** @var IMailer|MockObject */
|
||||
protected $mailer;
|
||||
/** @var IURLGenerator|MockObject */
|
||||
|
@ -115,6 +118,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->mailer = $this->createMock(IMailer::class);
|
||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||
$this->defaults = $this->createMock(\OC_Defaults::class);
|
||||
$this->dispatcher = $this->createMock(IEventDispatcher::class);
|
||||
|
||||
$this->l10nFactory = $this->createMock(IFactory::class);
|
||||
$this->l = $this->createMock(IL10N::class);
|
||||
|
@ -140,7 +144,8 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->eventDispatcher,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults
|
||||
$this->defaults,
|
||||
$this->dispatcher
|
||||
);
|
||||
|
||||
$this->defaultProvider = $this->createMock(DefaultShareProvider::class);
|
||||
|
@ -168,7 +173,8 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->eventDispatcher,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults
|
||||
$this->defaults,
|
||||
$this->dispatcher
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -2192,7 +2198,8 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->eventDispatcher,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults
|
||||
$this->defaults,
|
||||
$this->dispatcher
|
||||
);
|
||||
|
||||
$share = $this->createMock(IShare::class);
|
||||
|
@ -2235,7 +2242,8 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->eventDispatcher,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults
|
||||
$this->defaults,
|
||||
$this->dispatcher
|
||||
);
|
||||
|
||||
$share = $this->createMock(IShare::class);
|
||||
|
@ -2285,7 +2293,8 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->eventDispatcher,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults
|
||||
$this->defaults,
|
||||
$this->dispatcher
|
||||
);
|
||||
|
||||
$share = $this->createMock(IShare::class);
|
||||
|
@ -3375,7 +3384,8 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->eventDispatcher,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults
|
||||
$this->defaults,
|
||||
$this->dispatcher
|
||||
);
|
||||
$this->assertSame($expected,
|
||||
$manager->shareProviderExists($shareType)
|
||||
|
@ -3407,7 +3417,8 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->eventDispatcher,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults
|
||||
$this->defaults,
|
||||
$this->dispatcher
|
||||
);
|
||||
|
||||
$factory->setProvider($this->defaultProvider);
|
||||
|
@ -3470,7 +3481,8 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->eventDispatcher,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults
|
||||
$this->defaults,
|
||||
$this->dispatcher
|
||||
);
|
||||
|
||||
$factory->setProvider($this->defaultProvider);
|
||||
|
@ -3586,7 +3598,8 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->eventDispatcher,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults
|
||||
$this->defaults,
|
||||
$this->dispatcher
|
||||
);
|
||||
|
||||
$factory->setProvider($this->defaultProvider);
|
||||
|
@ -3711,7 +3724,8 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->eventDispatcher,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults
|
||||
$this->defaults,
|
||||
$this->dispatcher
|
||||
);
|
||||
|
||||
$factory->setProvider($this->defaultProvider);
|
||||
|
|
Loading…
Reference in New Issue