diff --git a/apps/dav/appinfo/v2/publicremote.php b/apps/dav/appinfo/v2/publicremote.php index 53e85d556eb9f..7e664df68d0a0 100644 --- a/apps/dav/appinfo/v2/publicremote.php +++ b/apps/dav/appinfo/v2/publicremote.php @@ -12,6 +12,7 @@ use OCA\DAV\Storage\PublicOwnerWrapper; use OCA\DAV\Storage\PublicShareWrapper; use OCA\FederatedFileSharing\FederatedShareProvider; +use OCP\BeforeSabrePubliclyLoadedEvent; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Mount\IMountManager; use OCP\IConfig; @@ -35,6 +36,7 @@ $session = \OCP\Server::get(ISession::class); $request = \OCP\Server::get(IRequest::class); +$eventDispatcher = \OCP\Server::get(IEventDispatcher::class); $session->close(); $requestUri = $request->getRequestUri(); @@ -59,7 +61,7 @@ \OCP\Server::get(ITagManager::class), $request, \OCP\Server::get(IPreview::class), - \OCP\Server::get(IEventDispatcher::class), + $eventDispatcher, $l10nFactory->get('dav'), ); @@ -131,5 +133,9 @@ $server->addPlugin($linkCheckPlugin); $server->addPlugin($filesDropPlugin); +// allow setup of additional plugins +$event = new BeforeSabrePubliclyLoadedEvent($server); +$eventDispatcher->dispatchTyped($event); + // And off we go! $server->exec(); diff --git a/apps/dav/lib/Connector/Sabre/ServerFactory.php b/apps/dav/lib/Connector/Sabre/ServerFactory.php index 42d3ce1818ace..4f40b69cdc81b 100644 --- a/apps/dav/lib/Connector/Sabre/ServerFactory.php +++ b/apps/dav/lib/Connector/Sabre/ServerFactory.php @@ -11,6 +11,7 @@ use OCA\DAV\CalDAV\DefaultCalendarValidator; use OCA\DAV\DAV\ViewOnlyPlugin; use OCA\DAV\Files\ErrorPagePlugin; +use OCA\DAV\SystemTag\SystemTagPlugin; use OCA\Theming\ThemingDefaults; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Folder; @@ -18,49 +19,32 @@ use OCP\Files\Mount\IMountManager; use OCP\IConfig; use OCP\IDBConnection; +use OCP\IGroupManager; use OCP\IL10N; use OCP\IPreview; use OCP\IRequest; use OCP\ITagManager; use OCP\IUserSession; use OCP\SabrePluginEvent; +use OCP\SystemTag\ISystemTagManager; +use OCP\SystemTag\ISystemTagObjectMapper; use Psr\Log\LoggerInterface; use Sabre\DAV\Auth\Plugin; class ServerFactory { - private IConfig $config; - private LoggerInterface $logger; - private IDBConnection $databaseConnection; - private IUserSession $userSession; - private IMountManager $mountManager; - private ITagManager $tagManager; - private IRequest $request; - private IPreview $previewManager; - private IEventDispatcher $eventDispatcher; - private IL10N $l10n; public function __construct( - IConfig $config, - LoggerInterface $logger, - IDBConnection $databaseConnection, - IUserSession $userSession, - IMountManager $mountManager, - ITagManager $tagManager, - IRequest $request, - IPreview $previewManager, - IEventDispatcher $eventDispatcher, - IL10N $l10n + private IConfig $config, + private LoggerInterface $logger, + private IDBConnection $databaseConnection, + private IUserSession $userSession, + private IMountManager $mountManager, + private ITagManager $tagManager, + private IRequest $request, + private IPreview $previewManager, + private IEventDispatcher $eventDispatcher, + private IL10N $l10n ) { - $this->config = $config; - $this->logger = $logger; - $this->databaseConnection = $databaseConnection; - $this->userSession = $userSession; - $this->mountManager = $mountManager; - $this->tagManager = $tagManager; - $this->request = $request; - $this->previewManager = $previewManager; - $this->eventDispatcher = $eventDispatcher; - $this->l10n = $l10n; } /** diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php index 2784e99b5f73b..3b6fc1108938a 100644 --- a/apps/dav/lib/Server.php +++ b/apps/dav/lib/Server.php @@ -197,7 +197,7 @@ public function __construct(IRequest $request, string $baseUri) { } // system tags plugins - $this->server->addPlugin(\OC::$server->get(SystemTagPlugin::class)); + // $this->server->addPlugin(\OCP\Server::get(SystemTagPlugin::class)); // comments plugin $this->server->addPlugin(new CommentsPlugin( diff --git a/apps/dav/lib/SystemTag/SystemTagList.php b/apps/dav/lib/SystemTag/SystemTagList.php index cbdf98b752fcb..7f651e7de0a45 100644 --- a/apps/dav/lib/SystemTag/SystemTagList.php +++ b/apps/dav/lib/SystemTag/SystemTagList.php @@ -20,12 +20,13 @@ class SystemTagList implements Element { public const NS_NEXTCLOUD = 'http://nextcloud.org/ns'; - /** @var ISystemTag[] */ - private array $tags; - private ISystemTagManager $tagManager; - private IUser $user; - - public function __construct(array $tags, ISystemTagManager $tagManager, IUser $user) { + /** + * @param ISystemTag[] $tags + */ + public function __construct( + private array $tags, + private ISystemTagManager $tagManager, + private ?IUser $user) { $this->tags = $tags; $this->tagManager = $tagManager; $this->user = $user; diff --git a/apps/dav/lib/SystemTag/SystemTagPlugin.php b/apps/dav/lib/SystemTag/SystemTagPlugin.php index ec2014163b376..ef7d3e88d9354 100644 --- a/apps/dav/lib/SystemTag/SystemTagPlugin.php +++ b/apps/dav/lib/SystemTag/SystemTagPlugin.php @@ -305,9 +305,6 @@ private function propfindForFile(PropFind $propFind, Node $node): void { $propFind->handle(self::SYSTEM_TAGS_PROPERTYNAME, function () use ($node) { $user = $this->userSession->getUser(); - if ($user === null) { - return; - } $tags = $this->getTagsForFile($node->getId(), $user); usort($tags, function (ISystemTag $tagA, ISystemTag $tagB): int { @@ -321,8 +318,7 @@ private function propfindForFile(PropFind $propFind, Node $node): void { * @param int $fileId * @return ISystemTag[] */ - private function getTagsForFile(int $fileId, IUser $user): array { - + private function getTagsForFile(int $fileId, ?IUser $user): array { if (isset($this->cachedTagMappings[$fileId])) { $tagIds = $this->cachedTagMappings[$fileId]; } else { diff --git a/apps/systemtags/composer/composer/autoload_classmap.php b/apps/systemtags/composer/composer/autoload_classmap.php index 66d788547c6fb..20174ee466797 100644 --- a/apps/systemtags/composer/composer/autoload_classmap.php +++ b/apps/systemtags/composer/composer/autoload_classmap.php @@ -13,6 +13,9 @@ 'OCA\\SystemTags\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php', 'OCA\\SystemTags\\Capabilities' => $baseDir . '/../lib/Capabilities.php', 'OCA\\SystemTags\\Controller\\LastUsedController' => $baseDir . '/../lib/Controller/LastUsedController.php', + 'OCA\\SystemTags\\Listeners\\BeforeSabrePubliclyLoadedListener' => $baseDir . '/../lib/Listeners/BeforeSabrePubliclyLoadedListener.php', + 'OCA\\SystemTags\\Listeners\\BeforeTemplateRenderedListener' => $baseDir . '/../lib/Listeners/BeforeTemplateRenderedListener.php', + 'OCA\\SystemTags\\Listeners\\LoadAdditionalScriptsListener' => $baseDir . '/../lib/Listeners/LoadAdditionalScriptsListener.php', 'OCA\\SystemTags\\Search\\TagSearchProvider' => $baseDir . '/../lib/Search/TagSearchProvider.php', 'OCA\\SystemTags\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php', ); diff --git a/apps/systemtags/composer/composer/autoload_static.php b/apps/systemtags/composer/composer/autoload_static.php index c1ea863518192..04dae4aa52f2a 100644 --- a/apps/systemtags/composer/composer/autoload_static.php +++ b/apps/systemtags/composer/composer/autoload_static.php @@ -28,6 +28,9 @@ class ComposerStaticInitSystemTags 'OCA\\SystemTags\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php', 'OCA\\SystemTags\\Capabilities' => __DIR__ . '/..' . '/../lib/Capabilities.php', 'OCA\\SystemTags\\Controller\\LastUsedController' => __DIR__ . '/..' . '/../lib/Controller/LastUsedController.php', + 'OCA\\SystemTags\\Listeners\\BeforeSabrePubliclyLoadedListener' => __DIR__ . '/..' . '/../lib/Listeners/BeforeSabrePubliclyLoadedListener.php', + 'OCA\\SystemTags\\Listeners\\BeforeTemplateRenderedListener' => __DIR__ . '/..' . '/../lib/Listeners/BeforeTemplateRenderedListener.php', + 'OCA\\SystemTags\\Listeners\\LoadAdditionalScriptsListener' => __DIR__ . '/..' . '/../lib/Listeners/LoadAdditionalScriptsListener.php', 'OCA\\SystemTags\\Search\\TagSearchProvider' => __DIR__ . '/..' . '/../lib/Search/TagSearchProvider.php', 'OCA\\SystemTags\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php', ); diff --git a/apps/systemtags/lib/AppInfo/Application.php b/apps/systemtags/lib/AppInfo/Application.php index e49449908b7a8..ea40a88ce2ebe 100644 --- a/apps/systemtags/lib/AppInfo/Application.php +++ b/apps/systemtags/lib/AppInfo/Application.php @@ -9,13 +9,18 @@ namespace OCA\SystemTags\AppInfo; use OCA\Files\Event\LoadAdditionalScriptsEvent; +use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent; use OCA\SystemTags\Activity\Listener; use OCA\SystemTags\Capabilities; +use OCA\SystemTags\Listeners\BeforeSabrePubliclyLoadedListener; +use OCA\SystemTags\Listeners\BeforeTemplateRenderedListener; +use OCA\SystemTags\Listeners\LoadAdditionalScriptsListener; use OCA\SystemTags\Search\TagSearchProvider; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; +use OCP\BeforeSabrePubliclyLoadedEvent; use OCP\EventDispatcher\IEventDispatcher; use OCP\SystemTag\ManagerEvent; use OCP\SystemTag\MapperEvent; @@ -30,6 +35,9 @@ public function __construct() { public function register(IRegistrationContext $context): void { $context->registerSearchProvider(TagSearchProvider::class); $context->registerCapability(Capabilities::class); + $context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalScriptsListener::class); + $context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class); + $context->registerEventListener(BeforeSabrePubliclyLoadedEvent::class, BeforeSabrePubliclyLoadedListener::class); } public function boot(IBootContext $context): void { diff --git a/apps/systemtags/lib/Listeners/BeforeSabrePubliclyLoadedListener.php b/apps/systemtags/lib/Listeners/BeforeSabrePubliclyLoadedListener.php new file mode 100644 index 0000000000000..3abcce85eae17 --- /dev/null +++ b/apps/systemtags/lib/Listeners/BeforeSabrePubliclyLoadedListener.php @@ -0,0 +1,26 @@ + + */ +class BeforeSabrePubliclyLoadedListener implements IEventListener { + public function handle(Event $event): void { + if (!$event instanceof BeforeSabrePubliclyLoadedEvent) { + return; + } + $event->getServer()->addPlugin(Server::get(SystemTagPlugin::class)); + } +} diff --git a/apps/systemtags/lib/Listeners/BeforeTemplateRenderedListener.php b/apps/systemtags/lib/Listeners/BeforeTemplateRenderedListener.php new file mode 100644 index 0000000000000..74fa6bd03fef2 --- /dev/null +++ b/apps/systemtags/lib/Listeners/BeforeTemplateRenderedListener.php @@ -0,0 +1,26 @@ + + */ +class BeforeTemplateRenderedListener implements IEventListener { + public function handle(Event $event): void { + if (!$event instanceof BeforeTemplateRenderedEvent) { + return; + } + Util::addInitScript(Application::APP_ID, 'init'); + } +} diff --git a/apps/systemtags/lib/Listeners/LoadAdditionalScriptsListener.php b/apps/systemtags/lib/Listeners/LoadAdditionalScriptsListener.php new file mode 100644 index 0000000000000..5a2561d20129c --- /dev/null +++ b/apps/systemtags/lib/Listeners/LoadAdditionalScriptsListener.php @@ -0,0 +1,26 @@ + + */ +class LoadAdditionalScriptsListener implements IEventListener { + public function handle(Event $event): void { + if (!$event instanceof LoadAdditionalScriptsEvent) { + return; + } + Util::addInitScript(Application::APP_ID, 'init'); + } +} diff --git a/lib/private/SystemTag/SystemTagManager.php b/lib/private/SystemTag/SystemTagManager.php index e99213b618bee..671c9e2ad615f 100644 --- a/lib/private/SystemTag/SystemTagManager.php +++ b/lib/private/SystemTag/SystemTagManager.php @@ -305,7 +305,11 @@ public function deleteTags($tagIds): void { /** * {@inheritdoc} */ - public function canUserAssignTag(ISystemTag $tag, IUser $user): bool { + public function canUserAssignTag(ISystemTag $tag, ?IUser $user): bool { + if ($user === null) { + return false; + } + // early check to avoid unneeded group lookups if ($tag->isUserAssignable() && $tag->isUserVisible()) { return true; @@ -333,11 +337,16 @@ public function canUserAssignTag(ISystemTag $tag, IUser $user): bool { /** * {@inheritdoc} */ - public function canUserSeeTag(ISystemTag $tag, IUser $user): bool { + public function canUserSeeTag(ISystemTag $tag, ?IUser $user): bool { if ($tag->isUserVisible()) { return true; } + // If no user and not user visible, then it's invisible + if ($user === null) { + return false; + } + if ($this->groupManager->isAdmin($user->getUID())) { return true; } diff --git a/lib/public/SystemTag/ISystemTagManager.php b/lib/public/SystemTag/ISystemTagManager.php index 8d0241e752fad..1c007ea0afa72 100644 --- a/lib/public/SystemTag/ISystemTagManager.php +++ b/lib/public/SystemTag/ISystemTagManager.php @@ -112,7 +112,7 @@ public function deleteTags($tagIds); * * @since 9.1.0 */ - public function canUserAssignTag(ISystemTag $tag, IUser $user): bool; + public function canUserAssignTag(ISystemTag $tag, ?IUser $user): bool; /** * Checks whether the given user is allowed to see the tag with the given id. @@ -124,7 +124,7 @@ public function canUserAssignTag(ISystemTag $tag, IUser $user): bool; * * @since 9.1.0 */ - public function canUserSeeTag(ISystemTag $tag, IUser $user): bool; + public function canUserSeeTag(ISystemTag $tag, ?IUser $user): bool; /** * Set groups that can assign a given tag.