Skip to content

Commit 39d2dc2

Browse files
Merge pull request #61845 from nextcloud/fix/declarative-settings-delegation
fix(DeclarativeManager): Fix admin delegation
2 parents 2eaad34 + 6d2a98a commit 39d2dc2

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

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)