From 34308087d61b894d08b51d96b63809cc8902e7a0 Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Mon, 11 Jul 2022 23:58:32 +0000 Subject: Consolidate account property getters Signed-off-by: Christopher Ng --- .../lib/Settings/Personal/PersonalInfo.php | 102 +++------------------ .../BiographySection/BiographySection.vue | 10 +- .../DisplayNameSection/DisplayNameSection.vue | 14 +-- .../HeadlineSection/HeadlineSection.vue | 10 +- .../OrganisationSection/OrganisationSection.vue | 10 +- .../PersonalInfo/ProfileSection/ProfileSection.vue | 4 +- .../PersonalInfo/RoleSection/RoleSection.vue | 10 +- 7 files changed, 41 insertions(+), 119 deletions(-) (limited to 'apps') diff --git a/apps/settings/lib/Settings/Personal/PersonalInfo.php b/apps/settings/lib/Settings/Personal/PersonalInfo.php index 4bac8e67fb7..fbbee7b81bb 100644 --- a/apps/settings/lib/Settings/Personal/PersonalInfo.php +++ b/apps/settings/lib/Settings/Personal/PersonalInfo.php @@ -171,15 +171,15 @@ class PersonalInfo implements ISettings { $personalInfoParameters = [ 'userId' => $uid, - 'displayNameMap' => $this->getDisplayNameMap($account), + 'displayName' => $this->getProperty($account, IAccountManager::PROPERTY_DISPLAYNAME), 'emailMap' => $this->getEmailMap($account), 'languageMap' => $this->getLanguageMap($user), 'profileEnabledGlobally' => $this->profileManager->isProfileEnabled(), 'profileEnabled' => $this->profileManager->isProfileEnabled($user), - 'organisationMap' => $this->getOrganisationMap($account), - 'roleMap' => $this->getRoleMap($account), - 'headlineMap' => $this->getHeadlineMap($account), - 'biographyMap' => $this->getBiographyMap($account), + 'organisation' => $this->getProperty($account, IAccountManager::PROPERTY_ORGANISATION), + 'role' => $this->getProperty($account, IAccountManager::PROPERTY_ROLE), + 'headline' => $this->getProperty($account, IAccountManager::PROPERTY_HEADLINE), + 'biography' => $this->getProperty($account, IAccountManager::PROPERTY_BIOGRAPHY), ]; $accountParameters = [ @@ -208,75 +208,17 @@ class PersonalInfo implements ISettings { } /** - * returns the primary biography in an + * returns the property data in an * associative array */ - private function getBiographyMap(IAccount $account): array { - $primaryBiography = [ - 'value' => $account->getProperty(IAccountManager::PROPERTY_BIOGRAPHY)->getValue(), - 'scope' => $account->getProperty(IAccountManager::PROPERTY_BIOGRAPHY)->getScope(), - 'verified' => $account->getProperty(IAccountManager::PROPERTY_BIOGRAPHY)->getVerified(), + private function getProperty(IAccount $account, string $property): array { + $property = [ + 'value' => $account->getProperty($property)->getValue(), + 'scope' => $account->getProperty($property)->getScope(), + 'verified' => $account->getProperty($property)->getVerified(), ]; - $biographyMap = [ - 'primaryBiography' => $primaryBiography, - ]; - - return $biographyMap; - } - - /** - * returns the primary organisation in an - * associative array - */ - private function getOrganisationMap(IAccount $account): array { - $primaryOrganisation = [ - 'value' => $account->getProperty(IAccountManager::PROPERTY_ORGANISATION)->getValue(), - 'scope' => $account->getProperty(IAccountManager::PROPERTY_ORGANISATION)->getScope(), - 'verified' => $account->getProperty(IAccountManager::PROPERTY_ORGANISATION)->getVerified(), - ]; - - $organisationMap = [ - 'primaryOrganisation' => $primaryOrganisation, - ]; - - return $organisationMap; - } - - /** - * returns the primary headline in an - * associative array - */ - private function getHeadlineMap(IAccount $account): array { - $primaryHeadline = [ - 'value' => $account->getProperty(IAccountManager::PROPERTY_HEADLINE)->getValue(), - 'scope' => $account->getProperty(IAccountManager::PROPERTY_HEADLINE)->getScope(), - 'verified' => $account->getProperty(IAccountManager::PROPERTY_HEADLINE)->getVerified(), - ]; - - $headlineMap = [ - 'primaryHeadline' => $primaryHeadline, - ]; - - return $headlineMap; - } - - /** - * returns the primary role in an - * associative array - */ - private function getRoleMap(IAccount $account): array { - $primaryRole = [ - 'value' => $account->getProperty(IAccountManager::PROPERTY_ROLE)->getValue(), - 'scope' => $account->getProperty(IAccountManager::PROPERTY_ROLE)->getScope(), - 'verified' => $account->getProperty(IAccountManager::PROPERTY_ROLE)->getVerified(), - ]; - - $roleMap = [ - 'primaryRole' => $primaryRole, - ]; - - return $roleMap; + return $property; } /** @@ -314,26 +256,6 @@ class PersonalInfo implements ISettings { return $groups; } - /** - * returns the primary display name in an - * associative array - * - * NOTE may be extended to provide additional display names (i.e. aliases) in the future - */ - private function getDisplayNameMap(IAccount $account): array { - $primaryDisplayName = [ - 'value' => $account->getProperty(IAccountManager::PROPERTY_DISPLAYNAME)->getValue(), - 'scope' => $account->getProperty(IAccountManager::PROPERTY_DISPLAYNAME)->getScope(), - 'verified' => $account->getProperty(IAccountManager::PROPERTY_DISPLAYNAME)->getVerified(), - ]; - - $displayNameMap = [ - 'primaryDisplayName' => $primaryDisplayName, - ]; - - return $displayNameMap; - } - /** * returns the primary email and additional emails in an * associative array diff --git a/apps/settings/src/components/PersonalInfo/BiographySection/BiographySection.vue b/apps/settings/src/components/PersonalInfo/BiographySection/BiographySection.vue index c8aacb03e9c..c8464f7b243 100644 --- a/apps/settings/src/components/PersonalInfo/BiographySection/BiographySection.vue +++ b/apps/settings/src/components/PersonalInfo/BiographySection/BiographySection.vue @@ -24,10 +24,10 @@
+ :scope.sync="biography.scope" /> - +
@@ -39,7 +39,7 @@ import HeaderBar from '../shared/HeaderBar' import { ACCOUNT_PROPERTY_READABLE_ENUM } from '../../../constants/AccountPropertyConstants' -const { biographyMap: { primaryBiography } } = loadState('settings', 'personalInfoParameters', {}) +const { biography } = loadState('settings', 'personalInfoParameters', {}) export default { name: 'BiographySection', @@ -52,7 +52,7 @@ export default { data() { return { accountProperty: ACCOUNT_PROPERTY_READABLE_ENUM.BIOGRAPHY, - primaryBiography, + biography, } }, } diff --git a/apps/settings/src/components/PersonalInfo/DisplayNameSection/DisplayNameSection.vue b/apps/settings/src/components/PersonalInfo/DisplayNameSection/DisplayNameSection.vue index caee7e7c68e..d808369e9fb 100644 --- a/apps/settings/src/components/PersonalInfo/DisplayNameSection/DisplayNameSection.vue +++ b/apps/settings/src/components/PersonalInfo/DisplayNameSection/DisplayNameSection.vue @@ -26,15 +26,15 @@ label-for="displayname" :is-editable="displayNameChangeSupported" :is-valid-section="isValidSection" - :scope.sync="primaryDisplayName.scope" /> + :scope.sync="displayName.scope" /> - {{ primaryDisplayName.value || t('settings', 'No full name set') }} + {{ displayName.value || t('settings', 'No full name set') }} @@ -48,7 +48,7 @@ import HeaderBar from '../shared/HeaderBar' import { ACCOUNT_PROPERTY_READABLE_ENUM } from '../../../constants/AccountPropertyConstants' import { validateStringInput } from '../../../utils/validate' -const { displayNameMap: { primaryDisplayName } } = loadState('settings', 'personalInfoParameters', {}) +const { displayName } = loadState('settings', 'personalInfoParameters', {}) const { displayNameChangeSupported } = loadState('settings', 'accountParameters', {}) export default { @@ -63,13 +63,13 @@ export default { return { accountProperty: ACCOUNT_PROPERTY_READABLE_ENUM.DISPLAYNAME, displayNameChangeSupported, - primaryDisplayName, + displayName, } }, computed: { isValidSection() { - return validateStringInput(this.primaryDisplayName.value) + return validateStringInput(this.displayName.value) }, }, } diff --git a/apps/settings/src/components/PersonalInfo/HeadlineSection/HeadlineSection.vue b/apps/settings/src/components/PersonalInfo/HeadlineSection/HeadlineSection.vue index 4f3714aa0ee..1a608d2fc02 100644 --- a/apps/settings/src/components/PersonalInfo/HeadlineSection/HeadlineSection.vue +++ b/apps/settings/src/components/PersonalInfo/HeadlineSection/HeadlineSection.vue @@ -24,10 +24,10 @@
+ :scope.sync="headline.scope" /> - +
@@ -39,7 +39,7 @@ import HeaderBar from '../shared/HeaderBar' import { ACCOUNT_PROPERTY_READABLE_ENUM } from '../../../constants/AccountPropertyConstants' -const { headlineMap: { primaryHeadline } } = loadState('settings', 'personalInfoParameters', {}) +const { headline } = loadState('settings', 'personalInfoParameters', {}) export default { name: 'HeadlineSection', @@ -52,7 +52,7 @@ export default { data() { return { accountProperty: ACCOUNT_PROPERTY_READABLE_ENUM.HEADLINE, - primaryHeadline, + headline, } }, } diff --git a/apps/settings/src/components/PersonalInfo/OrganisationSection/OrganisationSection.vue b/apps/settings/src/components/PersonalInfo/OrganisationSection/OrganisationSection.vue index 2a0b93d552f..b436b2edd0b 100644 --- a/apps/settings/src/components/PersonalInfo/OrganisationSection/OrganisationSection.vue +++ b/apps/settings/src/components/PersonalInfo/OrganisationSection/OrganisationSection.vue @@ -24,10 +24,10 @@
+ :scope.sync="organisation.scope" /> - +
@@ -39,7 +39,7 @@ import HeaderBar from '../shared/HeaderBar' import { ACCOUNT_PROPERTY_READABLE_ENUM } from '../../../constants/AccountPropertyConstants' -const { organisationMap: { primaryOrganisation } } = loadState('settings', 'personalInfoParameters', {}) +const { organisation } = loadState('settings', 'personalInfoParameters', {}) export default { name: 'OrganisationSection', @@ -52,7 +52,7 @@ export default { data() { return { accountProperty: ACCOUNT_PROPERTY_READABLE_ENUM.ORGANISATION, - primaryOrganisation, + organisation, } }, } diff --git a/apps/settings/src/components/PersonalInfo/ProfileSection/ProfileSection.vue b/apps/settings/src/components/PersonalInfo/ProfileSection/ProfileSection.vue index 46048e96c0e..0196b3161a7 100644 --- a/apps/settings/src/components/PersonalInfo/ProfileSection/ProfileSection.vue +++ b/apps/settings/src/components/PersonalInfo/ProfileSection/ProfileSection.vue @@ -47,8 +47,8 @@ import ProfilePreviewCard from './ProfilePreviewCard' import { ACCOUNT_PROPERTY_READABLE_ENUM } from '../../../constants/AccountPropertyConstants' const { - organisationMap: { primaryOrganisation: { value: organisation } }, - displayNameMap: { primaryDisplayName: { value: displayName } }, + organisation: { value: organisation }, + displayName: { value: displayName }, profileEnabled, userId, } = loadState('settings', 'personalInfoParameters', {}) diff --git a/apps/settings/src/components/PersonalInfo/RoleSection/RoleSection.vue b/apps/settings/src/components/PersonalInfo/RoleSection/RoleSection.vue index 51026f4860c..b3e95bc8153 100644 --- a/apps/settings/src/components/PersonalInfo/RoleSection/RoleSection.vue +++ b/apps/settings/src/components/PersonalInfo/RoleSection/RoleSection.vue @@ -24,10 +24,10 @@
+ :scope.sync="role.scope" /> - +
@@ -39,7 +39,7 @@ import HeaderBar from '../shared/HeaderBar' import { ACCOUNT_PROPERTY_READABLE_ENUM } from '../../../constants/AccountPropertyConstants' -const { roleMap: { primaryRole } } = loadState('settings', 'personalInfoParameters', {}) +const { role } = loadState('settings', 'personalInfoParameters', {}) export default { name: 'RoleSection', @@ -52,7 +52,7 @@ export default { data() { return { accountProperty: ACCOUNT_PROPERTY_READABLE_ENUM.ROLE, - primaryRole, + role, } }, } -- cgit v1.2.3