mirror of
https://github.com/nextcloud/server.git
synced 2026-02-20 00:12:30 -05:00
fix populating account array with missing default values
- both $userData and $defaultUserData have numeric indices - each element contains at least the name and other fields - appending the missing data array is sufficient Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
6b099ecfe5
commit
e26d6f080b
2 changed files with 14 additions and 15 deletions
|
|
@ -473,15 +473,16 @@ class AccountManager implements IAccountManager {
|
|||
* Make sure that all expected data are set
|
||||
*/
|
||||
protected function addMissingDefaultValues(array $userData, array $defaultUserData): array {
|
||||
foreach ($defaultUserData as $i => $value) {
|
||||
// If property doesn't exists, initialize it
|
||||
if (!array_key_exists($i, $userData)) {
|
||||
$userData[$i] = [];
|
||||
foreach ($defaultUserData as $defaultDataItem) {
|
||||
// If property does not exist, initialize it
|
||||
$userDataIndex = array_search($defaultDataItem['name'], array_column($userData, 'name'));
|
||||
if ($userDataIndex === false) {
|
||||
$userData[] = $defaultDataItem;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Merge and extend default missing values
|
||||
$defaultValueIndex = array_search($value['name'], array_column($defaultUserData, 'name'));
|
||||
$userData[$i] = array_merge($defaultUserData[$defaultValueIndex], $userData[$i]);
|
||||
$userData[$userDataIndex] = array_merge($defaultDataItem, $userData[$userDataIndex]);
|
||||
}
|
||||
|
||||
return $userData;
|
||||
|
|
|
|||
|
|
@ -516,8 +516,6 @@ class AccountManagerTest extends TestCase {
|
|||
'value' => 'bob',
|
||||
'verified' => IAccountManager::NOT_VERIFIED,
|
||||
],
|
||||
[],
|
||||
[],
|
||||
[
|
||||
'name' => IAccountManager::PROPERTY_EMAIL,
|
||||
'value' => 'bob@bob.bob',
|
||||
|
|
@ -532,6 +530,13 @@ class AccountManagerTest extends TestCase {
|
|||
'verified' => IAccountManager::NOT_VERIFIED,
|
||||
],
|
||||
|
||||
[
|
||||
'name' => IAccountManager::PROPERTY_EMAIL,
|
||||
'value' => 'bob@bob.bob',
|
||||
'scope' => IAccountManager::SCOPE_FEDERATED,
|
||||
'verified' => IAccountManager::NOT_VERIFIED,
|
||||
],
|
||||
|
||||
[
|
||||
'name' => IAccountManager::PROPERTY_ADDRESS,
|
||||
'value' => '',
|
||||
|
|
@ -546,13 +551,6 @@ class AccountManagerTest extends TestCase {
|
|||
'verified' => IAccountManager::NOT_VERIFIED,
|
||||
],
|
||||
|
||||
[
|
||||
'name' => IAccountManager::PROPERTY_EMAIL,
|
||||
'value' => 'bob@bob.bob',
|
||||
'scope' => IAccountManager::SCOPE_FEDERATED,
|
||||
'verified' => IAccountManager::NOT_VERIFIED,
|
||||
],
|
||||
|
||||
[
|
||||
'name' => IAccountManager::PROPERTY_AVATAR,
|
||||
'scope' => IAccountManager::SCOPE_FEDERATED
|
||||
|
|
|
|||
Loading…
Reference in a new issue