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;
$session = \OCP\Server::get(ISession::class);
$request = \OCP\Server::get(IRequest::class);
+$eventDispatcher = \OCP\Server::get(IEventDispatcher::class);
$session->close();
$requestUri = $request->getRequestUri();
\OCP\Server::get(ITagManager::class),
$request,
\OCP\Server::get(IPreview::class),
- \OCP\Server::get(IEventDispatcher::class),
+ $eventDispatcher,
$l10nFactory->get('dav'),
);
$server->addPlugin($linkCheckPlugin);
$server->addPlugin($filesDropPlugin);
+// allow setup of additional plugins
+$event = new BeforeSabrePubliclyLoadedEvent($server);
+$eventDispatcher->dispatchTyped($event);
+
// And off we go!
$server->start();
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;
$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 {
* @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 {
'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',
);
'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',
);
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;
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 {
--- /dev/null
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\SystemTags\Listeners;
+
+use OCA\DAV\SystemTag\SystemTagPlugin;
+use OCP\BeforeSabrePubliclyLoadedEvent;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use OCP\Server;
+
+/**
+ * @template-implements IEventListener<BeforeSabrePubliclyLoadedEvent>
+ */
+class BeforeSabrePubliclyLoadedListener implements IEventListener {
+ public function handle(Event $event): void {
+ if (!$event instanceof BeforeSabrePubliclyLoadedEvent) {
+ return;
+ }
+
+ $server = $event->getServer();
+ if ($server === null) {
+ return;
+ }
+
+ $server->addPlugin(Server::get(SystemTagPlugin::class));
+ }
+}
--- /dev/null
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\SystemTags\Listeners;
+
+use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
+use OCA\SystemTags\AppInfo\Application;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use OCP\Util;
+
+/**
+ * @template-implements IEventListener<BeforeTemplateRenderedEvent>
+ */
+class BeforeTemplateRenderedListener implements IEventListener {
+ public function handle(Event $event): void {
+ if (!$event instanceof BeforeTemplateRenderedEvent) {
+ return;
+ }
+ Util::addInitScript(Application::APP_ID, 'init');
+ }
+}
--- /dev/null
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\SystemTags\Listeners;
+
+use OCA\Files\Event\LoadAdditionalScriptsEvent;
+use OCA\SystemTags\AppInfo\Application;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use OCP\Util;
+
+/**
+ * @template-implements IEventListener<LoadAdditionalScriptsEvent>
+ */
+class LoadAdditionalScriptsListener implements IEventListener {
+ public function handle(Event $event): void {
+ if (!$event instanceof LoadAdditionalScriptsEvent) {
+ return;
+ }
+ Util::addInitScript(Application::APP_ID, 'init');
+ }
+}
/**
* {@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;
/**
* {@inheritdoc}
*/
- public function canUserSeeTag(ISystemTag $tag, IUser $user): bool {
+ public function canUserSeeTag(ISystemTag $tag, ?IUser $user): bool {
+ // If no user, then we only show public tags
+ if (!$user && $tag->getAccessLevel() === ISystemTag::ACCESS_LEVEL_PUBLIC) {
+ return true;
+ }
+
if ($tag->isUserVisible()) {
return true;
}
+ // if not returned yet, and user is not logged in, then the tag is not visible
+ if ($user === null) {
+ return false;
+ }
+
if ($this->groupManager->isAdmin($user->getUID())) {
return true;
}
* given id.
*
* @param ISystemTag $tag tag to check permission for
- * @param IUser $user user to check permission for
+ * @param IUser|null $user user to check permission for
*
* @return bool true if the user is allowed to assign/unassign the tag, false otherwise
*
* @since 9.1.0
+ * @since 31.0.0 `$user` can be null to check anonymous permissions
*/
- 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.
*
* @param ISystemTag $tag tag to check permission for
- * @param IUser $user user to check permission for
+ * @param IUser|null $user user to check permission for
*
* @return bool true if the user can see the tag, false otherwise
*
* @since 9.1.0
+ * @since 31.0.0 `$user` can be null to check anonymous permissions
*/
- public function canUserSeeTag(ISystemTag $tag, IUser $user): bool;
+ public function canUserSeeTag(ISystemTag $tag, ?IUser $user): bool;
/**
* Set groups that can assign a given tag.