Skip to content

Commit 221c88f

Browse files
Merge pull request #61876 from nextcloud/backport/61845/stable34
[stable34] fix(DeclarativeManager): Fix admin delegation
2 parents a777c3f + 3c445d6 commit 221c88f

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
@@ -146,8 +146,10 @@ public function getFormsWithValues(IUser $user, ?string $type, ?string $section)
146146
if ($section !== null && $schema['section_id'] !== $section) {
147147
continue;
148148
}
149-
// If listing all fields skip the admin fields which a non-admin user has no access to
150-
if ($type === null && $schema['section_type'] === 'admin' && !$isAdmin) {
149+
// Skip admin declarative forms for non-admin users. They have no access to
150+
// these fields even when they are allowed to view the section through admin
151+
// delegation, which only covers non-declarative settings.
152+
if ($schema['section_type'] === DeclarativeSettingsTypes::SECTION_TYPE_ADMIN && !$isAdmin) {
151153
continue;
152154
}
153155

tests/lib/Settings/DeclarativeManagerTest.php

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

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

563570
/**

0 commit comments

Comments
 (0)