summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/lib
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2019-12-12 21:38:52 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2019-12-16 09:07:25 +0100
commitbb4264c565963f07c087a4aebc47ff6ca0d59686 (patch)
tree1a60ad4d122a1af6b99d2e1ef6e0f9867a64c63d /apps/files_sharing/lib
parent87104ce5100f905dab3ce056f05847fad5dde393 (diff)
downloadnextcloud-server-bb4264c565963f07c087a4aebc47ff6ca0d59686.tar.gz
nextcloud-server-bb4264c565963f07c087a4aebc47ff6ca0d59686.zip
config.php setting to always accept internal shares
Part of #18255 Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/files_sharing/lib')
-rw-r--r--apps/files_sharing/lib/AppInfo/Application.php13
-rw-r--r--apps/files_sharing/lib/Listener/GlobalShareAcceptanceListener.php61
2 files changed, 69 insertions, 5 deletions
diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php
index 8b83fea2e8e..840f8a809ff 100644
--- a/apps/files_sharing/lib/AppInfo/Application.php
+++ b/apps/files_sharing/lib/AppInfo/Application.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) {
@@ -233,7 +236,7 @@ class Application extends App {
}
$sharingSublistArray = [];
-
+
if (\OCP\Util::isSharingDisabledForUser() === false) {
array_push($sharingSublistArray, [
'id' => 'sharingout',
@@ -243,7 +246,7 @@ class Application extends App {
'name' => $l->t('Shared with others'),
]);
}
-
+
array_push($sharingSublistArray, [
'id' => 'sharingin',
'appname' => 'files_sharing',
@@ -251,7 +254,7 @@ class Application extends App {
'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') {
@@ -264,7 +267,7 @@ class Application extends App {
]);
}
}
-
+
array_push($sharingSublistArray, [
'id' => 'deletedshares',
'appname' => 'files_sharing',
@@ -272,7 +275,7 @@ class Application extends App {
'order' => 19,
'name' => $l->t('Deleted shares'),
]);
-
+
// show_Quick_Access stored as string
\OCA\Files\App::getNavigationManager()->add([
'id' => 'shareoverview',
diff --git a/apps/files_sharing/lib/Listener/GlobalShareAcceptanceListener.php b/apps/files_sharing/lib/Listener/GlobalShareAcceptanceListener.php
new file mode 100644
index 00000000000..d30801a8fd4
--- /dev/null
+++ b/apps/files_sharing/lib/Listener/GlobalShareAcceptanceListener.php
@@ -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);
+ }
+ }
+ }
+
+}