Skip to content

Commit 62ee7d0

Browse files
authored
Merge pull request #62920 from nextcloud/backport/62810/stable30
[stable30] fix: require admin permissions for all systemtag updates
2 parents 1f4c61a + 2fa6626 commit 62ee7d0

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
@@ -112,18 +112,10 @@ public function update($name, $userVisible, $userAssignable): void {
112112
if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) {
113113
throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist');
114114
}
115-
if (!$this->tagManager->canUserAssignTag($this->tag, $this->user)) {
116-
throw new Forbidden('No permission to update tag ' . $this->tag->getId());
117-
}
118115

119-
// only admin is able to change permissions, regular users can only rename
116+
// only admin is able to update system tags
120117
if (!$this->isAdmin) {
121-
// only renaming is allowed for regular users
122-
if ($userVisible !== $this->tag->isUserVisible()
123-
|| $userAssignable !== $this->tag->isUserAssignable()
124-
) {
125-
throw new Forbidden('No permission to update permissions for tag ' . $this->tag->getId());
126-
}
118+
throw new Forbidden('No permission to update tag ' . $this->tag->getId());
127119
}
128120

129121
$this->tagManager->updateTag($this->tag->getId(), $name, $userVisible, $userAssignable);

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

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,38 +75,45 @@ public function tagNodeProvider() {
7575
[
7676
true,
7777
new SystemTag(1, 'Original', true, true),
78-
['Renamed', true, true]
78+
['Renamed', true, true],
79+
true,
7980
],
8081
[
8182
true,
8283
new SystemTag(1, 'Original', true, true),
83-
['Original', false, false]
84+
['Original', false, false],
85+
true,
8486
],
8587
// non-admin
8688
[
87-
// renaming allowed
89+
// renaming not allowed
8890
false,
8991
new SystemTag(1, 'Original', true, true),
90-
['Rename', true, true]
92+
['Renamed', true, true],
93+
false,
9194
],
9295
];
9396
}
9497

9598
/**
9699
* @dataProvider tagNodeProvider
97100
*/
98-
public function testUpdateTag($isAdmin, ISystemTag $originalTag, $changedArgs): void {
99-
$this->tagManager->expects($this->once())
100-
->method('canUserSeeTag')
101+
public function testUpdateTag($isAdmin, ISystemTag $originalTag, $changedArgs, $allowed): void {
102+
$this->tagManager->method('canUserSeeTag')
101103
->with($originalTag)
102104
->willReturn($originalTag->isUserVisible() || $isAdmin);
103-
$this->tagManager->expects($this->once())
104-
->method('canUserAssignTag')
105+
$this->tagManager->method('canUserAssignTag')
105106
->with($originalTag)
106107
->willReturn($originalTag->isUserAssignable() || $isAdmin);
107-
$this->tagManager->expects($this->once())
108-
->method('updateTag')
109-
->with(1, $changedArgs[0], $changedArgs[1], $changedArgs[2]);
108+
if ($allowed) {
109+
$this->tagManager->expects($this->once())
110+
->method('updateTag')
111+
->with(1, $changedArgs[0], $changedArgs[1], $changedArgs[2]);
112+
} else {
113+
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
114+
$this->tagManager->expects($this->never())
115+
->method('updateTag');
116+
}
110117
$this->getTagNode($isAdmin, $originalTag)
111118
->update($changedArgs[0], $changedArgs[1], $changedArgs[2]);
112119
}
@@ -196,7 +203,7 @@ public function testUpdateTagAlreadyExists(): void {
196203
->method('updateTag')
197204
->with(1, 'Renamed', true, true)
198205
->will($this->throwException(new TagAlreadyExistsException()));
199-
$this->getTagNode(false, $tag)->update('Renamed', true, true);
206+
$this->getTagNode(true, $tag)->update('Renamed', true, true);
200207
}
201208

202209

@@ -216,7 +223,7 @@ public function testUpdateTagNotFound(): void {
216223
->method('updateTag')
217224
->with(1, 'Renamed', true, true)
218225
->will($this->throwException(new TagNotFoundException()));
219-
$this->getTagNode(false, $tag)->update('Renamed', true, true);
226+
$this->getTagNode(true, $tag)->update('Renamed', true, true);
220227
}
221228

222229
/**

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)