Skip to content

Commit 0d42292

Browse files
Merge pull request nextcloud#62810 from nextcloud/systemtag-update-permissions
fix: require admin permissions for all systemtag updates
2 parents bd72241 + 575702b commit 0d42292

3 files changed

Lines changed: 26 additions & 27 deletions

File tree

‎apps/dav/lib/SystemTag/SystemTagNode.php‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,10 @@ public function update($name, $userVisible, $userAssignable, $color): void {
101101
if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) {
102102
throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist');
103103
}
104-
if (!$this->tagManager->canUserAssignTag($this->tag, $this->user)) {
105-
throw new Forbidden('No permission to update tag ' . $this->tag->getId());
106-
}
107104

108-
// only admin is able to change permissions, regular users can only rename
105+
// only admin is able to update system tags
109106
if (!$this->isAdmin) {
110-
// only renaming is allowed for regular users
111-
if ($userVisible !== $this->tag->isUserVisible()
112-
|| $userAssignable !== $this->tag->isUserAssignable()
113-
) {
114-
throw new Forbidden('No permission to update permissions for tag ' . $this->tag->getId());
115-
}
107+
throw new Forbidden('No permission to update tag ' . $this->tag->getId());
116108
}
117109

118110
// Make sure color is a proper hex

‎apps/dav/tests/unit/SystemTag/SystemTagNodeTest.php‎

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,36 +70,43 @@ public static function tagNodeProvider(): array {
7070
[
7171
true,
7272
new SystemTag('1', 'Original', true, true),
73-
['Renamed', true, true, null]
73+
['Renamed', true, true, null],
74+
true,
7475
],
7576
[
7677
true,
7778
new SystemTag('1', 'Original', true, true),
78-
['Original', false, false, null]
79+
['Original', false, false, null],
80+
true,
7981
],
8082
// non-admin
8183
[
82-
// renaming allowed
84+
// renaming not allowed
8385
false,
8486
new SystemTag('1', 'Original', true, true),
85-
['Rename', true, true, '0082c9']
87+
['Renamed', true, true, null],
88+
false,
8689
],
8790
];
8891
}
8992

9093
#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'tagNodeProvider')]
91-
public function testUpdateTag(bool $isAdmin, ISystemTag $originalTag, array $changedArgs): void {
92-
$this->tagManager->expects($this->once())
93-
->method('canUserSeeTag')
94+
public function testUpdateTag(bool $isAdmin, ISystemTag $originalTag, $changedArgs, $allowed): void {
95+
$this->tagManager->method('canUserSeeTag')
9496
->with($originalTag)
9597
->willReturn($originalTag->isUserVisible() || $isAdmin);
96-
$this->tagManager->expects($this->once())
97-
->method('canUserAssignTag')
98+
$this->tagManager->method('canUserAssignTag')
9899
->with($originalTag)
99100
->willReturn($originalTag->isUserAssignable() || $isAdmin);
100-
$this->tagManager->expects($this->once())
101-
->method('updateTag')
102-
->with(1, $changedArgs[0], $changedArgs[1], $changedArgs[2], $changedArgs[3]);
101+
if ($allowed) {
102+
$this->tagManager->expects($this->once())
103+
->method('updateTag')
104+
->with(1, $changedArgs[0], $changedArgs[1], $changedArgs[2], $changedArgs[3]);
105+
} else {
106+
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
107+
$this->tagManager->expects($this->never())
108+
->method('updateTag');
109+
}
103110
$this->getTagNode($isAdmin, $originalTag)
104111
->update($changedArgs[0], $changedArgs[1], $changedArgs[2], $changedArgs[3]);
105112
}
@@ -186,7 +193,7 @@ public function testUpdateTagAlreadyExists(): void {
186193
->method('updateTag')
187194
->with(1, 'Renamed', true, true)
188195
->willThrowException(new TagAlreadyExistsException());
189-
$this->getTagNode(false, $tag)->update('Renamed', true, true, null);
196+
$this->getTagNode(true, $tag)->update('Renamed', true, true, null);
190197
}
191198

192199
public function testUpdateTagNotFound(): void {
@@ -205,7 +212,7 @@ public function testUpdateTagNotFound(): void {
205212
->method('updateTag')
206213
->with(1, 'Renamed', true, true)
207214
->willThrowException(new TagNotFoundException());
208-
$this->getTagNode(false, $tag)->update('Renamed', true, true, null);
215+
$this->getTagNode(true, $tag)->update('Renamed', true, true, null);
209216
}
210217

211218
#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'adminFlagProvider')]

‎build/integration/files_features/tags.feature‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ Feature: tags
3636
Then The response should have a status code "400"
3737
And "0" tags should exist for "user0"
3838

39-
Scenario: Renaming a normal tag as regular user should work
39+
Scenario: Renaming a normal tag as regular user should fail
4040
Given user "user0" exists
4141
Given "admin" creates a "normal" tag with name "MySuperAwesomeTagName"
4242
When "user0" edits the tag with name "MySuperAwesomeTagName" and sets its name to "AnotherTagName"
43-
Then The response should have a status code "207"
43+
Then The response should have a status code "403"
4444
And The following tags should exist for "admin"
45-
|AnotherTagName|true|true|
45+
|MySuperAwesomeTagName|true|true|
4646

4747
Scenario: Renaming a not user-assignable tag as regular user should fail
4848
Given user "user0" exists

0 commit comments

Comments
 (0)