prov api reports additional emails on getUser

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2021-06-11 13:34:53 +02:00 committed by backportbot[bot]
parent e74f5aeec2
commit 4398cf85c1
4 changed files with 47 additions and 5 deletions

View file

@ -150,6 +150,20 @@ abstract class AUserData extends OCSController {
if ($includeScopes) {
$data[IAccountManager::PROPERTY_EMAIL . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_EMAIL)->getScope();
}
$additionalEmails = $additionalEmailScopes = [];
$emailCollection = $userAccount->getPropertyCollection(IAccountManager::COLLECTION_EMAIL);
foreach ($emailCollection->getProperties() as $property) {
$additionalEmails[] = $property->getValue();
if ($includeScopes) {
$additionalEmailScopes = $property->getScope();
}
}
$data[IAccountManager::COLLECTION_EMAIL] = $additionalEmails;
if ($includeScopes) {
$data[IAccountManager::COLLECTION_EMAIL . self::SCOPE_SUFFIX] = $additionalEmailScopes;
}
$data[IAccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName();
if ($includeScopes) {
$data[IAccountManager::PROPERTY_DISPLAYNAME . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_DISPLAYNAME)->getScope();

View file

@ -1071,7 +1071,8 @@ class UsersControllerTest extends TestCase {
'backendCapabilities' => [
'setDisplayName' => true,
'setPassword' => true,
]
],
'additional_mail' => [],
];
$this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID']));
}
@ -1198,7 +1199,8 @@ class UsersControllerTest extends TestCase {
'backendCapabilities' => [
'setDisplayName' => true,
'setPassword' => true,
]
],
'additional_mail' => [],
];
$this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID']));
}
@ -1363,7 +1365,8 @@ class UsersControllerTest extends TestCase {
'backendCapabilities' => [
'setDisplayName' => false,
'setPassword' => false,
]
],
'additional_mail' => [],
];
$this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID']));
}

View file

@ -39,6 +39,7 @@ use libphonenumber\PhoneNumberUtil;
use OCA\Settings\BackgroundJobs\VerifyUserData;
use OCP\Accounts\IAccount;
use OCP\Accounts\IAccountManager;
use OCP\Accounts\IAccountPropertyCollection;
use OCP\BackgroundJob\IJobList;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IConfig;
@ -400,10 +401,13 @@ class AccountManager implements IAccountManager {
*/
protected function addMissingDefaultValues(array $userData) {
foreach ($userData as $key => $value) {
if (!isset($userData[$key]['verified'])) {
if (!isset($userData[$key]['verified']) && !$this->isCollection($key)) {
$userData[$key]['verified'] = self::NOT_VERIFIED;
}
}
if (!isset($userData[IAccountManager::COLLECTION_EMAIL])) {
$userData[IAccountManager::COLLECTION_EMAIL] = [];
}
return $userData;
}
@ -582,13 +586,33 @@ class AccountManager implements IAccountManager {
'scope' => self::SCOPE_LOCAL,
'verified' => self::NOT_VERIFIED,
],
self::COLLECTION_EMAIL => [],
];
}
private function arrayDataToCollection(string $collectionName, array $data): IAccountPropertyCollection {
$collection = new AccountPropertyCollection($collectionName);
foreach ($data as $propertyData) {
$p = new AccountProperty(
$collectionName,
$propertyData['value'] ?? '',
$propertyData['scope'] ?? self::SCOPE_LOCAL,
$propertyData['verified'] ?? self::NOT_VERIFIED,
''
);
$collection->addProperty($p);
}
return $collection;
}
private function parseAccountData(IUser $user, $data): Account {
$account = new Account($user);
foreach ($data as $property => $accountData) {
$account->setProperty($property, $accountData['value'] ?? '', $accountData['scope'] ?? self::SCOPE_LOCAL, $accountData['verified'] ?? self::NOT_VERIFIED);
if ($this->isCollection($property)) {
$account->setPropertyCollection($this->arrayDataToCollection($property, $accountData));
} else {
$account->setProperty($property, $accountData['value'] ?? '', $accountData['scope'] ?? self::SCOPE_LOCAL, $accountData['verified'] ?? self::NOT_VERIFIED);
}
}
return $account;
}

View file

@ -464,6 +464,7 @@ class AccountManagerTest extends TestCase {
$expected = [
'key1' => ['value' => 'value1', 'verified' => '0'],
'key2' => ['value' => 'value1', 'verified' => '0'],
'additional_mail' => []
];
$result = $this->invokePrivate($this->accountManager, 'addMissingDefaultValues', [$input]);