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
This commit is contained in:
Joas Schilling 2026-03-11 10:02:20 +01:00 committed by GitHub
commit a304a54775
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 37 additions and 0 deletions

View file

@ -150,6 +150,15 @@ class SystemTagManager implements ISystemTagManager {
return $this->createSystemTagFromRow($row);
}
#[\Override]
public function getGeneratedByAITag(): ISystemTag {
try {
return $this->getTag(ISystemTag::GENERATED_BY_AI, true, true);
} catch (TagNotFoundException) {
return $this->createTag(ISystemTag::GENERATED_BY_AI, true, true);
}
}
public function createTag(string $tagName, bool $userVisible, bool $userAssignable): ISystemTag {
$user = $this->userSession->getUser();
if (!$this->canUserCreateTag($user)) {

View file

@ -176,6 +176,12 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
$this->dispatcher->dispatchTyped(new TagAssignedEvent($objectType, [$objId], $tagsAssigned));
}
#[Override]
public function assignGeneratedByAITag(string $objId, string $objectType) {
$tag = $this->tagManager->getGeneratedByAITag();
$this->assignTags($objId, $objectType, [$tag->getId()]);
}
#[Override]
public function unassignTags(string $objId, string $objectType, $tagIds): void {
if (!\is_array($tagIds)) {

View file

@ -36,6 +36,11 @@ interface ISystemTag {
ISystemTag::ACCESS_LEVEL_INVISIBLE => 'invisible',
];
/**
* @since 34.0.0
*/
public const GENERATED_BY_AI = 'Generated by AI';
/**
* Returns the tag id
*

View file

@ -47,6 +47,14 @@ interface ISystemTagManager {
*/
public function getTag(string $tagName, bool $userVisible, bool $userAssignable): ISystemTag;
/**
* Returns the tag object to mark AI generated content with
*
* @return ISystemTag system tag
* @since 34.0.0
*/
public function getGeneratedByAITag(): ISystemTag;
/**
* Creates the tag object using the given attributes.
*

View file

@ -81,6 +81,15 @@ interface ISystemTagObjectMapper {
*/
public function assignTags(string $objId, string $objectType, $tagIds);
/**
* Assign the "Generated by AI" tag to the given object.
*
* @param string $objId object id
* @param string $objectType object type
* @since 34.0.0
*/
public function assignGeneratedByAITag(string $objId, string $objectType);
/**
* Unassign the given tags from the given object.
*