Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Provide initial state
Signed-off-by: Christopher Ng <[email protected]>
(cherry picked from commit 94e469f)
  • Loading branch information
Pytal committed Jul 16, 2021
commit a130d113c833f012f5ebf96025f9b73ce87f0103
50 changes: 49 additions & 1 deletion apps/settings/lib/Settings/Personal/PersonalInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*
* @author Arthur Schiwon <[email protected]>
* @author Christoph Wurst <[email protected]>
* @author Christopher Ng <[email protected]>
* @author Georg Ehrke <[email protected]>
* @author Joas Schilling <[email protected]>
* @author John Molakvoæ <[email protected]>
Expand Down Expand Up @@ -48,6 +49,8 @@
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Settings\ISettings;
use OCP\Accounts\IAccountProperty;
use OCP\AppFramework\Services\IInitialState;

class PersonalInfo implements ISettings {

Expand All @@ -65,6 +68,8 @@ class PersonalInfo implements ISettings {
private $l10nFactory;
/** @var IL10N */
private $l;
/** @var IInitialState */
private $initialStateService;

public function __construct(
IConfig $config,
Expand All @@ -73,7 +78,8 @@ public function __construct(
IAccountManager $accountManager,
IAppManager $appManager,
IFactory $l10nFactory,
IL10N $l
IL10N $l,
IInitialState $initialStateService
) {
$this->config = $config;
$this->userManager = $userManager;
Expand All @@ -82,6 +88,7 @@ public function __construct(
$this->appManager = $appManager;
$this->l10nFactory = $l10nFactory;
$this->l = $l;
$this->initialStateService = $initialStateService;
}

public function getForm(): TemplateResponse {
Expand Down Expand Up @@ -138,6 +145,14 @@ public function getForm(): TemplateResponse {
'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, '');
}
Expand Down Expand Up @@ -180,6 +195,39 @@ static function (IGroup $group) {
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
Expand Down