diff --git a/apps/dav/lib/SystemTag/SystemTagNode.php b/apps/dav/lib/SystemTag/SystemTagNode.php
index 350547865f9ab..da51279a9d250 100644
--- a/apps/dav/lib/SystemTag/SystemTagNode.php
+++ b/apps/dav/lib/SystemTag/SystemTagNode.php
@@ -13,6 +13,7 @@
use OCP\SystemTag\ISystemTagObjectMapper;
use OCP\SystemTag\TagAlreadyExistsException;
use OCP\SystemTag\TagNotFoundException;
+use Sabre\DAV\Exception\BadRequest;
use Sabre\DAV\Exception\Conflict;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\MethodNotAllowed;
@@ -111,6 +112,11 @@ public function update($name, $userVisible, $userAssignable, $color): void {
}
}
+ // Make sure color is a proper hex
+ if ($color !== null && (strlen($color) !== 6 || !ctype_xdigit($color))) {
+ throw new BadRequest('Color must be a 6-digit hexadecimal value');
+ }
+
$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');
diff --git a/core/Command/SystemTag/Edit.php b/core/Command/SystemTag/Edit.php
index eb6412b763991..614f2798ce4c2 100644
--- a/core/Command/SystemTag/Edit.php
+++ b/core/Command/SystemTag/Edit.php
@@ -40,6 +40,12 @@ protected function configure() {
null,
InputOption::VALUE_OPTIONAL,
'sets the access control level (public, restricted, invisible)',
+ )
+ ->addOption(
+ 'color',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'set the tag color',
);
}
@@ -80,9 +86,24 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}
+ $color = $tag->getColor();
+ if ($input->hasOption('color')) {
+ $color = $input->getOption('color');
+ if (substr($color, 0, 1) === '#') {
+ $color = substr($color, 1);
+ }
+
+ if ($input->getOption('color') === '') {
+ $color = null;
+ } elseif (strlen($color) !== 6 || !ctype_xdigit($color)) {
+ $output->writeln('Color must be a 6-digit hexadecimal value');
+ return 2;
+ }
+ }
+
try {
- $this->systemTagManager->updateTag($input->getArgument('id'), $name, $userVisible, $userAssignable);
- $output->writeln('Tag updated ("' . $name . '", ' . $userVisible . ', ' . $userAssignable . ')');
+ $this->systemTagManager->updateTag($input->getArgument('id'), $name, $userVisible, $userAssignable, $color);
+ $output->writeln('Tag updated ("' . $name . '", ' . json_encode($userVisible) . ', ' . json_encode($userAssignable) . ', "' . ($color ? "#$color" : '') . '")');
return 0;
} catch (TagNotFoundException $e) {
$output->writeln('Tag not found');
diff --git a/tests/Core/Command/SystemTag/EditTest.php b/tests/Core/Command/SystemTag/EditTest.php
index f269559190565..0d2f6ba4fbc9c 100644
--- a/tests/Core/Command/SystemTag/EditTest.php
+++ b/tests/Core/Command/SystemTag/EditTest.php
@@ -81,13 +81,14 @@ public function testExecute(): void {
$tagId,
$newTagName,
$newTagUserVisible,
- $newTagUserAssignable
+ $newTagUserAssignable,
+ ''
);
$this->output->expects($this->once())
->method('writeln')
->with(
- 'Tag updated ("' . $newTagName . '", ' . $newTagUserVisible . ', ' . $newTagUserAssignable . ')'
+ 'Tag updated ("' . $newTagName . '", ' . json_encode($newTagUserVisible) . ', ' . json_encode($newTagUserAssignable) . ', "")'
);
$this->invokePrivate($this->command, 'execute', [$this->input, $this->output]);
@@ -145,7 +146,8 @@ public function testAlreadyExists(): void {
$tagId,
$newTagName,
$newTagUserVisible,
- $newTagUserAssignable
+ $newTagUserAssignable,
+ ''
);
$this->output->expects($this->once())