Skip to content

Commit

Permalink
Consolidate account property getters
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <chrng8@gmail.com>
  • Loading branch information
Pytal committed Jul 21, 2022
1 parent ea73f66 commit 3430808
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 122 deletions.
102 changes: 12 additions & 90 deletions apps/settings/lib/Settings/Personal/PersonalInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ public function getForm(): TemplateResponse {

$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 = [
Expand Down Expand Up @@ -208,75 +208,17 @@ private function isFairUseOfFreePushService(): bool {
}

/**
* 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;
}

/**
Expand Down Expand Up @@ -314,26 +256,6 @@ static function (IGroup $group) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
<section>
<HeaderBar :account-property="accountProperty"
label-for="biography"
:scope.sync="primaryBiography.scope" />
:scope.sync="biography.scope" />

<Biography :biography.sync="primaryBiography.value"
:scope.sync="primaryBiography.scope" />
<Biography :biography.sync="biography.value"
:scope.sync="biography.scope" />
</section>
</template>

Expand All @@ -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',
Expand All @@ -52,7 +52,7 @@ export default {
data() {
return {
accountProperty: ACCOUNT_PROPERTY_READABLE_ENUM.BIOGRAPHY,
primaryBiography,
biography,
}
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
label-for="displayname"
:is-editable="displayNameChangeSupported"
:is-valid-section="isValidSection"
:scope.sync="primaryDisplayName.scope" />
:scope.sync="displayName.scope" />

<template v-if="displayNameChangeSupported">
<DisplayName :display-name.sync="primaryDisplayName.value"
:scope.sync="primaryDisplayName.scope" />
<DisplayName :display-name.sync="displayName.value"
:scope.sync="displayName.scope" />
</template>

<span v-else>
{{ primaryDisplayName.value || t('settings', 'No full name set') }}
{{ displayName.value || t('settings', 'No full name set') }}
</span>
</section>
</template>
Expand All @@ -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 {
Expand All @@ -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)
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
<section>
<HeaderBar :account-property="accountProperty"
label-for="headline"
:scope.sync="primaryHeadline.scope" />
:scope.sync="headline.scope" />

<Headline :headline.sync="primaryHeadline.value"
:scope.sync="primaryHeadline.scope" />
<Headline :headline.sync="headline.value"
:scope.sync="headline.scope" />
</section>
</template>

Expand All @@ -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',
Expand All @@ -52,7 +52,7 @@ export default {
data() {
return {
accountProperty: ACCOUNT_PROPERTY_READABLE_ENUM.HEADLINE,
primaryHeadline,
headline,
}
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
<section>
<HeaderBar :account-property="accountProperty"
label-for="organisation"
:scope.sync="primaryOrganisation.scope" />
:scope.sync="organisation.scope" />

<Organisation :organisation.sync="primaryOrganisation.value"
:scope.sync="primaryOrganisation.scope" />
<Organisation :organisation.sync="organisation.value"
:scope.sync="organisation.scope" />
</section>
</template>

Expand All @@ -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',
Expand All @@ -52,7 +52,7 @@ export default {
data() {
return {
accountProperty: ACCOUNT_PROPERTY_READABLE_ENUM.ORGANISATION,
primaryOrganisation,
organisation,
}
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
<section>
<HeaderBar :account-property="accountProperty"
label-for="role"
:scope.sync="primaryRole.scope" />
:scope.sync="role.scope" />

<Role :role.sync="primaryRole.value"
:scope.sync="primaryRole.scope" />
<Role :role.sync="role.value"
:scope.sync="role.scope" />
</section>
</template>

Expand All @@ -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',
Expand All @@ -52,7 +52,7 @@ export default {
data() {
return {
accountProperty: ACCOUNT_PROPERTY_READABLE_ENUM.ROLE,
primaryRole,
role,
}
},
}
Expand Down
4 changes: 2 additions & 2 deletions dist/settings-vue-settings-personal-info.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/settings-vue-settings-personal-info.js.map

Large diffs are not rendered by default.

0 comments on commit 3430808

Please sign in to comment.