Skip to content

Commit a304a54

Browse files
Merge pull request #58836 from nextcloud/feat/noid/unify-generated-by-ai-tag-handling
feat(systemtags): Add methods to directly do "Generated by AI" tag
2 parents 1a70d19 + 1425df4 commit a304a54

5 files changed

Lines changed: 37 additions & 0 deletions

File tree

lib/private/SystemTag/SystemTagManager.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ public function getTag(string $tagName, bool $userVisible, bool $userAssignable)
150150
return $this->createSystemTagFromRow($row);
151151
}
152152

153+
#[\Override]
154+
public function getGeneratedByAITag(): ISystemTag {
155+
try {
156+
return $this->getTag(ISystemTag::GENERATED_BY_AI, true, true);
157+
} catch (TagNotFoundException) {
158+
return $this->createTag(ISystemTag::GENERATED_BY_AI, true, true);
159+
}
160+
}
161+
153162
public function createTag(string $tagName, bool $userVisible, bool $userAssignable): ISystemTag {
154163
$user = $this->userSession->getUser();
155164
if (!$this->canUserCreateTag($user)) {

lib/private/SystemTag/SystemTagObjectMapper.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ public function assignTags(string $objId, string $objectType, $tagIds): void {
176176
$this->dispatcher->dispatchTyped(new TagAssignedEvent($objectType, [$objId], $tagsAssigned));
177177
}
178178

179+
#[Override]
180+
public function assignGeneratedByAITag(string $objId, string $objectType) {
181+
$tag = $this->tagManager->getGeneratedByAITag();
182+
$this->assignTags($objId, $objectType, [$tag->getId()]);
183+
}
184+
179185
#[Override]
180186
public function unassignTags(string $objId, string $objectType, $tagIds): void {
181187
if (!\is_array($tagIds)) {

lib/public/SystemTag/ISystemTag.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ interface ISystemTag {
3636
ISystemTag::ACCESS_LEVEL_INVISIBLE => 'invisible',
3737
];
3838

39+
/**
40+
* @since 34.0.0
41+
*/
42+
public const GENERATED_BY_AI = 'Generated by AI';
43+
3944
/**
4045
* Returns the tag id
4146
*

lib/public/SystemTag/ISystemTagManager.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ public function getTagsByIds($tagIds, ?IUser $user = null): array;
4747
*/
4848
public function getTag(string $tagName, bool $userVisible, bool $userAssignable): ISystemTag;
4949

50+
/**
51+
* Returns the tag object to mark AI generated content with
52+
*
53+
* @return ISystemTag system tag
54+
* @since 34.0.0
55+
*/
56+
public function getGeneratedByAITag(): ISystemTag;
57+
5058
/**
5159
* Creates the tag object using the given attributes.
5260
*

lib/public/SystemTag/ISystemTagObjectMapper.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ public function getObjectIdsForTags($tagIds, string $objectType, int $limit = 0,
8181
*/
8282
public function assignTags(string $objId, string $objectType, $tagIds);
8383

84+
/**
85+
* Assign the "Generated by AI" tag to the given object.
86+
*
87+
* @param string $objId object id
88+
* @param string $objectType object type
89+
* @since 34.0.0
90+
*/
91+
public function assignGeneratedByAITag(string $objId, string $objectType);
92+
8493
/**
8594
* Unassign the given tags from the given object.
8695
*

0 commit comments

Comments
 (0)