Skip to content

Commit

Permalink
chore(systemtags): pre-compute user authorizations
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Gaussorgues <[email protected]>
  • Loading branch information
Altahrim committed Dec 3, 2024
1 parent b638dd1 commit 0026817
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions apps/dav/lib/SystemTag/SystemTagList.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@
*/
class SystemTagList implements Element {
public const NS_NEXTCLOUD = 'http://nextcloud.org/ns';
private array $canAssignTagMap = [];

/**
* @param ISystemTag[] $tags
*/
public function __construct(
private array $tags,
private ISystemTagManager $tagManager,
private ?IUser $user,
ISystemTagManager $tagManager,
?IUser $user,
) {
$this->tags = $tags;
$this->tagManager = $tagManager;
$this->user = $user;
foreach ($this->tags as $tag) {
$this->canAssignTagMap[$tag->getId()] = $tagManager->canUserAssignTag($tag, $user);
}
}

/**
Expand All @@ -48,7 +50,7 @@ public function xmlSerialize(Writer $writer): void {
foreach ($this->tags as $tag) {
$writer->startElement('{' . self::NS_NEXTCLOUD . '}system-tag');
$writer->writeAttributes([
SystemTagPlugin::CANASSIGN_PROPERTYNAME => $this->tagManager->canUserAssignTag($tag, $this->user) ? 'true' : 'false',
SystemTagPlugin::CANASSIGN_PROPERTYNAME => $this->canAssignTagMap[$tag->getId()] ? 'true' : 'false',
SystemTagPlugin::ID_PROPERTYNAME => $tag->getId(),
SystemTagPlugin::USERASSIGNABLE_PROPERTYNAME => $tag->isUserAssignable() ? 'true' : 'false',
SystemTagPlugin::USERVISIBLE_PROPERTYNAME => $tag->isUserVisible() ? 'true' : 'false',
Expand Down

0 comments on commit 0026817

Please sign in to comment.