Provide initial state

Signed-off-by: Christopher Ng <chrng8@gmail.com>
pull/27379/head
Christopher Ng 2021-06-29 18:37:22 +07:00 committed by John Molakvoæ (skjnldsv)
parent 8cedf0de03
commit ef41d5977a
No known key found for this signature in database
GPG Key ID: 60C25B8C072916CF
1 changed files with 49 additions and 1 deletions

@ -7,6 +7,7 @@ declare(strict_types=1);
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Christopher Ng <chrng8@gmail.com>
* @author Georg Ehrke <oc.list@georgehrke.com>
* @author Joas Schilling <coding@schilljs.com>
* @author John Molakvoæ <skjnldsv@protonmail.com>
@ -48,6 +49,8 @@ use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Settings\ISettings;
use OCP\Accounts\IAccountProperty;
use OCP\AppFramework\Services\IInitialState;
class PersonalInfo implements ISettings {
@ -65,6 +68,8 @@ class PersonalInfo implements ISettings {
private $l10nFactory;
/** @var IL10N */
private $l;
/** @var IInitialState */
private $initialStateService;
public function __construct(
IConfig $config,
@ -73,7 +78,8 @@ class PersonalInfo implements ISettings {
IAccountManager $accountManager,
IAppManager $appManager,
IFactory $l10nFactory,
IL10N $l
IL10N $l,
IInitialState $initialStateService
) {
$this->config = $config;
$this->userManager = $userManager;
@ -82,6 +88,7 @@ class PersonalInfo implements ISettings {
$this->appManager = $appManager;
$this->l10nFactory = $l10nFactory;
$this->l = $l;
$this->initialStateService = $initialStateService;
}
public function getForm(): TemplateResponse {
@ -138,6 +145,14 @@ class PersonalInfo implements ISettings {
'groups' => $this->getGroups($user),
] + $messageParameters + $languageParameters + $localeParameters;
$emails = $this->getEmails($account);
$accountParameters = [
'displayNameChangeSupported' => $user->canChangeDisplayName(),
];
$this->initialStateService->provideInitialState('emails', $emails);
$this->initialStateService->provideInitialState('accountParameters', $accountParameters);
return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, '');
}
@ -180,6 +195,39 @@ class PersonalInfo implements ISettings {
return $groups;
}
/**
* returns the primary email and additional emails in an
* associative array
*
* @param IAccount $account
* @return array
*/
private function getEmails(IAccount $account): array {
$primaryEmail = [
'value' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getValue(),
'scope' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getScope(),
'verified' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getVerified(),
];
$additionalEmails = array_map(
function (IAccountProperty $property) {
return [
'value' => $property->getValue(),
'scope' => $property->getScope(),
'verified' => $property->getVerified(),
];
},
$account->getPropertyCollection(IAccountManager::COLLECTION_EMAIL)->getProperties()
);
$emails = [
'primaryEmail' => $primaryEmail,
'additionalEmails' => $additionalEmails,
];
return $emails;
}
/**
* returns the user language, common language and other languages in an
* associative array