Skip to content

Commit 3430808

Browse files
committed
Consolidate account property getters
Signed-off-by: Christopher Ng <chrng8@gmail.com>
1 parent ea73f66 commit 3430808

File tree

9 files changed

+44
-122
lines changed

9 files changed

+44
-122
lines changed

apps/settings/lib/Settings/Personal/PersonalInfo.php

Lines changed: 12 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@ public function getForm(): TemplateResponse {
171171

172172
$personalInfoParameters = [
173173
'userId' => $uid,
174-
'displayNameMap' => $this->getDisplayNameMap($account),
174+
'displayName' => $this->getProperty($account, IAccountManager::PROPERTY_DISPLAYNAME),
175175
'emailMap' => $this->getEmailMap($account),
176176
'languageMap' => $this->getLanguageMap($user),
177177
'profileEnabledGlobally' => $this->profileManager->isProfileEnabled(),
178178
'profileEnabled' => $this->profileManager->isProfileEnabled($user),
179-
'organisationMap' => $this->getOrganisationMap($account),
180-
'roleMap' => $this->getRoleMap($account),
181-
'headlineMap' => $this->getHeadlineMap($account),
182-
'biographyMap' => $this->getBiographyMap($account),
179+
'organisation' => $this->getProperty($account, IAccountManager::PROPERTY_ORGANISATION),
180+
'role' => $this->getProperty($account, IAccountManager::PROPERTY_ROLE),
181+
'headline' => $this->getProperty($account, IAccountManager::PROPERTY_HEADLINE),
182+
'biography' => $this->getProperty($account, IAccountManager::PROPERTY_BIOGRAPHY),
183183
];
184184

185185
$accountParameters = [
@@ -208,75 +208,17 @@ private function isFairUseOfFreePushService(): bool {
208208
}
209209

210210
/**
211-
* returns the primary biography in an
211+
* returns the property data in an
212212
* associative array
213213
*/
214-
private function getBiographyMap(IAccount $account): array {
215-
$primaryBiography = [
216-
'value' => $account->getProperty(IAccountManager::PROPERTY_BIOGRAPHY)->getValue(),
217-
'scope' => $account->getProperty(IAccountManager::PROPERTY_BIOGRAPHY)->getScope(),
218-
'verified' => $account->getProperty(IAccountManager::PROPERTY_BIOGRAPHY)->getVerified(),
214+
private function getProperty(IAccount $account, string $property): array {
215+
$property = [
216+
'value' => $account->getProperty($property)->getValue(),
217+
'scope' => $account->getProperty($property)->getScope(),
218+
'verified' => $account->getProperty($property)->getVerified(),
219219
];
220220

221-
$biographyMap = [
222-
'primaryBiography' => $primaryBiography,
223-
];
224-
225-
return $biographyMap;
226-
}
227-
228-
/**
229-
* returns the primary organisation in an
230-
* associative array
231-
*/
232-
private function getOrganisationMap(IAccount $account): array {
233-
$primaryOrganisation = [
234-
'value' => $account->getProperty(IAccountManager::PROPERTY_ORGANISATION)->getValue(),
235-
'scope' => $account->getProperty(IAccountManager::PROPERTY_ORGANISATION)->getScope(),
236-
'verified' => $account->getProperty(IAccountManager::PROPERTY_ORGANISATION)->getVerified(),
237-
];
238-
239-
$organisationMap = [
240-
'primaryOrganisation' => $primaryOrganisation,
241-
];
242-
243-
return $organisationMap;
244-
}
245-
246-
/**
247-
* returns the primary headline in an
248-
* associative array
249-
*/
250-
private function getHeadlineMap(IAccount $account): array {
251-
$primaryHeadline = [
252-
'value' => $account->getProperty(IAccountManager::PROPERTY_HEADLINE)->getValue(),
253-
'scope' => $account->getProperty(IAccountManager::PROPERTY_HEADLINE)->getScope(),
254-
'verified' => $account->getProperty(IAccountManager::PROPERTY_HEADLINE)->getVerified(),
255-
];
256-
257-
$headlineMap = [
258-
'primaryHeadline' => $primaryHeadline,
259-
];
260-
261-
return $headlineMap;
262-
}
263-
264-
/**
265-
* returns the primary role in an
266-
* associative array
267-
*/
268-
private function getRoleMap(IAccount $account): array {
269-
$primaryRole = [
270-
'value' => $account->getProperty(IAccountManager::PROPERTY_ROLE)->getValue(),
271-
'scope' => $account->getProperty(IAccountManager::PROPERTY_ROLE)->getScope(),
272-
'verified' => $account->getProperty(IAccountManager::PROPERTY_ROLE)->getVerified(),
273-
];
274-
275-
$roleMap = [
276-
'primaryRole' => $primaryRole,
277-
];
278-
279-
return $roleMap;
221+
return $property;
280222
}
281223

282224
/**
@@ -314,26 +256,6 @@ static function (IGroup $group) {
314256
return $groups;
315257
}
316258

317-
/**
318-
* returns the primary display name in an
319-
* associative array
320-
*
321-
* NOTE may be extended to provide additional display names (i.e. aliases) in the future
322-
*/
323-
private function getDisplayNameMap(IAccount $account): array {
324-
$primaryDisplayName = [
325-
'value' => $account->getProperty(IAccountManager::PROPERTY_DISPLAYNAME)->getValue(),
326-
'scope' => $account->getProperty(IAccountManager::PROPERTY_DISPLAYNAME)->getScope(),
327-
'verified' => $account->getProperty(IAccountManager::PROPERTY_DISPLAYNAME)->getVerified(),
328-
];
329-
330-
$displayNameMap = [
331-
'primaryDisplayName' => $primaryDisplayName,
332-
];
333-
334-
return $displayNameMap;
335-
}
336-
337259
/**
338260
* returns the primary email and additional emails in an
339261
* associative array

apps/settings/src/components/PersonalInfo/BiographySection/BiographySection.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
<section>
2525
<HeaderBar :account-property="accountProperty"
2626
label-for="biography"
27-
:scope.sync="primaryBiography.scope" />
27+
:scope.sync="biography.scope" />
2828

29-
<Biography :biography.sync="primaryBiography.value"
30-
:scope.sync="primaryBiography.scope" />
29+
<Biography :biography.sync="biography.value"
30+
:scope.sync="biography.scope" />
3131
</section>
3232
</template>
3333

@@ -39,7 +39,7 @@ import HeaderBar from '../shared/HeaderBar'
3939
4040
import { ACCOUNT_PROPERTY_READABLE_ENUM } from '../../../constants/AccountPropertyConstants'
4141
42-
const { biographyMap: { primaryBiography } } = loadState('settings', 'personalInfoParameters', {})
42+
const { biography } = loadState('settings', 'personalInfoParameters', {})
4343
4444
export default {
4545
name: 'BiographySection',
@@ -52,7 +52,7 @@ export default {
5252
data() {
5353
return {
5454
accountProperty: ACCOUNT_PROPERTY_READABLE_ENUM.BIOGRAPHY,
55-
primaryBiography,
55+
biography,
5656
}
5757
},
5858
}

apps/settings/src/components/PersonalInfo/DisplayNameSection/DisplayNameSection.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
label-for="displayname"
2727
:is-editable="displayNameChangeSupported"
2828
:is-valid-section="isValidSection"
29-
:scope.sync="primaryDisplayName.scope" />
29+
:scope.sync="displayName.scope" />
3030

3131
<template v-if="displayNameChangeSupported">
32-
<DisplayName :display-name.sync="primaryDisplayName.value"
33-
:scope.sync="primaryDisplayName.scope" />
32+
<DisplayName :display-name.sync="displayName.value"
33+
:scope.sync="displayName.scope" />
3434
</template>
3535

3636
<span v-else>
37-
{{ primaryDisplayName.value || t('settings', 'No full name set') }}
37+
{{ displayName.value || t('settings', 'No full name set') }}
3838
</span>
3939
</section>
4040
</template>
@@ -48,7 +48,7 @@ import HeaderBar from '../shared/HeaderBar'
4848
import { ACCOUNT_PROPERTY_READABLE_ENUM } from '../../../constants/AccountPropertyConstants'
4949
import { validateStringInput } from '../../../utils/validate'
5050
51-
const { displayNameMap: { primaryDisplayName } } = loadState('settings', 'personalInfoParameters', {})
51+
const { displayName } = loadState('settings', 'personalInfoParameters', {})
5252
const { displayNameChangeSupported } = loadState('settings', 'accountParameters', {})
5353
5454
export default {
@@ -63,13 +63,13 @@ export default {
6363
return {
6464
accountProperty: ACCOUNT_PROPERTY_READABLE_ENUM.DISPLAYNAME,
6565
displayNameChangeSupported,
66-
primaryDisplayName,
66+
displayName,
6767
}
6868
},
6969
7070
computed: {
7171
isValidSection() {
72-
return validateStringInput(this.primaryDisplayName.value)
72+
return validateStringInput(this.displayName.value)
7373
},
7474
},
7575
}

apps/settings/src/components/PersonalInfo/HeadlineSection/HeadlineSection.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
<section>
2525
<HeaderBar :account-property="accountProperty"
2626
label-for="headline"
27-
:scope.sync="primaryHeadline.scope" />
27+
:scope.sync="headline.scope" />
2828

29-
<Headline :headline.sync="primaryHeadline.value"
30-
:scope.sync="primaryHeadline.scope" />
29+
<Headline :headline.sync="headline.value"
30+
:scope.sync="headline.scope" />
3131
</section>
3232
</template>
3333

@@ -39,7 +39,7 @@ import HeaderBar from '../shared/HeaderBar'
3939
4040
import { ACCOUNT_PROPERTY_READABLE_ENUM } from '../../../constants/AccountPropertyConstants'
4141
42-
const { headlineMap: { primaryHeadline } } = loadState('settings', 'personalInfoParameters', {})
42+
const { headline } = loadState('settings', 'personalInfoParameters', {})
4343
4444
export default {
4545
name: 'HeadlineSection',
@@ -52,7 +52,7 @@ export default {
5252
data() {
5353
return {
5454
accountProperty: ACCOUNT_PROPERTY_READABLE_ENUM.HEADLINE,
55-
primaryHeadline,
55+
headline,
5656
}
5757
},
5858
}

apps/settings/src/components/PersonalInfo/OrganisationSection/OrganisationSection.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
<section>
2525
<HeaderBar :account-property="accountProperty"
2626
label-for="organisation"
27-
:scope.sync="primaryOrganisation.scope" />
27+
:scope.sync="organisation.scope" />
2828

29-
<Organisation :organisation.sync="primaryOrganisation.value"
30-
:scope.sync="primaryOrganisation.scope" />
29+
<Organisation :organisation.sync="organisation.value"
30+
:scope.sync="organisation.scope" />
3131
</section>
3232
</template>
3333

@@ -39,7 +39,7 @@ import HeaderBar from '../shared/HeaderBar'
3939
4040
import { ACCOUNT_PROPERTY_READABLE_ENUM } from '../../../constants/AccountPropertyConstants'
4141
42-
const { organisationMap: { primaryOrganisation } } = loadState('settings', 'personalInfoParameters', {})
42+
const { organisation } = loadState('settings', 'personalInfoParameters', {})
4343
4444
export default {
4545
name: 'OrganisationSection',
@@ -52,7 +52,7 @@ export default {
5252
data() {
5353
return {
5454
accountProperty: ACCOUNT_PROPERTY_READABLE_ENUM.ORGANISATION,
55-
primaryOrganisation,
55+
organisation,
5656
}
5757
},
5858
}

apps/settings/src/components/PersonalInfo/ProfileSection/ProfileSection.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ import ProfilePreviewCard from './ProfilePreviewCard'
4747
import { ACCOUNT_PROPERTY_READABLE_ENUM } from '../../../constants/AccountPropertyConstants'
4848
4949
const {
50-
organisationMap: { primaryOrganisation: { value: organisation } },
51-
displayNameMap: { primaryDisplayName: { value: displayName } },
50+
organisation: { value: organisation },
51+
displayName: { value: displayName },
5252
profileEnabled,
5353
userId,
5454
} = loadState('settings', 'personalInfoParameters', {})

apps/settings/src/components/PersonalInfo/RoleSection/RoleSection.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
<section>
2525
<HeaderBar :account-property="accountProperty"
2626
label-for="role"
27-
:scope.sync="primaryRole.scope" />
27+
:scope.sync="role.scope" />
2828

29-
<Role :role.sync="primaryRole.value"
30-
:scope.sync="primaryRole.scope" />
29+
<Role :role.sync="role.value"
30+
:scope.sync="role.scope" />
3131
</section>
3232
</template>
3333

@@ -39,7 +39,7 @@ import HeaderBar from '../shared/HeaderBar'
3939
4040
import { ACCOUNT_PROPERTY_READABLE_ENUM } from '../../../constants/AccountPropertyConstants'
4141
42-
const { roleMap: { primaryRole } } = loadState('settings', 'personalInfoParameters', {})
42+
const { role } = loadState('settings', 'personalInfoParameters', {})
4343
4444
export default {
4545
name: 'RoleSection',
@@ -52,7 +52,7 @@ export default {
5252
data() {
5353
return {
5454
accountProperty: ACCOUNT_PROPERTY_READABLE_ENUM.ROLE,
55-
primaryRole,
55+
role,
5656
}
5757
},
5858
}

dist/settings-vue-settings-personal-info.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/settings-vue-settings-personal-info.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)