Skip to content

Commit 82a3d7c

Browse files
committed
chore(systemtags): pre-compute user authorizations
Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
1 parent 504e99d commit 82a3d7c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

apps/dav/lib/SystemTag/SystemTagList.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,20 @@
1919
*/
2020
class SystemTagList implements Element {
2121
public const NS_NEXTCLOUD = 'http://nextcloud.org/ns';
22+
private array $canAssignTagMap = [];
2223

2324
/**
2425
* @param ISystemTag[] $tags
2526
*/
2627
public function __construct(
2728
private array $tags,
28-
private ISystemTagManager $tagManager,
29-
private ?IUser $user,
29+
ISystemTagManager $tagManager,
30+
?IUser $user,
3031
) {
3132
$this->tags = $tags;
32-
$this->tagManager = $tagManager;
33-
$this->user = $user;
33+
foreach ($this->tags as $tag) {
34+
$this->canAssignTagMap[$tag->getId()] = $tagManager->canUserAssignTag($tag, $user);
35+
}
3436
}
3537

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

0 commit comments

Comments
 (0)