Skip to content

Commit 7040916

Browse files
authored
Merge pull request #59222 from nextcloud/artonge/fix/systemtag_user_context
feat(systemtag): Add $user context to create and update tag
2 parents 9756097 + 4e0217e commit 7040916

3 files changed

Lines changed: 14 additions & 11 deletions

File tree

lib/private/SystemTag/SystemTagManager.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ public function getGeneratedByAITag(): ISystemTag {
159159
}
160160
}
161161

162-
public function createTag(string $tagName, bool $userVisible, bool $userAssignable): ISystemTag {
163-
$user = $this->userSession->getUser();
162+
public function createTag(string $tagName, bool $userVisible, bool $userAssignable, ?IUser $user = null): ISystemTag {
163+
$user ??= $this->userSession->getUser();
164164
if (!$this->canUserCreateTag($user)) {
165165
throw new TagCreationForbiddenException();
166166
}
@@ -219,6 +219,7 @@ public function updateTag(
219219
bool $userVisible,
220220
bool $userAssignable,
221221
?string $color,
222+
?IUser $user = null,
222223
): void {
223224
try {
224225
$tags = $this->getTagsByIds($tagId);
@@ -228,7 +229,7 @@ public function updateTag(
228229
);
229230
}
230231

231-
$user = $this->userSession->getUser();
232+
$user ??= $this->userSession->getUser();
232233
if (!$this->canUserUpdateTag($user)) {
233234
throw new TagUpdateForbiddenException();
234235
}

lib/public/SystemTag/ISystemTagManager.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function getGeneratedByAITag(): ISystemTag;
6161
* @param string $tagName tag name
6262
* @param bool $userVisible whether the tag is visible by users
6363
* @param bool $userAssignable whether the tag is assignable by users
64+
* @param ?IUser $user the user that wants to create a tag. Null to use the one in session.
6465
*
6566
* @return ISystemTag system tag
6667
*
@@ -69,8 +70,9 @@ public function getGeneratedByAITag(): ISystemTag;
6970
*
7071
* @since 9.0.0
7172
* @since 31.0.0 Can throw TagCreationForbiddenExceptionif user doesn't have the right to create a new tag
73+
* @since 34.0.0 Added nullable $user parameter
7274
*/
73-
public function createTag(string $tagName, bool $userVisible, bool $userAssignable): ISystemTag;
75+
public function createTag(string $tagName, bool $userVisible, bool $userAssignable, ?IUser $user = null): ISystemTag;
7476

7577
/**
7678
* Returns all known tags, optionally filtered by visibility.
@@ -92,15 +94,17 @@ public function getAllTags($visibilityFilter = null, $nameSearchPattern = null):
9294
* @param bool $userVisible whether the tag is visible by users
9395
* @param bool $userAssignable whether the tag is assignable by users
9496
* @param string $color color
97+
* @param ?IUser $user the user that wants to update a tag. Null to use the one in session.
9598
*
9699
* @throws TagNotFoundException if tag with the given id does not exist
97100
* @throws TagAlreadyExistsException if there is already another tag
98101
* with the same attributes
99102
*
100103
* @since 9.0.0
101104
* @since 31.0.0 `$color` parameter added
105+
* @since 34.0.0 Added nullable $user parameter
102106
*/
103-
public function updateTag(string $tagId, string $newName, bool $userVisible, bool $userAssignable, ?string $color);
107+
public function updateTag(string $tagId, string $newName, bool $userVisible, bool $userAssignable, ?string $color, ?IUser $user = null): void;
104108

105109
/**
106110
* Delete the given tags from the database and all their relationships.

tests/lib/SystemTag/SystemTagManagerTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,22 +296,22 @@ public static function updateTagProvider(): array {
296296
return [
297297
[
298298
// update name
299-
['one', true, true, '0082c9'],
299+
['one', true, true],
300300
['two', true, true, '0082c9']
301301
],
302302
[
303303
// update one flag
304-
['one', false, true, null],
304+
['one', false, true],
305305
['one', true, true, '0082c9']
306306
],
307307
[
308308
// update all flags
309-
['one', false, false, '0082c9'],
309+
['one', false, false],
310310
['one', true, true, null]
311311
],
312312
[
313313
// update all
314-
['one', false, false, '0082c9'],
314+
['one', false, false],
315315
['two', true, true, '0082c9']
316316
],
317317
];
@@ -323,7 +323,6 @@ public function testUpdateTag($tagCreate, $tagUpdated): void {
323323
$tagCreate[0],
324324
$tagCreate[1],
325325
$tagCreate[2],
326-
$tagCreate[3],
327326
);
328327
$this->tagManager->updateTag(
329328
$tag1->getId(),
@@ -336,7 +335,6 @@ public function testUpdateTag($tagCreate, $tagUpdated): void {
336335
$tagUpdated[0],
337336
$tagUpdated[1],
338337
$tagUpdated[2],
339-
$tagUpdated[3],
340338
);
341339

342340
$this->assertEquals($tag2->getId(), $tag1->getId());

0 commit comments

Comments
 (0)