Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config.php setting to always accept internal shares #18384

Merged
merged 1 commit into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/files_sharing/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
'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',
Expand Down
1 change: 1 addition & 0 deletions apps/files_sharing/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
13 changes: 8 additions & 5 deletions apps/files_sharing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
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;
Expand All @@ -54,6 +55,7 @@
use OCP\IContainer;
use OCP\IGroup;
use OCP\IServerContainer;
use OCP\Share\Events\ShareCreatedEvent;
use OCP\Util;
use Symfony\Component\EventDispatcher\GenericEvent;

Expand Down Expand Up @@ -210,6 +212,7 @@ protected function registerEventsScripts(IEventDispatcher $dispatcher) {
$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) {
Expand All @@ -233,7 +236,7 @@ protected function setupSharingMenus() {
}

$sharingSublistArray = [];

if (\OCP\Util::isSharingDisabledForUser() === false) {
array_push($sharingSublistArray, [
'id' => 'sharingout',
Expand All @@ -243,15 +246,15 @@ protected function setupSharingMenus() {
'name' => $l->t('Shared with others'),
]);
}

array_push($sharingSublistArray, [
'id' => 'sharingin',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 15,
'name' => $l->t('Shared with you'),
]);

if (\OCP\Util::isSharingDisabledForUser() === false) {
// Check if sharing by link is enabled
if ($config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes') {
Expand All @@ -264,15 +267,15 @@ protected function setupSharingMenus() {
]);
}
}

array_push($sharingSublistArray, [
'id' => 'deletedshares',
'appname' => 'files_sharing',
'script' => 'list.php',
'order' => 19,
'name' => $l->t('Deleted shares'),
]);

// show_Quick_Access stored as string
\OCA\Files\App::getNavigationManager()->add([
'id' => 'shareoverview',
Expand Down
61 changes: 61 additions & 0 deletions apps/files_sharing/lib/Listener/GlobalShareAcceptanceListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2019, Roeland Jago Douma <[email protected]>
*
* @author Roeland Jago Douma <[email protected]>
*
* @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)) {
rullzer marked this conversation as resolved.
Show resolved Hide resolved
$share = $event->getShare();

if ($share->getShareType() === IShare::TYPE_USER || $share->getShareType() === IShare::TYPE_GROUP) {
$share->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share);
}
}
}

}
7 changes: 7 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,13 @@
*/
'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
*/
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@
'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',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,8 @@ public function __construct($webRoot, \OC\Config $config) {
$c->getEventDispatcher(),
$c->getMailer(),
$c->getURLGenerator(),
$c->getThemingDefaults()
$c->getThemingDefaults(),
$c->query(IEventDispatcher::class)
);

return $manager;
Expand Down
31 changes: 19 additions & 12 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
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;
Expand Down Expand Up @@ -101,7 +102,7 @@ class Manager implements IManager {
/** @var CappedMemoryCache */
private $sharingDisabledForUsersCache;
/** @var EventDispatcherInterface */
private $eventDispatcher;
private $legacyDispatcher;
/** @var LegacyHooks */
private $legacyHooks;
/** @var IMailer */
Expand All @@ -110,6 +111,8 @@ class Manager implements IManager {
private $urlGenerator;
/** @var \OC_Defaults */
private $defaults;
/** @var IEventDispatcher */
private $dispatcher;


/**
Expand Down Expand Up @@ -143,10 +146,11 @@ public function __construct(
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;
Expand All @@ -159,12 +163,13 @@ public function __construct(
$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;
}

/**
Expand Down Expand Up @@ -195,7 +200,7 @@ protected function verifyPassword($password) {

// 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());
}
Expand Down Expand Up @@ -766,7 +771,7 @@ public function createShare(\OCP\Share\IShare $share) {

// 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'));
}
Expand All @@ -779,7 +784,9 @@ public function createShare(\OCP\Share\IShare $share) {

// 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();
Expand Down Expand Up @@ -1041,7 +1048,7 @@ public function acceptShare(IShare $share, string $recipientId): IShare {
}
$provider->acceptShare($share, $recipientId);
$event = new GenericEvent($share);
$this->eventDispatcher->dispatch('OCP\Share::postAcceptShare', $event);
$this->legacyDispatcher->dispatch('OCP\Share::postAcceptShare', $event);

return $share;
}
Expand Down Expand Up @@ -1111,7 +1118,7 @@ public function deleteShare(\OCP\Share\IShare $share) {
}

$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);
Expand All @@ -1125,7 +1132,7 @@ public function deleteShare(\OCP\Share\IShare $share) {

// Emit post hook
$event->setArgument('deletedShares', $deletedShares);
$this->eventDispatcher->dispatch('OCP\Share::postUnshare', $event);
$this->legacyDispatcher->dispatch('OCP\Share::postUnshare', $event);
}


Expand All @@ -1144,7 +1151,7 @@ public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) {

$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 {
Expand Down
53 changes: 53 additions & 0 deletions lib/public/Share/Events/ShareCreatedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2019, Roeland Jago Douma <[email protected]>
*
* @author Roeland Jago Douma <[email protected]>
*
* @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;
}
}
Loading