feat: add displayname into user obj #8637 (#8909)

* feat: add displayname into user obj #8637

* fix: spec

* perf: dont load settings if acp setting is turned off
This commit is contained in:
Barış Soner Uşaklı
2020-11-19 00:52:19 -05:00
committed by GitHub
parent 8d060065a0
commit 9ca44e6f54
17 changed files with 98 additions and 0 deletions

View File

@@ -114,6 +114,7 @@
"email:smtpTransport:pool": false,
"hideFullname": 0,
"hideEmail": 0,
"showFullnameAsDisplayName": 0,
"allowGuestHandles": 0,
"guestsIncrementTopicViews": 1,
"allowGuestReplyNotifications": 1,

View File

@@ -16,6 +16,7 @@
"allow-account-deletion": "Allow account deletion",
"hide-fullname": "Hide fullname from users",
"hide-email": "Hide email from users",
"show-fullname-as-displayname": "Show user's full name as their display name if available",
"themes": "Themes",
"disable-user-skins": "Prevent users from choosing a custom skin",
"account-protection": "Account Protection",

View File

@@ -34,6 +34,9 @@ PostObject:
username:
type: string
description: A friendly name for a given user account
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
userslug:
type: string
description: An URL-safe variant of the username (i.e. lower-cased, spaces

View File

@@ -89,6 +89,9 @@ TopicObject:
username:
type: string
description: A friendly name for a given user account
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
fullname:
type: string
userslug:

View File

@@ -27,6 +27,10 @@ UserObj:
fullname:
type: string
example: Mr. Dragon Fruit Jr.
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
example: Dragon Fruit
location:
type: string
example: 'Toronto, Canada'

View File

@@ -37,6 +37,10 @@ UserObject:
fullname:
type: string
example: Mr. Dragon Fruit Jr.
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
example: Dragon Fruit
location:
type: string
example: 'Toronto, Canada'
@@ -227,6 +231,10 @@ UserObjectFull:
fullname:
type: string
example: Mr. Dragon Fruit Jr.
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
example: Dragon Fruit
location:
type: string
example: 'Toronto, Canada'
@@ -463,6 +471,10 @@ UserObjectSlim:
type: string
description: A friendly name for a given user account
example: Dragon Fruit
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
example: Dragon Fruit
userslug:
type: string
description: An URL-safe variant of the username (i.e. lower-cased, spaces removed, etc.)
@@ -544,6 +556,10 @@ UserObjectACP:
type: string
description: A friendly name for a given user account
example: Dragon Fruit
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
example: Dragon Fruit
userslug:
type: string
description: An URL-safe variant of the username (i.e. lower-cased, spaces removed, etc.)

View File

@@ -21,6 +21,9 @@ get:
username:
type: string
description: A friendly name for a given user account
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
picture:
nullable: true
type: string

View File

@@ -150,6 +150,9 @@ get:
username:
type: string
description: A friendly name for a given user account
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
userslug:
type: string
description: An URL-safe variant of the username (i.e. lower-cased, spaces

View File

@@ -77,6 +77,9 @@ get:
username:
type: string
description: A friendly name for a given user account
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
userslug:
type: string
description: An URL-safe variant of the username (i.e. lower-cased, spaces
@@ -160,6 +163,9 @@ get:
username:
type: string
description: A friendly name for a given user account
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
userslug:
type: string
description: An URL-safe variant of the username (i.e. lower-cased, spaces

View File

@@ -83,6 +83,9 @@ get:
username:
type: string
description: A friendly name for a given user account
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
userslug:
type: string
description: An URL-safe variant of the username (i.e. lower-cased, spaces
@@ -145,6 +148,9 @@ get:
username:
type: string
description: A friendly name for a given user account
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
userslug:
type: string
description: An URL-safe variant of the username (i.e. lower-cased, spaces

View File

@@ -36,6 +36,9 @@ get:
username:
type: string
description: A friendly name for a given user account
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
userslug:
type: string
description: An URL-safe variant of the username (i.e. lower-cased, spaces

View File

@@ -137,6 +137,9 @@ get:
username:
type: string
description: A friendly name for a given user account
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
userslug:
type: string
description: An URL-safe variant of the username (i.e. lower-cased, spaces

View File

@@ -109,6 +109,9 @@ get:
username:
type: string
description: A friendly name for a given user account
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
fullname:
type: string
userslug:

View File

@@ -65,6 +65,9 @@ get:
username:
type: string
description: A friendly name for a given user account
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
userslug:
type: string
description: An URL-safe variant of the username (i.e. lower-cased, spaces
@@ -115,6 +118,9 @@ get:
username:
type: string
description: A friendly name for a given user account
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
picture:
type: string
nullable: true
@@ -171,6 +177,9 @@ get:
username:
type: string
description: A friendly name for a given user account
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
userslug:
type: string
description: An URL-safe variant of the username (i.e. lower-cased, spaces
@@ -221,6 +230,9 @@ get:
username:
type: string
description: A friendly name for a given user account
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
userslug:
type: string
description: An URL-safe variant of the username (i.e. lower-cased, spaces
@@ -256,6 +268,9 @@ get:
username:
type: string
description: A friendly name for a given user account
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
userslug:
type: string
description: An URL-safe variant of the username (i.e. lower-cased, spaces

View File

@@ -38,6 +38,9 @@ get:
username:
type: string
description: A friendly name for a given user account
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
userslug:
type: string
description: An URL-safe variant of the username (i.e. lower-cased, spaces

View File

@@ -136,6 +136,15 @@ module.exports = function (User) {
};
async function modifyUserData(users, requestedFields, fieldsToRemove) {
let uidToSettings = {};
if (meta.config.showFullnameAsDisplayName) {
const uids = _.uniq(users.map(user => user.uid));
uidToSettings = _.zipObject(uids, await db.getObjectsFields(
uids.map(uid => 'user:' + uid + ':settings'),
['showfullname']
));
}
users = await Promise.all(users.map(async function (user) {
if (!user) {
return user;
@@ -144,6 +153,16 @@ module.exports = function (User) {
db.parseIntFields(user, intFields, requestedFields);
if (user.hasOwnProperty('username')) {
let showfullname = parseInt(meta.config.showfullname, 10) === 1;
if (uidToSettings[user.uid] && parseInt(uidToSettings[user.uid].showfullname, 10) === 0) {
showfullname = false;
}
user.displayname = validator.escape(String(
meta.config.showFullnameAsDisplayName && showfullname && user.fullname ?
user.fullname :
user.username
));
user.username = validator.escape(user.username ? user.username.toString() : '');
}

View File

@@ -77,6 +77,12 @@
<span class="mdl-switch__label"><strong>[[admin/settings/user:hide-email]]</strong></span>
</label>
</div>
<div class="checkbox">
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
<input class="mdl-switch__input" type="checkbox" data-field="showFullnameAsDisplayName">
<span class="mdl-switch__label"><strong>[[admin/settings/user:show-fullname-as-displayname]]</strong></span>
</label>
</div>
</form>
</div>
</div>