diff options
16 files changed, 133 insertions, 101 deletions
diff --git a/apps/dav/lib/SystemTag/SystemTagNode.php b/apps/dav/lib/SystemTag/SystemTagNode.php index ed4eb44cbbd..350547865f9 100644 --- a/apps/dav/lib/SystemTag/SystemTagNode.php +++ b/apps/dav/lib/SystemTag/SystemTagNode.php @@ -86,12 +86,13 @@ class SystemTagNode implements \Sabre\DAV\ICollection { * @param string $name new tag name * @param bool $userVisible user visible * @param bool $userAssignable user assignable + * @param string $color color * * @throws NotFound whenever the given tag id does not exist * @throws Forbidden whenever there is no permission to update said tag * @throws Conflict whenever a tag already exists with the given attributes */ - public function update($name, $userVisible, $userAssignable): void { + public function update($name, $userVisible, $userAssignable, $color): void { try { if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) { throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist'); @@ -110,7 +111,7 @@ class SystemTagNode implements \Sabre\DAV\ICollection { } } - $this->tagManager->updateTag($this->tag->getId(), $name, $userVisible, $userAssignable); + $this->tagManager->updateTag($this->tag->getId(), $name, $userVisible, $userAssignable, $color); } catch (TagNotFoundException $e) { throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist'); } catch (TagAlreadyExistsException $e) { diff --git a/apps/dav/lib/SystemTag/SystemTagPlugin.php b/apps/dav/lib/SystemTag/SystemTagPlugin.php index 00585953b29..afa4b8149d0 100644 --- a/apps/dav/lib/SystemTag/SystemTagPlugin.php +++ b/apps/dav/lib/SystemTag/SystemTagPlugin.php @@ -49,6 +49,7 @@ class SystemTagPlugin extends \Sabre\DAV\ServerPlugin { public const NUM_FILES_PROPERTYNAME = '{http://nextcloud.org/ns}files-assigned'; public const REFERENCE_FILEID_PROPERTYNAME = '{http://nextcloud.org/ns}reference-fileid'; public const OBJECTIDS_PROPERTYNAME = '{http://nextcloud.org/ns}object-ids'; + public const COLOR_PROPERTYNAME = '{http://nextcloud.org/ns}color'; /** * @var \Sabre\DAV\Server $server @@ -243,6 +244,10 @@ class SystemTagPlugin extends \Sabre\DAV\ServerPlugin { return $this->tagManager->canUserAssignTag($node->getSystemTag(), $this->userSession->getUser()) ? 'true' : 'false'; }); + $propFind->handle(self::COLOR_PROPERTYNAME, function () use ($node) { + return $node->getSystemTag()->getColor() ?? ''; + }); + $propFind->handle(self::GROUPS_PROPERTYNAME, function () use ($node) { if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { // property only available for admins @@ -406,6 +411,7 @@ class SystemTagPlugin extends \Sabre\DAV\ServerPlugin { self::GROUPS_PROPERTYNAME, self::NUM_FILES_PROPERTYNAME, self::REFERENCE_FILEID_PROPERTYNAME, + self::COLOR_PROPERTYNAME, ], function ($props) use ($node) { if (!($node instanceof SystemTagNode)) { return false; @@ -415,6 +421,7 @@ class SystemTagPlugin extends \Sabre\DAV\ServerPlugin { $name = $tag->getName(); $userVisible = $tag->isUserVisible(); $userAssignable = $tag->isUserAssignable(); + $color = $tag->getColor(); $updateTag = false; @@ -435,6 +442,11 @@ class SystemTagPlugin extends \Sabre\DAV\ServerPlugin { $updateTag = true; } + if (isset($props[self::COLOR_PROPERTYNAME])) { + $color = $props[self::COLOR_PROPERTYNAME]; + $updateTag = true; + } + if (isset($props[self::GROUPS_PROPERTYNAME])) { if (!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) { // property only available for admins @@ -452,7 +464,7 @@ class SystemTagPlugin extends \Sabre\DAV\ServerPlugin { } if ($updateTag) { - $node->update($name, $userVisible, $userAssignable); + $node->update($name, $userVisible, $userAssignable, $color); } return true; diff --git a/apps/dav/lib/SystemTag/SystemTagsInUseCollection.php b/apps/dav/lib/SystemTag/SystemTagsInUseCollection.php index 9b02a5be42c..f11482b04ee 100644 --- a/apps/dav/lib/SystemTag/SystemTagsInUseCollection.php +++ b/apps/dav/lib/SystemTag/SystemTagsInUseCollection.php @@ -73,7 +73,7 @@ class SystemTagsInUseCollection extends SimpleCollection { $result = $this->systemTagsInFilesDetector->detectAssignedSystemTagsIn($userFolder, $this->mediaType); $children = []; foreach ($result as $tagData) { - $tag = new SystemTag((string)$tagData['id'], $tagData['name'], (bool)$tagData['visibility'], (bool)$tagData['editable'], $tagData['etag']); + $tag = new SystemTag((string)$tagData['id'], $tagData['name'], (bool)$tagData['visibility'], (bool)$tagData['editable'], $tagData['etag'], $tagData['color']); // read only, so we can submit the isAdmin parameter as false generally $node = new SystemTagNode($tag, $user, false, $this->systemTagManager, $this->tagMapper); $node->setNumberOfFiles((int)$tagData['number_files']); diff --git a/apps/dav/tests/unit/SystemTag/SystemTagNodeTest.php b/apps/dav/tests/unit/SystemTag/SystemTagNodeTest.php index b84eb90b7bf..0d6012b5a88 100644 --- a/apps/dav/tests/unit/SystemTag/SystemTagNodeTest.php +++ b/apps/dav/tests/unit/SystemTag/SystemTagNodeTest.php @@ -85,19 +85,19 @@ class SystemTagNodeTest extends \Test\TestCase { [ true, new SystemTag(1, 'Original', true, true), - ['Renamed', true, true] + ['Renamed', true, true, ''] ], [ true, new SystemTag(1, 'Original', true, true), - ['Original', false, false] + ['Original', false, false, ''] ], // non-admin [ // renaming allowed false, new SystemTag(1, 'Original', true, true), - ['Rename', true, true] + ['Rename', true, true, '#0082c9'] ], ]; } @@ -116,9 +116,9 @@ class SystemTagNodeTest extends \Test\TestCase { ->willReturn($originalTag->isUserAssignable() || $isAdmin); $this->tagManager->expects($this->once()) ->method('updateTag') - ->with(1, $changedArgs[0], $changedArgs[1], $changedArgs[2]); + ->with(1, $changedArgs[0], $changedArgs[1], $changedArgs[2], $changedArgs[3]); $this->getTagNode($isAdmin, $originalTag) - ->update($changedArgs[0], $changedArgs[1], $changedArgs[2]); + ->update($changedArgs[0], $changedArgs[1], $changedArgs[2], $changedArgs[3]); } public function tagNodeProviderPermissionException() { @@ -126,37 +126,37 @@ class SystemTagNodeTest extends \Test\TestCase { [ // changing permissions not allowed new SystemTag(1, 'Original', true, true), - ['Original', false, true], + ['Original', false, true, ''], 'Sabre\DAV\Exception\Forbidden', ], [ // changing permissions not allowed new SystemTag(1, 'Original', true, true), - ['Original', true, false], + ['Original', true, false, ''], 'Sabre\DAV\Exception\Forbidden', ], [ // changing permissions not allowed new SystemTag(1, 'Original', true, true), - ['Original', false, false], + ['Original', false, false, ''], 'Sabre\DAV\Exception\Forbidden', ], [ // changing non-assignable not allowed new SystemTag(1, 'Original', true, false), - ['Rename', true, false], + ['Rename', true, false, ''], 'Sabre\DAV\Exception\Forbidden', ], [ // changing non-assignable not allowed new SystemTag(1, 'Original', true, false), - ['Original', true, true], + ['Original', true, true, ''], 'Sabre\DAV\Exception\Forbidden', ], [ // invisible tag does not exist new SystemTag(1, 'Original', false, false), - ['Rename', false, false], + ['Rename', false, false, ''], 'Sabre\DAV\Exception\NotFound', ], ]; @@ -181,7 +181,7 @@ class SystemTagNodeTest extends \Test\TestCase { try { $this->getTagNode(false, $originalTag) - ->update($changedArgs[0], $changedArgs[1], $changedArgs[2]); + ->update($changedArgs[0], $changedArgs[1], $changedArgs[2], $changedArgs[3]); } catch (\Exception $e) { $thrown = $e; } @@ -206,7 +206,7 @@ class SystemTagNodeTest extends \Test\TestCase { ->method('updateTag') ->with(1, 'Renamed', true, true) ->will($this->throwException(new TagAlreadyExistsException())); - $this->getTagNode(false, $tag)->update('Renamed', true, true); + $this->getTagNode(false, $tag)->update('Renamed', true, true, ''); } @@ -226,7 +226,7 @@ class SystemTagNodeTest extends \Test\TestCase { ->method('updateTag') ->with(1, 'Renamed', true, true) ->will($this->throwException(new TagNotFoundException())); - $this->getTagNode(false, $tag)->update('Renamed', true, true); + $this->getTagNode(false, $tag)->update('Renamed', true, true, ''); } /** diff --git a/apps/systemtags/composer/composer/autoload_classmap.php b/apps/systemtags/composer/composer/autoload_classmap.php index 20174ee4667..e6c60728ff6 100644 --- a/apps/systemtags/composer/composer/autoload_classmap.php +++ b/apps/systemtags/composer/composer/autoload_classmap.php @@ -16,6 +16,8 @@ return array( 'OCA\\SystemTags\\Listeners\\BeforeSabrePubliclyLoadedListener' => $baseDir . '/../lib/Listeners/BeforeSabrePubliclyLoadedListener.php', 'OCA\\SystemTags\\Listeners\\BeforeTemplateRenderedListener' => $baseDir . '/../lib/Listeners/BeforeTemplateRenderedListener.php', 'OCA\\SystemTags\\Listeners\\LoadAdditionalScriptsListener' => $baseDir . '/../lib/Listeners/LoadAdditionalScriptsListener.php', + 'OCA\\SystemTags\\Migration\\Version31000Date20241018063111' => $baseDir . '/../lib/Migration/Version31000Date20241018063111.php', + 'OCA\\SystemTags\\Migration\\Version31000Date20241114171300' => $baseDir . '/../lib/Migration/Version31000Date20241114171300.php', 'OCA\\SystemTags\\Search\\TagSearchProvider' => $baseDir . '/../lib/Search/TagSearchProvider.php', 'OCA\\SystemTags\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php', ); diff --git a/apps/systemtags/composer/composer/autoload_static.php b/apps/systemtags/composer/composer/autoload_static.php index 04dae4aa52f..3d61ea1a1c1 100644 --- a/apps/systemtags/composer/composer/autoload_static.php +++ b/apps/systemtags/composer/composer/autoload_static.php @@ -31,6 +31,8 @@ class ComposerStaticInitSystemTags 'OCA\\SystemTags\\Listeners\\BeforeSabrePubliclyLoadedListener' => __DIR__ . '/..' . '/../lib/Listeners/BeforeSabrePubliclyLoadedListener.php', 'OCA\\SystemTags\\Listeners\\BeforeTemplateRenderedListener' => __DIR__ . '/..' . '/../lib/Listeners/BeforeTemplateRenderedListener.php', 'OCA\\SystemTags\\Listeners\\LoadAdditionalScriptsListener' => __DIR__ . '/..' . '/../lib/Listeners/LoadAdditionalScriptsListener.php', + 'OCA\\SystemTags\\Migration\\Version31000Date20241018063111' => __DIR__ . '/..' . '/../lib/Migration/Version31000Date20241018063111.php', + 'OCA\\SystemTags\\Migration\\Version31000Date20241114171300' => __DIR__ . '/..' . '/../lib/Migration/Version31000Date20241114171300.php', 'OCA\\SystemTags\\Search\\TagSearchProvider' => __DIR__ . '/..' . '/../lib/Search/TagSearchProvider.php', 'OCA\\SystemTags\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php', ); diff --git a/core/Migrations/Version31000Date20241018063111.php b/apps/systemtags/lib/Migration/Version31000Date20241018063111.php index ce4c42df159..f813c4e0dee 100644 --- a/core/Migrations/Version31000Date20241018063111.php +++ b/apps/systemtags/lib/Migration/Version31000Date20241018063111.php @@ -7,7 +7,7 @@ declare(strict_types=1); * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace OC\Core\Migrations; +namespace OCA\SystemTags\Migration; use Closure; use Doctrine\DBAL\Types\Types; @@ -26,12 +26,6 @@ use OCP\Migration\SimpleMigrationStep; #[AddIndex(table: 'systemtag_object_mapping', type: IndexType::INDEX, description: 'Adding objecttype index to systemtag_object_mapping')] class Version31000Date20241018063111 extends SimpleMigrationStep { - /** - * @param IOutput $output - * @param Closure(): ISchemaWrapper $schemaClosure - * @param array $options - * @return null|ISchemaWrapper - */ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); diff --git a/apps/systemtags/lib/Migration/Version31000Date20241114171300.php b/apps/systemtags/lib/Migration/Version31000Date20241114171300.php new file mode 100644 index 00000000000..5830d3aefae --- /dev/null +++ b/apps/systemtags/lib/Migration/Version31000Date20241114171300.php @@ -0,0 +1,43 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCA\SystemTags\Migration; + +use Closure; +use Doctrine\DBAL\Types\Types; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\Attributes\AddColumn; +use OCP\Migration\Attributes\ColumnType; +use OCP\Migration\IOutput; +use OCP\Migration\SimpleMigrationStep; + +/** + * Add objecttype index to systemtag_object_mapping + */ +#[AddColumn(table: 'systemtag', name: 'color', type: ColumnType::STRING, description: 'Adding color for systemtag table')] +class Version31000Date20241114171300 extends SimpleMigrationStep { + + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + if ($schema->hasTable('systemtag')) { + $table = $schema->getTable('systemtag'); + + if (!$table->hasColumn('color')) { + $table->addColumn('color', Types::STRING, [ + 'notnull' => false, + 'length' => 6, + ]); + } + } + + return $schema; + } +} diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 94e6e1f1e41..746e43248d8 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -1416,7 +1416,6 @@ return array( 'OC\\Core\\Migrations\\Version30000Date20240906095113' => $baseDir . '/core/Migrations/Version30000Date20240906095113.php', 'OC\\Core\\Migrations\\Version31000Date20240101084401' => $baseDir . '/core/Migrations/Version31000Date20240101084401.php', 'OC\\Core\\Migrations\\Version31000Date20240814184402' => $baseDir . '/core/Migrations/Version31000Date20240814184402.php', - 'OC\\Core\\Migrations\\Version31000Date20241018063111' => $baseDir . '/core/Migrations/Version31000Date20241018063111.php', 'OC\\Core\\Notification\\CoreNotifier' => $baseDir . '/core/Notification/CoreNotifier.php', 'OC\\Core\\ResponseDefinitions' => $baseDir . '/core/ResponseDefinitions.php', 'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 246934b4848..62124d74496 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -1457,7 +1457,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\Core\\Migrations\\Version30000Date20240906095113' => __DIR__ . '/../../..' . '/core/Migrations/Version30000Date20240906095113.php', 'OC\\Core\\Migrations\\Version31000Date20240101084401' => __DIR__ . '/../../..' . '/core/Migrations/Version31000Date20240101084401.php', 'OC\\Core\\Migrations\\Version31000Date20240814184402' => __DIR__ . '/../../..' . '/core/Migrations/Version31000Date20240814184402.php', - 'OC\\Core\\Migrations\\Version31000Date20241018063111' => __DIR__ . '/../../..' . '/core/Migrations/Version31000Date20241018063111.php', 'OC\\Core\\Notification\\CoreNotifier' => __DIR__ . '/../../..' . '/core/Notification/CoreNotifier.php', 'OC\\Core\\ResponseDefinitions' => __DIR__ . '/../../..' . '/core/ResponseDefinitions.php', 'OC\\Core\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php', diff --git a/lib/composer/composer/installed.php b/lib/composer/composer/installed.php index 3d7c94e736c..bd6f4140a96 100644 --- a/lib/composer/composer/installed.php +++ b/lib/composer/composer/installed.php @@ -3,7 +3,7 @@ 'name' => '__root__', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => 'd481e4c575c189d6ddb128740892dd54a7c7ed48', + 'reference' => 'ee76fe192de8656d216b4079a6c50dda3fc9cdb1', 'type' => 'library', 'install_path' => __DIR__ . '/../../../', 'aliases' => array(), @@ -13,7 +13,7 @@ '__root__' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => 'd481e4c575c189d6ddb128740892dd54a7c7ed48', + 'reference' => 'ee76fe192de8656d216b4079a6c50dda3fc9cdb1', 'type' => 'library', 'install_path' => __DIR__ . '/../../../', 'aliases' => array(), diff --git a/lib/private/SystemTag/SystemTag.php b/lib/private/SystemTag/SystemTag.php index 8c64f2389d0..1a573dabeaa 100644 --- a/lib/private/SystemTag/SystemTag.php +++ b/lib/private/SystemTag/SystemTag.php @@ -17,40 +17,26 @@ class SystemTag implements ISystemTag { private bool $userVisible, private bool $userAssignable, private ?string $etag = null, + private ?string $color = null, ) { } - /** - * {@inheritdoc} - */ public function getId(): string { return $this->id; } - /** - * {@inheritdoc} - */ public function getName(): string { return $this->name; } - /** - * {@inheritdoc} - */ public function isUserVisible(): bool { return $this->userVisible; } - /** - * {@inheritdoc} - */ public function isUserAssignable(): bool { return $this->userAssignable; } - /** - * {@inheritdoc} - */ public function getAccessLevel(): int { if (!$this->userVisible) { return self::ACCESS_LEVEL_INVISIBLE; @@ -63,10 +49,11 @@ class SystemTag implements ISystemTag { return self::ACCESS_LEVEL_PUBLIC; } - /** - * {@inheritdoc} - */ public function getETag(): ?string { return $this->etag; } + + public function getColor(): ?string { + return $this->color; + } } diff --git a/lib/private/SystemTag/SystemTagManager.php b/lib/private/SystemTag/SystemTagManager.php index 70bb8e6e70b..4f05d40c34c 100644 --- a/lib/private/SystemTag/SystemTagManager.php +++ b/lib/private/SystemTag/SystemTagManager.php @@ -45,9 +45,6 @@ class SystemTagManager implements ISystemTagManager { ->andWhere($query->expr()->eq('editable', $query->createParameter('editable'))); } - /** - * {@inheritdoc} - */ public function getTagsByIds($tagIds, ?IUser $user = null): array { if (!\is_array($tagIds)) { $tagIds = [$tagIds]; @@ -92,9 +89,6 @@ class SystemTagManager implements ISystemTagManager { return $tags; } - /** - * {@inheritdoc} - */ public function getAllTags($visibilityFilter = null, $nameSearchPattern = null): array { $tags = []; @@ -130,9 +124,6 @@ class SystemTagManager implements ISystemTagManager { return $tags; } - /** - * {@inheritdoc} - */ public function getTag(string $tagName, bool $userVisible, bool $userAssignable): ISystemTag { // Length of name column is 64 $truncatedTagName = substr($tagName, 0, 64); @@ -153,9 +144,6 @@ class SystemTagManager implements ISystemTagManager { return $this->createSystemTagFromRow($row); } - /** - * {@inheritdoc} - */ public function createTag(string $tagName, bool $userVisible, bool $userAssignable): ISystemTag { // Length of name column is 64 $truncatedTagName = substr($tagName, 0, 64); @@ -194,14 +182,12 @@ class SystemTagManager implements ISystemTagManager { return $tag; } - /** - * {@inheritdoc} - */ public function updateTag( string $tagId, string $newName, bool $userVisible, bool $userAssignable, + ?string $color, ): void { try { $tags = $this->getTagsByIds($tagId); @@ -218,7 +204,9 @@ class SystemTagManager implements ISystemTagManager { $tagId, $truncatedNewName, $userVisible, - $userAssignable + $userAssignable, + $beforeUpdate->getETag(), + $color ); $query = $this->connection->getQueryBuilder(); @@ -226,11 +214,13 @@ class SystemTagManager implements ISystemTagManager { ->set('name', $query->createParameter('name')) ->set('visibility', $query->createParameter('visibility')) ->set('editable', $query->createParameter('editable')) + ->set('color', $query->createParameter('color')) ->where($query->expr()->eq('id', $query->createParameter('tagid'))) ->setParameter('name', $truncatedNewName) ->setParameter('visibility', $userVisible ? 1 : 0) ->setParameter('editable', $userAssignable ? 1 : 0) - ->setParameter('tagid', $tagId); + ->setParameter('tagid', $tagId) + ->setParameter('color', $color); try { if ($query->execute() === 0) { @@ -251,9 +241,6 @@ class SystemTagManager implements ISystemTagManager { )); } - /** - * {@inheritdoc} - */ public function deleteTags($tagIds): void { if (!\is_array($tagIds)) { $tagIds = [$tagIds]; @@ -303,9 +290,6 @@ class SystemTagManager implements ISystemTagManager { } } - /** - * {@inheritdoc} - */ public function canUserAssignTag(ISystemTag $tag, ?IUser $user): bool { if ($user === null) { return false; @@ -335,9 +319,6 @@ class SystemTagManager implements ISystemTagManager { return false; } - /** - * {@inheritdoc} - */ public function canUserSeeTag(ISystemTag $tag, ?IUser $user): bool { // If no user, then we only show public tags if (!$user && $tag->getAccessLevel() === ISystemTag::ACCESS_LEVEL_PUBLIC) { @@ -361,12 +342,9 @@ class SystemTagManager implements ISystemTagManager { } private function createSystemTagFromRow($row): SystemTag { - return new SystemTag((string)$row['id'], $row['name'], (bool)$row['visibility'], (bool)$row['editable'], $row['etag']); + return new SystemTag((string)$row['id'], $row['name'], (bool)$row['visibility'], (bool)$row['editable'], $row['etag'], $row['color']); } - /** - * {@inheritdoc} - */ public function setTagGroups(ISystemTag $tag, array $groupIds): void { // delete relationships first $this->connection->beginTransaction(); @@ -398,9 +376,6 @@ class SystemTagManager implements ISystemTagManager { } } - /** - * {@inheritdoc} - */ public function getTagGroups(ISystemTag $tag): array { $groupIds = []; $query = $this->connection->getQueryBuilder(); @@ -418,4 +393,5 @@ class SystemTagManager implements ISystemTagManager { return $groupIds; } + } diff --git a/lib/public/SystemTag/ISystemTag.php b/lib/public/SystemTag/ISystemTag.php index 593c127ba63..4fd93831955 100644 --- a/lib/public/SystemTag/ISystemTag.php +++ b/lib/public/SystemTag/ISystemTag.php @@ -89,4 +89,11 @@ interface ISystemTag { * @since 31.0.0 */ public function getETag(): ?string; + + /** + * Returns the color of the tag + * + * @since 31.0.0 + */ + public function getColor(): ?string; } diff --git a/lib/public/SystemTag/ISystemTagManager.php b/lib/public/SystemTag/ISystemTagManager.php index 1c08d3b22e1..04804798114 100644 --- a/lib/public/SystemTag/ISystemTagManager.php +++ b/lib/public/SystemTag/ISystemTagManager.php @@ -81,14 +81,16 @@ interface ISystemTagManager { * @param string $newName the new tag name * @param bool $userVisible whether the tag is visible by users * @param bool $userAssignable whether the tag is assignable by users + * @param string $color color * * @throws TagNotFoundException if tag with the given id does not exist * @throws TagAlreadyExistsException if there is already another tag * with the same attributes * * @since 9.0.0 + * @since 31.0.0 `$color` parameter added */ - public function updateTag(string $tagId, string $newName, bool $userVisible, bool $userAssignable); + public function updateTag(string $tagId, string $newName, bool $userVisible, bool $userAssignable, ?string $color); /** * Delete the given tags from the database and all their relationships. diff --git a/tests/lib/SystemTag/SystemTagManagerTest.php b/tests/lib/SystemTag/SystemTagManagerTest.php index 7b93d900bee..99f033cfd95 100644 --- a/tests/lib/SystemTag/SystemTagManagerTest.php +++ b/tests/lib/SystemTag/SystemTagManagerTest.php @@ -72,7 +72,7 @@ class SystemTagManagerTest extends TestCase { $query->delete(SystemTagManager::TAG_TABLE)->execute(); } - public function getAllTagsDataProvider() { + public static function getAllTagsDataProvider() { return [ [ // no tags at all @@ -119,7 +119,7 @@ class SystemTagManagerTest extends TestCase { } } - public function getAllTagsFilteredDataProvider() { + public static function getAllTagsFilteredDataProvider() { return [ [ [ @@ -232,7 +232,7 @@ class SystemTagManagerTest extends TestCase { } } - public function oneTagMultipleFlagsProvider() { + public static function oneTagMultipleFlagsProvider() { return [ ['one', false, false], ['one', true, false], @@ -305,27 +305,27 @@ class SystemTagManagerTest extends TestCase { $this->tagManager->getTagsByIds([$tag1->getId() . 'suffix']); } - public function updateTagProvider() { + public static function updateTagProvider() { return [ [ // update name - ['one', true, true], - ['two', true, true] + ['one', true, true, '0082c9'], + ['two', true, true, '0082c9'] ], [ // update one flag - ['one', false, true], - ['one', true, true] + ['one', false, true, null], + ['one', true, true, '0082c9'] ], [ // update all flags - ['one', false, false], - ['one', true, true] + ['one', false, false, '0082c9'], + ['one', true, true, null] ], [ // update all - ['one', false, false], - ['two', true, true] + ['one', false, false, '0082c9'], + ['two', true, true, '0082c9'] ], ]; } @@ -337,24 +337,29 @@ class SystemTagManagerTest extends TestCase { $tag1 = $this->tagManager->createTag( $tagCreate[0], $tagCreate[1], - $tagCreate[2] + $tagCreate[2], + $tagCreate[3], ); $this->tagManager->updateTag( $tag1->getId(), $tagUpdated[0], $tagUpdated[1], - $tagUpdated[2] + $tagUpdated[2], + $tagUpdated[3], ); $tag2 = $this->tagManager->getTag( $tagUpdated[0], $tagUpdated[1], - $tagUpdated[2] + $tagUpdated[2], + $tagUpdated[3], ); $this->assertEquals($tag2->getId(), $tag1->getId()); $this->assertEquals($tag2->getName(), $tagUpdated[0]); $this->assertEquals($tag2->isUserVisible(), $tagUpdated[1]); $this->assertEquals($tag2->isUserAssignable(), $tagUpdated[2]); + $this->assertEquals($tag2->getColor(), $tagUpdated[3]); + } /** @@ -366,12 +371,14 @@ class SystemTagManagerTest extends TestCase { $this->tagManager->createTag( $tagCreate[0], $tagCreate[1], - $tagCreate[2] + $tagCreate[2], + $tagCreate[3], ); $tag2 = $this->tagManager->createTag( $tagUpdated[0], $tagUpdated[1], - $tagUpdated[2] + $tagUpdated[2], + $tagUpdated[3], ); // update to match the first tag @@ -379,7 +386,8 @@ class SystemTagManagerTest extends TestCase { $tag2->getId(), $tagCreate[0], $tagCreate[1], - $tagCreate[2] + $tagCreate[2], + $tagCreate[3], ); } @@ -422,7 +430,7 @@ class SystemTagManagerTest extends TestCase { ], $tagIdMapping); } - public function visibilityCheckProvider() { + public static function visibilityCheckProvider() { return [ [false, false, false, false], [true, false, false, true], @@ -449,7 +457,7 @@ class SystemTagManagerTest extends TestCase { $this->assertEquals($expectedResult, $this->tagManager->canUserSeeTag($tag1, $user)); } - public function assignabilityCheckProvider() { + public static function assignabilityCheckProvider() { return [ // no groups [false, false, false, false], |