aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorskjnldsv <skjnldsv@protonmail.com>2024-11-15 15:59:55 +0100
committerskjnldsv <skjnldsv@protonmail.com>2024-12-06 10:19:42 +0100
commit0c7e2591517818862f6021c8e66a44f5b84d6a65 (patch)
tree2ffeb47a1b56be9387a9f9dd1b4f140fca51781b
parent4af365de733a92f3fdf157e0ff1ad2d0aa4893f1 (diff)
downloadnextcloud-server-0c7e2591517818862f6021c8e66a44f5b84d6a65.tar.gz
nextcloud-server-0c7e2591517818862f6021c8e66a44f5b84d6a65.zip
feat(systemtags): allow setting color with occ
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
-rw-r--r--apps/dav/lib/SystemTag/SystemTagNode.php6
-rw-r--r--apps/dav/tests/unit/SystemTag/SystemTagNodeTest.php10
-rw-r--r--core/Command/SystemTag/Edit.php25
-rw-r--r--tests/Core/Command/SystemTag/EditTest.php8
4 files changed, 39 insertions, 10 deletions
diff --git a/apps/dav/lib/SystemTag/SystemTagNode.php b/apps/dav/lib/SystemTag/SystemTagNode.php
index 350547865f9..da51279a9d2 100644
--- a/apps/dav/lib/SystemTag/SystemTagNode.php
+++ b/apps/dav/lib/SystemTag/SystemTagNode.php
@@ -13,6 +13,7 @@ use OCP\SystemTag\ISystemTagManager;
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 @@ class SystemTagNode implements \Sabre\DAV\ICollection {
}
}
+ // 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/apps/dav/tests/unit/SystemTag/SystemTagNodeTest.php b/apps/dav/tests/unit/SystemTag/SystemTagNodeTest.php
index 0d6012b5a88..32ee733dce8 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, null]
],
[
true,
new SystemTag(1, 'Original', true, true),
- ['Original', false, false, '']
+ ['Original', false, false, null]
],
// non-admin
[
// renaming allowed
false,
new SystemTag(1, 'Original', true, true),
- ['Rename', true, true, '#0082c9']
+ ['Rename', true, true, '0082c9']
],
];
}
@@ -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, null);
}
@@ -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, null);
}
/**
diff --git a/core/Command/SystemTag/Edit.php b/core/Command/SystemTag/Edit.php
index eb6412b7639..614f2798ce4 100644
--- a/core/Command/SystemTag/Edit.php
+++ b/core/Command/SystemTag/Edit.php
@@ -40,6 +40,12 @@ class Edit extends Base {
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 @@ class Edit extends Base {
}
}
+ $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('<error>Color must be a 6-digit hexadecimal value</error>');
+ return 2;
+ }
+ }
+
try {
- $this->systemTagManager->updateTag($input->getArgument('id'), $name, $userVisible, $userAssignable);
- $output->writeln('<info>Tag updated ("' . $name . '", ' . $userVisible . ', ' . $userAssignable . ')</info>');
+ $this->systemTagManager->updateTag($input->getArgument('id'), $name, $userVisible, $userAssignable, $color);
+ $output->writeln('<info>Tag updated ("' . $name . '", ' . json_encode($userVisible) . ', ' . json_encode($userAssignable) . ', "' . ($color ? "#$color" : '') . '")</info>');
return 0;
} catch (TagNotFoundException $e) {
$output->writeln('<error>Tag not found</error>');
diff --git a/tests/Core/Command/SystemTag/EditTest.php b/tests/Core/Command/SystemTag/EditTest.php
index f2695591905..0d2f6ba4fbc 100644
--- a/tests/Core/Command/SystemTag/EditTest.php
+++ b/tests/Core/Command/SystemTag/EditTest.php
@@ -81,13 +81,14 @@ class EditTest extends TestCase {
$tagId,
$newTagName,
$newTagUserVisible,
- $newTagUserAssignable
+ $newTagUserAssignable,
+ ''
);
$this->output->expects($this->once())
->method('writeln')
->with(
- '<info>Tag updated ("' . $newTagName . '", ' . $newTagUserVisible . ', ' . $newTagUserAssignable . ')</info>'
+ '<info>Tag updated ("' . $newTagName . '", ' . json_encode($newTagUserVisible) . ', ' . json_encode($newTagUserAssignable) . ', "")</info>'
);
$this->invokePrivate($this->command, 'execute', [$this->input, $this->output]);
@@ -145,7 +146,8 @@ class EditTest extends TestCase {
$tagId,
$newTagName,
$newTagUserVisible,
- $newTagUserAssignable
+ $newTagUserAssignable,
+ ''
);
$this->output->expects($this->once())