2015-03-09 11:20:18 -04:00
|
|
|
<?php
|
|
|
|
|
/**
|
2016-07-21 10:49:16 -04:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
|
*
|
|
|
|
|
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
2020-03-31 04:49:10 -04:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2016-07-21 10:49:16 -04:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2021-06-04 15:52:51 -04:00
|
|
|
* @author John Molakvoæ <skjnldsv@protonmail.com>
|
2020-01-13 08:23:49 -05:00
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
2017-11-06 09:56:42 -05:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 12:13:36 -04:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-07-21 10:49:16 -04:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2017-11-06 09:56:42 -05:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2015-06-25 05:43:55 -04:00
|
|
|
*
|
|
|
|
|
* @license AGPL-3.0
|
|
|
|
|
*
|
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* 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, version 3,
|
2019-12-03 13:57:53 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-06-25 05:43:55 -04:00
|
|
|
*
|
2015-03-09 11:20:18 -04:00
|
|
|
*/
|
2015-03-21 15:12:55 -04:00
|
|
|
namespace OCA\Files_Sharing\AppInfo;
|
2015-03-09 11:20:18 -04:00
|
|
|
|
2021-08-04 12:59:47 -04:00
|
|
|
use OC\Share\Share;
|
2022-04-22 04:01:35 -04:00
|
|
|
use OC\User\DisplayNameCache;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\Files_Sharing\Capabilities;
|
2020-07-13 10:05:11 -04:00
|
|
|
use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\Files_Sharing\External\Manager;
|
2021-08-09 10:06:23 -04:00
|
|
|
use OCA\Files_Sharing\External\MountProvider as ExternalMountProvider;
|
2021-08-04 12:59:47 -04:00
|
|
|
use OCA\Files_Sharing\Helper;
|
2020-07-13 10:05:11 -04:00
|
|
|
use OCA\Files_Sharing\Listener\LegacyBeforeTemplateRenderedListener;
|
2019-11-05 09:10:54 -05:00
|
|
|
use OCA\Files_Sharing\Listener\LoadAdditionalListener;
|
|
|
|
|
use OCA\Files_Sharing\Listener\LoadSidebarListener;
|
2020-03-19 04:47:36 -04:00
|
|
|
use OCA\Files_Sharing\Listener\ShareInteractionListener;
|
2020-03-25 03:51:27 -04:00
|
|
|
use OCA\Files_Sharing\Listener\UserAddedToGroupListener;
|
2019-12-12 15:45:59 -05:00
|
|
|
use OCA\Files_Sharing\Listener\UserShareAcceptanceListener;
|
2016-07-20 04:11:01 -04:00
|
|
|
use OCA\Files_Sharing\Middleware\OCSShareAPIMiddleware;
|
2017-07-25 16:25:23 -04:00
|
|
|
use OCA\Files_Sharing\Middleware\ShareInfoMiddleware;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\Files_Sharing\Middleware\SharingCheckMiddleware;
|
2015-03-09 11:20:18 -04:00
|
|
|
use OCA\Files_Sharing\MountProvider;
|
2019-08-21 21:17:17 -04:00
|
|
|
use OCA\Files_Sharing\Notification\Listener;
|
2019-10-28 15:27:59 -04:00
|
|
|
use OCA\Files_Sharing\Notification\Notifier;
|
2019-11-05 09:10:54 -05:00
|
|
|
use OCA\Files\Event\LoadAdditionalScriptsEvent;
|
|
|
|
|
use OCA\Files\Event\LoadSidebar;
|
2022-07-15 11:11:54 -04:00
|
|
|
use OCP\Files\Event\BeforeDirectGetEvent;
|
2021-08-04 12:59:47 -04:00
|
|
|
use OCA\Files_Sharing\ShareBackend\File;
|
|
|
|
|
use OCA\Files_Sharing\ShareBackend\Folder;
|
2022-05-18 08:54:27 -04:00
|
|
|
use OCA\Files_Sharing\ViewOnly;
|
2015-03-09 11:20:18 -04:00
|
|
|
use OCP\AppFramework\App;
|
2021-08-04 12:59:47 -04:00
|
|
|
use OCP\AppFramework\Bootstrap\IBootContext;
|
|
|
|
|
use OCP\AppFramework\Bootstrap\IBootstrap;
|
|
|
|
|
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
2019-11-05 09:10:54 -05:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2022-05-18 08:54:27 -04:00
|
|
|
use OCP\EventDispatcher\GenericEvent;
|
2020-07-16 04:27:44 -04:00
|
|
|
use OCP\Federation\ICloudIdManager;
|
2019-11-05 09:10:54 -05:00
|
|
|
use OCP\Files\Config\IMountProviderCollection;
|
2022-07-15 11:11:54 -04:00
|
|
|
use OCP\Files\Events\BeforeDirectFileDownloadEvent;
|
|
|
|
|
use OCP\Files\Events\BeforeZipCreatedEvent;
|
2022-05-18 08:54:27 -04:00
|
|
|
use OCP\Files\IRootFolder;
|
2020-03-25 03:51:27 -04:00
|
|
|
use OCP\Group\Events\UserAddedEvent;
|
2020-07-16 04:27:44 -04:00
|
|
|
use OCP\IDBConnection;
|
2019-09-06 07:06:21 -04:00
|
|
|
use OCP\IGroup;
|
2021-04-23 11:29:34 -04:00
|
|
|
use OCP\IUserSession;
|
2021-08-09 10:06:23 -04:00
|
|
|
use OCP\L10N\IFactory;
|
2019-12-12 15:38:52 -05:00
|
|
|
use OCP\Share\Events\ShareCreatedEvent;
|
2021-04-23 11:29:34 -04:00
|
|
|
use OCP\Share\IManager;
|
2022-04-22 04:01:35 -04:00
|
|
|
use OCP\User\Events\UserChangedEvent;
|
2019-11-08 03:29:20 -05:00
|
|
|
use OCP\Util;
|
2020-07-16 04:27:44 -04:00
|
|
|
use Psr\Container\ContainerInterface;
|
2020-10-29 15:15:04 -04:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
2022-05-18 08:54:27 -04:00
|
|
|
use Symfony\Component\EventDispatcher\GenericEvent as OldGenericEvent;
|
2015-03-09 11:20:18 -04:00
|
|
|
|
2021-08-04 12:59:47 -04:00
|
|
|
class Application extends App implements IBootstrap {
|
2020-04-10 10:54:27 -04:00
|
|
|
public const APP_ID = 'files_sharing';
|
2019-11-05 09:10:54 -05:00
|
|
|
|
|
|
|
|
public function __construct(array $urlParams = []) {
|
|
|
|
|
parent::__construct(self::APP_ID, $urlParams);
|
2021-08-04 12:59:47 -04:00
|
|
|
}
|
2015-04-20 10:59:20 -04:00
|
|
|
|
2021-08-04 12:59:47 -04:00
|
|
|
public function register(IRegistrationContext $context): void {
|
2021-08-09 10:06:23 -04:00
|
|
|
$context->registerService(ExternalMountProvider::class, function (ContainerInterface $c) {
|
|
|
|
|
return new ExternalMountProvider(
|
2020-07-16 04:27:44 -04:00
|
|
|
$c->get(IDBConnection::class),
|
2020-04-09 07:53:40 -04:00
|
|
|
function () use ($c) {
|
2020-07-16 04:27:44 -04:00
|
|
|
return $c->get(Manager::class);
|
2017-01-27 06:52:17 -05:00
|
|
|
},
|
2020-07-16 04:27:44 -04:00
|
|
|
$c->get(ICloudIdManager::class)
|
2015-10-05 10:39:11 -04:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2019-11-05 09:10:54 -05:00
|
|
|
/**
|
2021-08-04 12:59:47 -04:00
|
|
|
* Middleware
|
2015-03-21 15:12:55 -04:00
|
|
|
*/
|
2021-08-04 12:59:47 -04:00
|
|
|
$context->registerMiddleWare(SharingCheckMiddleware::class);
|
|
|
|
|
$context->registerMiddleWare(OCSShareAPIMiddleware::class);
|
|
|
|
|
$context->registerMiddleWare(ShareInfoMiddleware::class);
|
2019-10-28 15:27:59 -04:00
|
|
|
|
2021-08-04 12:59:47 -04:00
|
|
|
$context->registerCapability(Capabilities::class);
|
2019-11-05 09:10:54 -05:00
|
|
|
|
2021-08-04 12:59:47 -04:00
|
|
|
$context->registerNotifierService(Notifier::class);
|
2022-04-22 04:01:35 -04:00
|
|
|
$context->registerEventListener(UserChangedEvent::class, DisplayNameCache::class);
|
2021-08-04 12:59:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function boot(IBootContext $context): void {
|
|
|
|
|
$context->injectFn([$this, 'registerMountProviders']);
|
|
|
|
|
$context->injectFn([$this, 'registerEventsScripts']);
|
2022-05-18 08:54:27 -04:00
|
|
|
$context->injectFn([$this, 'registerDownloadEvents']);
|
2021-08-09 10:06:23 -04:00
|
|
|
$context->injectFn([$this, 'setupSharingMenus']);
|
2021-08-04 12:59:47 -04:00
|
|
|
|
|
|
|
|
Helper::registerHooks();
|
|
|
|
|
|
|
|
|
|
Share::registerBackend('file', File::class);
|
|
|
|
|
Share::registerBackend('folder', Folder::class, 'file');
|
2019-11-08 03:29:20 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Always add main sharing script
|
|
|
|
|
*/
|
2021-12-01 18:08:08 -05:00
|
|
|
Util::addScript(self::APP_ID, 'main');
|
2015-03-09 11:20:18 -04:00
|
|
|
}
|
|
|
|
|
|
2021-08-04 12:59:47 -04:00
|
|
|
|
2022-06-13 06:48:35 -04:00
|
|
|
public function registerMountProviders(IMountProviderCollection $mountProviderCollection, MountProvider $mountProvider, ExternalMountProvider $externalMountProvider): void {
|
2021-08-09 10:06:23 -04:00
|
|
|
$mountProviderCollection->registerProvider($mountProvider);
|
|
|
|
|
$mountProviderCollection->registerProvider($externalMountProvider);
|
2015-03-09 11:20:18 -04:00
|
|
|
}
|
2019-08-21 21:17:17 -04:00
|
|
|
|
2022-06-13 06:48:35 -04:00
|
|
|
public function registerEventsScripts(IEventDispatcher $dispatcher, EventDispatcherInterface $oldDispatcher): void {
|
2019-11-05 09:10:54 -05:00
|
|
|
// sidebar and files scripts
|
|
|
|
|
$dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class);
|
2020-07-13 10:05:11 -04:00
|
|
|
$dispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, LegacyBeforeTemplateRenderedListener::class);
|
2019-11-05 09:10:54 -05:00
|
|
|
$dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class);
|
2020-03-19 04:47:36 -04:00
|
|
|
$dispatcher->addServiceListener(ShareCreatedEvent::class, ShareInteractionListener::class);
|
2020-04-09 07:53:40 -04:00
|
|
|
$dispatcher->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function () {
|
2021-12-01 18:08:08 -05:00
|
|
|
\OCP\Util::addScript('files_sharing', 'collaboration');
|
2019-11-05 09:10:54 -05:00
|
|
|
});
|
2019-12-12 15:45:59 -05:00
|
|
|
$dispatcher->addServiceListener(ShareCreatedEvent::class, UserShareAcceptanceListener::class);
|
2020-03-25 03:51:27 -04:00
|
|
|
$dispatcher->addServiceListener(UserAddedEvent::class, UserAddedToGroupListener::class);
|
2019-11-05 09:10:54 -05:00
|
|
|
|
|
|
|
|
// notifications api to accept incoming user shares
|
2022-05-18 08:54:27 -04:00
|
|
|
$oldDispatcher->addListener('OCP\Share::postShare', function (OldGenericEvent $event) {
|
2019-08-21 21:17:17 -04:00
|
|
|
/** @var Listener $listener */
|
|
|
|
|
$listener = $this->getContainer()->query(Listener::class);
|
|
|
|
|
$listener->shareNotification($event);
|
|
|
|
|
});
|
2022-05-18 08:54:27 -04:00
|
|
|
$oldDispatcher->addListener(IGroup::class . '::postAddUser', function (OldGenericEvent $event) {
|
2019-09-06 07:06:21 -04:00
|
|
|
/** @var Listener $listener */
|
|
|
|
|
$listener = $this->getContainer()->query(Listener::class);
|
|
|
|
|
$listener->userAddedToGroup($event);
|
|
|
|
|
});
|
2019-08-21 21:17:17 -04:00
|
|
|
}
|
2019-11-05 09:10:54 -05:00
|
|
|
|
2022-05-18 08:54:27 -04:00
|
|
|
public function registerDownloadEvents(
|
|
|
|
|
IEventDispatcher $dispatcher,
|
2022-07-15 11:11:54 -04:00
|
|
|
IUserSession $userSession,
|
2022-05-18 08:54:27 -04:00
|
|
|
IRootFolder $rootFolder
|
2022-06-13 06:48:35 -04:00
|
|
|
): void {
|
2022-05-18 08:54:27 -04:00
|
|
|
|
|
|
|
|
$dispatcher->addListener(
|
2022-07-15 11:11:54 -04:00
|
|
|
BeforeDirectFileDownloadEvent::class,
|
|
|
|
|
function (BeforeDirectFileDownloadEvent $event) use ($userSession, $rootFolder): void {
|
|
|
|
|
$pathsToCheck = [$event->getPath()];
|
2022-05-18 08:54:27 -04:00
|
|
|
// Check only for user/group shares. Don't restrict e.g. share links
|
2022-07-15 11:11:54 -04:00
|
|
|
$user = $userSession->getUser();
|
|
|
|
|
if ($user) {
|
2022-05-18 08:54:27 -04:00
|
|
|
$viewOnlyHandler = new ViewOnly(
|
2022-07-15 11:11:54 -04:00
|
|
|
$rootFolder->getUserFolder($user->getUID())
|
2022-05-18 08:54:27 -04:00
|
|
|
);
|
|
|
|
|
if (!$viewOnlyHandler->check($pathsToCheck)) {
|
2022-07-15 11:11:54 -04:00
|
|
|
$event->setSuccessful(false);
|
|
|
|
|
$event->setErrorMessage('Access to this resource or one of its sub-items has been denied.');
|
2022-05-18 08:54:27 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$dispatcher->addListener(
|
2022-07-15 11:11:54 -04:00
|
|
|
BeforeZipCreatedEvent::class,
|
|
|
|
|
function (BeforeZipCreatedEvent $event) use ($userSession, $rootFolder): void {
|
|
|
|
|
$dir = $event->getDirectory();
|
|
|
|
|
$files = $event->getFiles();
|
2022-05-18 08:54:27 -04:00
|
|
|
|
|
|
|
|
$pathsToCheck = [];
|
2022-07-15 11:11:54 -04:00
|
|
|
foreach ($files as $file) {
|
|
|
|
|
$pathsToCheck[] = $dir . '/' . $file;
|
2022-05-18 08:54:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check only for user/group shares. Don't restrict e.g. share links
|
2022-07-15 11:11:54 -04:00
|
|
|
$user = $userSession->getUser();
|
|
|
|
|
if ($user) {
|
2022-05-18 08:54:27 -04:00
|
|
|
$viewOnlyHandler = new ViewOnly(
|
2022-07-15 11:11:54 -04:00
|
|
|
$rootFolder->getUserFolder($user->getUID())
|
2022-05-18 08:54:27 -04:00
|
|
|
);
|
|
|
|
|
if (!$viewOnlyHandler->check($pathsToCheck)) {
|
2022-07-15 11:11:54 -04:00
|
|
|
$event->setErrorMessage('Access to this resource or one of its sub-items has been denied.');
|
|
|
|
|
$event->setSuccessful(false);
|
2022-05-18 08:54:27 -04:00
|
|
|
} else {
|
2022-07-15 11:11:54 -04:00
|
|
|
$event->setSuccessful(true);
|
2022-05-18 08:54:27 -04:00
|
|
|
}
|
|
|
|
|
} else {
|
2022-07-15 11:11:54 -04:00
|
|
|
$event->setSuccessful(true);
|
2022-05-18 08:54:27 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-13 06:48:35 -04:00
|
|
|
public function setupSharingMenus(IManager $shareManager, IFactory $l10nFactory, IUserSession $userSession): void {
|
2021-04-23 11:29:34 -04:00
|
|
|
if (!$shareManager->shareApiEnabled() || !class_exists('\OCA\Files\App')) {
|
2019-11-05 09:10:54 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-11 11:24:37 -04:00
|
|
|
$navigationManager = \OCA\Files\App::getNavigationManager();
|
2020-07-09 03:48:09 -04:00
|
|
|
// show_Quick_Access stored as string
|
2021-08-09 10:06:23 -04:00
|
|
|
$navigationManager->add(function () use ($shareManager, $l10nFactory, $userSession) {
|
|
|
|
|
$l = $l10nFactory->get('files_sharing');
|
2021-04-23 11:29:34 -04:00
|
|
|
$user = $userSession->getUser();
|
|
|
|
|
$userId = $user ? $user->getUID() : null;
|
2019-12-12 15:38:52 -05:00
|
|
|
|
2020-07-09 03:48:09 -04:00
|
|
|
$sharingSublistArray = [];
|
2019-12-12 15:38:52 -05:00
|
|
|
|
2021-04-23 11:29:34 -04:00
|
|
|
if ($shareManager->sharingDisabledForUser($userId) === false) {
|
2020-07-09 03:48:09 -04:00
|
|
|
$sharingSublistArray[] = [
|
|
|
|
|
'id' => 'sharingout',
|
2019-11-05 09:10:54 -05:00
|
|
|
'appname' => 'files_sharing',
|
|
|
|
|
'script' => 'list.php',
|
2020-07-09 03:48:09 -04:00
|
|
|
'order' => 16,
|
|
|
|
|
'name' => $l->t('Shared with others'),
|
|
|
|
|
];
|
2019-11-05 09:10:54 -05:00
|
|
|
}
|
2019-12-12 15:38:52 -05:00
|
|
|
|
2020-07-09 03:48:09 -04:00
|
|
|
$sharingSublistArray[] = [
|
|
|
|
|
'id' => 'sharingin',
|
|
|
|
|
'appname' => 'files_sharing',
|
|
|
|
|
'script' => 'list.php',
|
|
|
|
|
'order' => 15,
|
|
|
|
|
'name' => $l->t('Shared with you'),
|
|
|
|
|
];
|
|
|
|
|
|
2021-04-23 11:29:34 -04:00
|
|
|
if ($shareManager->sharingDisabledForUser($userId) === false) {
|
2020-07-09 03:48:09 -04:00
|
|
|
// Check if sharing by link is enabled
|
2021-04-23 11:29:34 -04:00
|
|
|
if ($shareManager->shareApiAllowLinks()) {
|
2020-07-09 03:48:09 -04:00
|
|
|
$sharingSublistArray[] = [
|
|
|
|
|
'id' => 'sharinglinks',
|
|
|
|
|
'appname' => 'files_sharing',
|
|
|
|
|
'script' => 'list.php',
|
|
|
|
|
'order' => 17,
|
|
|
|
|
'name' => $l->t('Shared by link'),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-12 15:38:52 -05:00
|
|
|
|
2020-07-09 03:48:09 -04:00
|
|
|
$sharingSublistArray[] = [
|
|
|
|
|
'id' => 'deletedshares',
|
|
|
|
|
'appname' => 'files_sharing',
|
|
|
|
|
'script' => 'list.php',
|
|
|
|
|
'order' => 19,
|
|
|
|
|
'name' => $l->t('Deleted shares'),
|
|
|
|
|
];
|
2020-01-07 06:57:57 -05:00
|
|
|
|
2020-07-09 03:48:09 -04:00
|
|
|
$sharingSublistArray[] = [
|
|
|
|
|
'id' => 'pendingshares',
|
|
|
|
|
'appname' => 'files_sharing',
|
|
|
|
|
'script' => 'list.php',
|
|
|
|
|
'order' => 19,
|
|
|
|
|
'name' => $l->t('Pending shares'),
|
|
|
|
|
];
|
2020-01-07 06:57:57 -05:00
|
|
|
|
2020-07-09 03:48:09 -04:00
|
|
|
return [
|
|
|
|
|
'id' => 'shareoverview',
|
|
|
|
|
'appname' => 'files_sharing',
|
|
|
|
|
'script' => 'list.php',
|
|
|
|
|
'order' => 18,
|
|
|
|
|
'name' => $l->t('Shares'),
|
|
|
|
|
'classes' => 'collapsible',
|
|
|
|
|
'sublist' => $sharingSublistArray,
|
|
|
|
|
'expandedState' => 'show_sharing_menu'
|
|
|
|
|
];
|
|
|
|
|
});
|
2019-11-05 09:10:54 -05:00
|
|
|
}
|
2015-03-09 11:20:18 -04:00
|
|
|
}
|