Skip to content

Commit ed7b99d

Browse files
Merge pull request #61875 from nextcloud/backport/61845/stable33
[stable33] fix(DeclarativeManager): Fix admin delegation
2 parents c9ae941 + 432c541 commit ed7b99d

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

lib/private/Settings/DeclarativeManager.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@ public function getFormsWithValues(IUser $user, ?string $type, ?string $section)
142142
if ($section !== null && $schema['section_id'] !== $section) {
143143
continue;
144144
}
145-
// If listing all fields skip the admin fields which a non-admin user has no access to
146-
if ($type === null && $schema['section_type'] === 'admin' && !$isAdmin) {
145+
// Skip admin declarative forms for non-admin users. They have no access to
146+
// these fields even when they are allowed to view the section through admin
147+
// delegation, which only covers non-declarative settings.
148+
if ($schema['section_type'] === DeclarativeSettingsTypes::SECTION_TYPE_ADMIN && !$isAdmin) {
147149
continue;
148150
}
149151

tests/lib/Settings/DeclarativeManagerTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,15 @@ public function testAdminFormUserUnauthorized(): void {
555555
$schema = self::validSchemaAllFields;
556556
$this->declarativeManager->registerSchema($app, $schema);
557557

558+
// A non-admin user must not receive admin declarative forms, but this must not
559+
// throw: it would abort rendering of a section a user can legitimately access
560+
// through admin delegation (which only covers non-declarative settings).
561+
$forms = $this->declarativeManager->getFormsWithValues($this->user, $schema['section_type'], $schema['section_id']);
562+
$this->assertEmpty($forms);
563+
564+
// Writing to an admin declarative form is still forbidden for a non-admin user.
558565
$this->expectException(\Exception::class);
559-
$this->declarativeManager->getFormsWithValues($this->user, $schema['section_type'], $schema['section_id']);
566+
$this->declarativeManager->setValue($this->user, $app, $schema['id'], 'some_real_setting', '120m');
560567
}
561568

562569
/**

0 commit comments

Comments
 (0)