From 51b8e9a47cef68eaba831e8f6eb5b90f55701fcd Mon Sep 17 00:00:00 2001 From: Louis Chmn Date: Thu, 26 Mar 2026 10:54:08 +0100 Subject: [PATCH] feat(systemtag): Add $user context to create and update tag Signed-off-by: Louis Chmn --- lib/private/SystemTag/SystemTagManager.php | 7 ++++--- lib/public/SystemTag/ISystemTagManager.php | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/private/SystemTag/SystemTagManager.php b/lib/private/SystemTag/SystemTagManager.php index 3a9b48eec1ff2..36c0e74520634 100644 --- a/lib/private/SystemTag/SystemTagManager.php +++ b/lib/private/SystemTag/SystemTagManager.php @@ -159,8 +159,8 @@ public function getGeneratedByAITag(): ISystemTag { } } - public function createTag(string $tagName, bool $userVisible, bool $userAssignable): ISystemTag { - $user = $this->userSession->getUser(); + public function createTag(string $tagName, bool $userVisible, bool $userAssignable, ?IUser $user = null): ISystemTag { + $user ??= $this->userSession->getUser(); if (!$this->canUserCreateTag($user)) { throw new TagCreationForbiddenException(); } @@ -219,6 +219,7 @@ public function updateTag( bool $userVisible, bool $userAssignable, ?string $color, + ?IUser $user, ): void { try { $tags = $this->getTagsByIds($tagId); @@ -228,7 +229,7 @@ public function updateTag( ); } - $user = $this->userSession->getUser(); + $user ??= $this->userSession->getUser(); if (!$this->canUserUpdateTag($user)) { throw new TagUpdateForbiddenException(); } diff --git a/lib/public/SystemTag/ISystemTagManager.php b/lib/public/SystemTag/ISystemTagManager.php index 6df2cf3474b96..de274975c842f 100644 --- a/lib/public/SystemTag/ISystemTagManager.php +++ b/lib/public/SystemTag/ISystemTagManager.php @@ -61,6 +61,7 @@ public function getGeneratedByAITag(): ISystemTag; * @param string $tagName tag name * @param bool $userVisible whether the tag is visible by users * @param bool $userAssignable whether the tag is assignable by users + * @param IUser|null $user the user that wants to create a tag. * * @return ISystemTag system tag * @@ -70,7 +71,7 @@ public function getGeneratedByAITag(): ISystemTag; * @since 9.0.0 * @since 31.0.0 Can throw TagCreationForbiddenExceptionif user doesn't have the right to create a new tag */ - public function createTag(string $tagName, bool $userVisible, bool $userAssignable): ISystemTag; + public function createTag(string $tagName, bool $userVisible, bool $userAssignable, ?IUser $user): ISystemTag; /** * Returns all known tags, optionally filtered by visibility. @@ -92,6 +93,7 @@ public function getAllTags($visibilityFilter = null, $nameSearchPattern = null): * @param bool $userVisible whether the tag is visible by users * @param bool $userAssignable whether the tag is assignable by users * @param string $color color + * @param IUser|null $user the user that wants to update a tag. * * @throws TagNotFoundException if tag with the given id does not exist * @throws TagAlreadyExistsException if there is already another tag @@ -100,7 +102,7 @@ public function getAllTags($visibilityFilter = null, $nameSearchPattern = null): * @since 9.0.0 * @since 31.0.0 `$color` parameter added */ - public function updateTag(string $tagId, string $newName, bool $userVisible, bool $userAssignable, ?string $color); + public function updateTag(string $tagId, string $newName, bool $userVisible, bool $userAssignable, ?string $color, ?IUser $user): void; /** * Delete the given tags from the database and all their relationships.