Skip to content

Commit b1cec4e

Browse files
committed
Merge #20047 - Fix case where user preferences are not removed
Pull-request: #20047 Signed-off-by: William Desportes <williamdes@wdes.fr>
2 parents 8851a3a + daa9d1e commit b1cec4e

4 files changed

Lines changed: 19 additions & 32 deletions

File tree

libraries/classes/UserPreferences.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function save(array $config_array)
131131
$existingPrefs = $this->load();
132132
if (isset($existingPrefs['config_data']['2fa'])) {
133133
// This is likely a partial save from page settings - merge to preserve 2fa
134-
$config_array = array_merge($existingPrefs['config_data'], $config_array);
134+
$config_array['2fa'] = $existingPrefs['config_data']['2fa'];
135135
}
136136
}
137137

phpstan-baseline.neon

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48750,16 +48750,6 @@ parameters:
4875048750
count: 1
4875148751
path: test/classes/UserPreferencesTest.php
4875248752

48753-
-
48754-
message: "#^Cannot access offset '2fa' on mixed\\.$#"
48755-
count: 1
48756-
path: test/classes/UserPreferencesTest.php
48757-
48758-
-
48759-
message: "#^Cannot access offset 'Console/Mode' on mixed\\.$#"
48760-
count: 1
48761-
path: test/classes/UserPreferencesTest.php
48762-
4876348753
-
4876448754
message: "#^Cannot access offset 'DisableIS' on mixed\\.$#"
4876548755
count: 1
@@ -48790,21 +48780,11 @@ parameters:
4879048780
count: 3
4879148781
path: test/classes/UserPreferencesTest.php
4879248782

48793-
-
48794-
message: "#^Cannot access offset 'secret' on mixed\\.$#"
48795-
count: 1
48796-
path: test/classes/UserPreferencesTest.php
48797-
4879848783
-
4879948784
message: "#^Cannot access offset 'server_2' on mixed\\.$#"
4880048785
count: 1
4880148786
path: test/classes/UserPreferencesTest.php
4880248787

48803-
-
48804-
message: "#^Cannot access offset 'settings' on mixed\\.$#"
48805-
count: 1
48806-
path: test/classes/UserPreferencesTest.php
48807-
4880848788
-
4880948789
message: "#^Cannot access offset 'ts' on mixed\\.$#"
4881048790
count: 1

psalm-baseline.xml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14186,9 +14186,10 @@
1418614186
<code>$allowList[$path]</code>
1418714187
<code>$excludeList[$path]</code>
1418814188
</MixedArrayTypeCoercion>
14189-
<MixedAssignment occurrences="5">
14189+
<MixedAssignment occurrences="6">
1419014190
<code>$configData</code>
1419114191
<code>$configData</code>
14192+
<code>$config_array['2fa']</code>
1419214193
<code>$prefs['config_data'][$path]</code>
1419314194
<code>$timestamp</code>
1419414195
<code>$value</code>
@@ -16451,17 +16452,12 @@
1645116452
</MixedMethodCall>
1645216453
</file>
1645316454
<file src="test/classes/UserPreferencesTest.php">
16454-
<InvalidArrayOffset occurrences="2">
16455-
<code>$resultConfig['2fa']</code>
16456-
<code>$resultConfig['Console/Mode']</code>
16457-
</InvalidArrayOffset>
1645816455
<MixedArgument occurrences="1">
1645916456
<code>$_SESSION['userconfig']</code>
1646016457
</MixedArgument>
16461-
<MixedArrayAccess occurrences="3">
16458+
<MixedArrayAccess occurrences="2">
1646216459
<code>$_SESSION['userconfig']['db']</code>
1646316460
<code>$_SESSION['userconfig']['ts']</code>
16464-
<code>$resultConfig['2fa']['settings']</code>
1646516461
</MixedArrayAccess>
1646616462
<TypeDoesNotContainType occurrences="1">
1646716463
<code>assertTrue</code>

test/classes/UserPreferencesTest.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,19 +233,30 @@ public function testSave(): void
233233

234234
// Initial save with 2fa
235235
$initialConfig = [
236+
'CharEditing' => 'textarea',
236237
'2fa' => ['backend' => 'application', 'settings' => ['secret' => 'thisisasecret']],
237-
'theme' => 'dark',
238+
'RowActionLinks' => 'both',
239+
'TableNavigationLinksMode' => 'both',
238240
];
239241
$this->userPreferences->save($initialConfig);
240242

241243
// Partial save without 2fa
242-
$partialConfig = ['Console/Mode' => 'collapse'];
244+
$partialConfig = [
245+
'CharEditing' => 'textarea',
246+
'TableNavigationLinksMode' => 'text',
247+
'Console/Mode' => 'collapse',
248+
];
243249
$this->userPreferences->save($partialConfig);
244250

245251
// Check that 2fa is still present
246252
$resultConfig = $_SESSION['userconfig']['db'];
247-
self::assertSame('thisisasecret', $resultConfig['2fa']['settings']['secret']);
248-
self::assertSame('collapse', $resultConfig['Console/Mode']);
253+
$expected = [
254+
'CharEditing' => 'textarea',
255+
'TableNavigationLinksMode' => 'text',
256+
'Console/Mode' => 'collapse',
257+
'2fa' => ['backend' => 'application', 'settings' => ['secret' => 'thisisasecret']],
258+
];
259+
self::assertSame($expected, $resultConfig);
249260
}
250261

251262
/**

0 commit comments

Comments
 (0)