Merge #20047 - Fix case where user preferences are not removed

Pull-request: #20047
Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
William Desportes 2026-01-25 21:09:39 +01:00
commit b1cec4e48f
No known key found for this signature in database
GPG Key ID: 70684F4717D49A31
4 changed files with 19 additions and 32 deletions

View File

@ -131,7 +131,7 @@ class UserPreferences
$existingPrefs = $this->load();
if (isset($existingPrefs['config_data']['2fa'])) {
// This is likely a partial save from page settings - merge to preserve 2fa
$config_array = array_merge($existingPrefs['config_data'], $config_array);
$config_array['2fa'] = $existingPrefs['config_data']['2fa'];
}
}

View File

@ -48750,16 +48750,6 @@ parameters:
count: 1
path: test/classes/UserPreferencesTest.php
-
message: "#^Cannot access offset '2fa' on mixed\\.$#"
count: 1
path: test/classes/UserPreferencesTest.php
-
message: "#^Cannot access offset 'Console/Mode' on mixed\\.$#"
count: 1
path: test/classes/UserPreferencesTest.php
-
message: "#^Cannot access offset 'DisableIS' on mixed\\.$#"
count: 1
@ -48790,21 +48780,11 @@ parameters:
count: 3
path: test/classes/UserPreferencesTest.php
-
message: "#^Cannot access offset 'secret' on mixed\\.$#"
count: 1
path: test/classes/UserPreferencesTest.php
-
message: "#^Cannot access offset 'server_2' on mixed\\.$#"
count: 1
path: test/classes/UserPreferencesTest.php
-
message: "#^Cannot access offset 'settings' on mixed\\.$#"
count: 1
path: test/classes/UserPreferencesTest.php
-
message: "#^Cannot access offset 'ts' on mixed\\.$#"
count: 1

View File

@ -14186,9 +14186,10 @@
<code>$allowList[$path]</code>
<code>$excludeList[$path]</code>
</MixedArrayTypeCoercion>
<MixedAssignment occurrences="5">
<MixedAssignment occurrences="6">
<code>$configData</code>
<code>$configData</code>
<code>$config_array['2fa']</code>
<code>$prefs['config_data'][$path]</code>
<code>$timestamp</code>
<code>$value</code>
@ -16451,17 +16452,12 @@
</MixedMethodCall>
</file>
<file src="test/classes/UserPreferencesTest.php">
<InvalidArrayOffset occurrences="2">
<code>$resultConfig['2fa']</code>
<code>$resultConfig['Console/Mode']</code>
</InvalidArrayOffset>
<MixedArgument occurrences="1">
<code>$_SESSION['userconfig']</code>
</MixedArgument>
<MixedArrayAccess occurrences="3">
<MixedArrayAccess occurrences="2">
<code>$_SESSION['userconfig']['db']</code>
<code>$_SESSION['userconfig']['ts']</code>
<code>$resultConfig['2fa']['settings']</code>
</MixedArrayAccess>
<TypeDoesNotContainType occurrences="1">
<code>assertTrue</code>

View File

@ -233,19 +233,30 @@ class UserPreferencesTest extends AbstractNetworkTestCase
// Initial save with 2fa
$initialConfig = [
'CharEditing' => 'textarea',
'2fa' => ['backend' => 'application', 'settings' => ['secret' => 'thisisasecret']],
'theme' => 'dark',
'RowActionLinks' => 'both',
'TableNavigationLinksMode' => 'both',
];
$this->userPreferences->save($initialConfig);
// Partial save without 2fa
$partialConfig = ['Console/Mode' => 'collapse'];
$partialConfig = [
'CharEditing' => 'textarea',
'TableNavigationLinksMode' => 'text',
'Console/Mode' => 'collapse',
];
$this->userPreferences->save($partialConfig);
// Check that 2fa is still present
$resultConfig = $_SESSION['userconfig']['db'];
self::assertSame('thisisasecret', $resultConfig['2fa']['settings']['secret']);
self::assertSame('collapse', $resultConfig['Console/Mode']);
$expected = [
'CharEditing' => 'textarea',
'TableNavigationLinksMode' => 'text',
'Console/Mode' => 'collapse',
'2fa' => ['backend' => 'application', 'settings' => ['secret' => 'thisisasecret']],
];
self::assertSame($expected, $resultConfig);
}
/**