2015-03-09 11:20:18 -04:00
|
|
|
<?php
|
|
|
|
|
/**
|
2024-06-06 13:48:28 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
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
|
|
|
|
2022-11-03 07:51:29 -04:00
|
|
|
use OC\Group\DisplayNameCache as GroupDisplayNameCache;
|
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-05 09:10:54 -05:00
|
|
|
use OCA\Files\Event\LoadAdditionalScriptsEvent;
|
|
|
|
|
use OCA\Files\Event\LoadSidebar;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\Files_Sharing\Capabilities;
|
|
|
|
|
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;
|
2024-04-20 14:07:55 -04:00
|
|
|
use OCA\Files_Sharing\Listener\BeforeDirectFileDownloadListener;
|
2025-03-13 07:09:38 -04:00
|
|
|
use OCA\Files_Sharing\Listener\BeforeNodeReadListener;
|
2024-04-20 14:07:55 -04:00
|
|
|
use OCA\Files_Sharing\Listener\BeforeZipCreatedListener;
|
2019-11-05 09:10:54 -05:00
|
|
|
use OCA\Files_Sharing\Listener\LoadAdditionalListener;
|
2024-07-17 10:48:47 -04:00
|
|
|
use OCA\Files_Sharing\Listener\LoadPublicFileRequestAuthListener;
|
2019-11-05 09:10:54 -05:00
|
|
|
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;
|
2021-08-04 12:59:47 -04:00
|
|
|
use OCA\Files_Sharing\ShareBackend\File;
|
|
|
|
|
use OCA\Files_Sharing\ShareBackend\Folder;
|
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;
|
2024-07-17 10:48:47 -04:00
|
|
|
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
|
2022-05-12 04:28:03 -04:00
|
|
|
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as ResourcesLoadAdditionalScriptsEvent;
|
2019-11-05 09:10:54 -05:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
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;
|
2025-03-13 07:09:38 -04:00
|
|
|
use OCP\Files\Events\Node\BeforeNodeReadEvent;
|
2022-11-03 07:51:29 -04:00
|
|
|
use OCP\Group\Events\GroupChangedEvent;
|
2023-08-28 08:59:54 -04:00
|
|
|
use OCP\Group\Events\GroupDeletedEvent;
|
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;
|
2019-12-12 15:38:52 -05:00
|
|
|
use OCP\Share\Events\ShareCreatedEvent;
|
2022-04-22 04:01:35 -04:00
|
|
|
use OCP\User\Events\UserChangedEvent;
|
2023-08-28 08:59:54 -04:00
|
|
|
use OCP\User\Events\UserDeletedEvent;
|
2019-11-08 03:29:20 -05:00
|
|
|
use OCP\Util;
|
2020-07-16 04:27:44 -04:00
|
|
|
use Psr\Container\ContainerInterface;
|
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);
|
2023-08-28 08:59:54 -04:00
|
|
|
$context->registerEventListener(UserDeletedEvent::class, DisplayNameCache::class);
|
2022-11-03 07:51:29 -04:00
|
|
|
$context->registerEventListener(GroupChangedEvent::class, GroupDisplayNameCache::class);
|
2023-08-28 08:59:54 -04:00
|
|
|
$context->registerEventListener(GroupDeletedEvent::class, GroupDisplayNameCache::class);
|
2024-04-20 14:07:55 -04:00
|
|
|
|
2024-07-17 10:48:47 -04:00
|
|
|
// Sidebar and files scripts
|
2024-04-20 14:07:55 -04:00
|
|
|
$context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class);
|
|
|
|
|
$context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class);
|
|
|
|
|
$context->registerEventListener(ShareCreatedEvent::class, ShareInteractionListener::class);
|
|
|
|
|
$context->registerEventListener(ShareCreatedEvent::class, UserShareAcceptanceListener::class);
|
|
|
|
|
$context->registerEventListener(UserAddedEvent::class, UserAddedToGroupListener::class);
|
|
|
|
|
|
2025-03-13 07:09:38 -04:00
|
|
|
// Publish activity for public download
|
|
|
|
|
$context->registerEventListener(BeforeNodeReadEvent::class, BeforeNodeReadListener::class);
|
2025-03-13 10:07:53 -04:00
|
|
|
$context->registerEventListener(BeforeZipCreatedEvent::class, BeforeNodeReadListener::class);
|
2025-03-13 07:09:38 -04:00
|
|
|
|
2025-03-13 12:10:06 -04:00
|
|
|
// Handle download events for view only checks. Priority higher than 0 to run early.
|
|
|
|
|
$context->registerEventListener(BeforeZipCreatedEvent::class, BeforeZipCreatedListener::class, 5);
|
|
|
|
|
$context->registerEventListener(BeforeDirectFileDownloadEvent::class, BeforeDirectFileDownloadListener::class, 5);
|
2024-07-17 10:48:47 -04:00
|
|
|
|
|
|
|
|
// File request auth
|
|
|
|
|
$context->registerEventListener(BeforeTemplateRenderedEvent::class, LoadPublicFileRequestAuthListener::class);
|
2021-08-04 12:59:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function boot(IBootContext $context): void {
|
|
|
|
|
$context->injectFn([$this, 'registerMountProviders']);
|
|
|
|
|
$context->injectFn([$this, 'registerEventsScripts']);
|
|
|
|
|
|
|
|
|
|
Helper::registerHooks();
|
|
|
|
|
|
|
|
|
|
Share::registerBackend('file', File::class);
|
|
|
|
|
Share::registerBackend('folder', Folder::class, 'file');
|
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
|
|
|
|
2023-07-19 15:56:34 -04:00
|
|
|
public function registerEventsScripts(IEventDispatcher $dispatcher): void {
|
2024-09-20 11:38:36 -04:00
|
|
|
$dispatcher->addListener(ResourcesLoadAdditionalScriptsEvent::class, function (): void {
|
2024-10-10 06:40:31 -04:00
|
|
|
Util::addScript('files_sharing', 'collaboration');
|
2022-05-12 04:28:03 -04:00
|
|
|
});
|
2024-10-10 06:40:31 -04:00
|
|
|
$dispatcher->addListener(BeforeTemplateRenderedEvent::class, function (): void {
|
2023-08-14 11:46:43 -04:00
|
|
|
/**
|
|
|
|
|
* Always add main sharing script
|
|
|
|
|
*/
|
|
|
|
|
Util::addScript(self::APP_ID, 'main');
|
|
|
|
|
});
|
2019-11-05 09:10:54 -05:00
|
|
|
|
|
|
|
|
// notifications api to accept incoming user shares
|
2024-09-20 11:38:36 -04:00
|
|
|
$dispatcher->addListener(ShareCreatedEvent::class, function (ShareCreatedEvent $event): void {
|
2019-08-21 21:17:17 -04:00
|
|
|
/** @var Listener $listener */
|
|
|
|
|
$listener = $this->getContainer()->query(Listener::class);
|
|
|
|
|
$listener->shareNotification($event);
|
|
|
|
|
});
|
2024-09-20 11:38:36 -04:00
|
|
|
$dispatcher->addListener(IGroup::class . '::postAddUser', function ($event): void {
|
2023-07-19 15:56:34 -04:00
|
|
|
if (!$event instanceof OldGenericEvent) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
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
|
|
|
}
|
2015-03-09 11:20:18 -04:00
|
|
|
}
|