Skip to content

Commit

Permalink
feat: make systemtags public visible
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Sep 19, 2024
1 parent 086b11f commit 7244306
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 53 deletions.
50 changes: 20 additions & 30 deletions apps/dav/lib/Connector/Sabre/ServerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,40 @@
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;
use OCP\Files\IFilenameValidator;
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;
}

/**
Expand Down Expand Up @@ -139,6 +123,12 @@ public function createServer(string $baseUri,
);
$server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view, true));
$server->addPlugin(new \OCA\DAV\Connector\Sabre\ChecksumUpdatePlugin());
$server->addPlugin(new SystemTagPlugin(
\OCP\Server::get(ISystemTagManager::class),
\OCP\Server::get(IGroupManager::class),
\OCP\Server::get(IUserSession::class),
\OCP\Server::get(ISystemTagObjectMapper::class),
));

// Allow view-only plugin for webdav requests
$server->addPlugin(new ViewOnlyPlugin(
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
13 changes: 7 additions & 6 deletions apps/dav/lib/SystemTag/SystemTagList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 1 addition & 5 deletions apps/dav/lib/SystemTag/SystemTagPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public function renderPage(IShare $share, string $token, string $path): Template
\OCP\Util::addInitScript(Application::APP_ID, 'init-public');
\OCP\Util::addScript('files', 'main');
\OCP\Util::addStyle('files', 'merged');
\OCP\Util::addInitScript('systemtags', 'init');

// Add file-request script if needed
$attributes = $share->getAttributes();
Expand Down
13 changes: 11 additions & 2 deletions lib/private/SystemTag/SystemTagManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 0 additions & 7 deletions lib/private/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ class Tags implements ITags {
private LoggerInterface $logger;
private array $tags = [];

/**
* Are we including tags for shared items?
*/
private bool $includeShared = false;

/**
* The current user, plus any owners of the items shared with the current
* user, if $this->includeShared === true.
Expand Down Expand Up @@ -59,8 +54,6 @@ class Tags implements ITags {
* @param string $user The user whose data the object will operate on.
* @param string $type The type of items for which tags will be loaded.
* @param array $defaultTags Tags that should be created at construction.
*
* since 20.0.0 $includeShared isn't used anymore
*/
public function __construct(TagMapper $mapper, string $user, string $type, LoggerInterface $logger, IDBConnection $connection, array $defaultTags = []) {
$this->mapper = $mapper;
Expand Down
4 changes: 2 additions & 2 deletions lib/public/SystemTag/ISystemTagManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit 7244306

Please sign in to comment.