diff --git a/install/data/defaults.json b/install/data/defaults.json index 05b16670cc..2682dde707 100644 --- a/install/data/defaults.json +++ b/install/data/defaults.json @@ -114,6 +114,7 @@ "email:smtpTransport:pool": false, "hideFullname": 0, "hideEmail": 0, + "showFullnameAsDisplayName": 0, "allowGuestHandles": 0, "guestsIncrementTopicViews": 1, "allowGuestReplyNotifications": 1, diff --git a/public/language/en-GB/admin/settings/user.json b/public/language/en-GB/admin/settings/user.json index e05aa5e3ed..48be13b75e 100644 --- a/public/language/en-GB/admin/settings/user.json +++ b/public/language/en-GB/admin/settings/user.json @@ -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", diff --git a/public/openapi/components/schemas/PostObject.yaml b/public/openapi/components/schemas/PostObject.yaml index fc2da47e12..5ff918cd7f 100644 --- a/public/openapi/components/schemas/PostObject.yaml +++ b/public/openapi/components/schemas/PostObject.yaml @@ -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 diff --git a/public/openapi/components/schemas/TopicObject.yaml b/public/openapi/components/schemas/TopicObject.yaml index 69662e0080..10453fe22b 100644 --- a/public/openapi/components/schemas/TopicObject.yaml +++ b/public/openapi/components/schemas/TopicObject.yaml @@ -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: diff --git a/public/openapi/components/schemas/UserObj.yaml b/public/openapi/components/schemas/UserObj.yaml index edcadb150d..fc2837b2cb 100644 --- a/public/openapi/components/schemas/UserObj.yaml +++ b/public/openapi/components/schemas/UserObj.yaml @@ -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' diff --git a/public/openapi/components/schemas/UserObject.yaml b/public/openapi/components/schemas/UserObject.yaml index 6c6910a239..1970b7a23e 100644 --- a/public/openapi/components/schemas/UserObject.yaml +++ b/public/openapi/components/schemas/UserObject.yaml @@ -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.) diff --git a/public/openapi/read/admin/manage/digest.yaml b/public/openapi/read/admin/manage/digest.yaml index 6ddfc471e2..f094a3f7b6 100644 --- a/public/openapi/read/admin/manage/digest.yaml +++ b/public/openapi/read/admin/manage/digest.yaml @@ -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 diff --git a/public/openapi/read/categories.yaml b/public/openapi/read/categories.yaml index cfa3cc9724..723501a410 100644 --- a/public/openapi/read/categories.yaml +++ b/public/openapi/read/categories.yaml @@ -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 diff --git a/public/openapi/read/flags/flagId.yaml b/public/openapi/read/flags/flagId.yaml index aa41da77d5..50be414e56 100644 --- a/public/openapi/read/flags/flagId.yaml +++ b/public/openapi/read/flags/flagId.yaml @@ -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 diff --git a/public/openapi/read/index.yaml b/public/openapi/read/index.yaml index 4b29a1dc99..33a1daadd9 100644 --- a/public/openapi/read/index.yaml +++ b/public/openapi/read/index.yaml @@ -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 diff --git a/public/openapi/read/notifications.yaml b/public/openapi/read/notifications.yaml index 84d3e56c51..59acc0ad62 100644 --- a/public/openapi/read/notifications.yaml +++ b/public/openapi/read/notifications.yaml @@ -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 diff --git a/public/openapi/read/topic/topic_id/slug/post_index.yaml b/public/openapi/read/topic/topic_id/slug/post_index.yaml index 47e0a60d2e..6dac531eab 100644 --- a/public/openapi/read/topic/topic_id/slug/post_index.yaml +++ b/public/openapi/read/topic/topic_id/slug/post_index.yaml @@ -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 diff --git a/public/openapi/read/unread.yaml b/public/openapi/read/unread.yaml index 49360647da..a5fe83348e 100644 --- a/public/openapi/read/unread.yaml +++ b/public/openapi/read/unread.yaml @@ -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: diff --git a/public/openapi/read/user/userslug/chats/roomid.yaml b/public/openapi/read/user/userslug/chats/roomid.yaml index 2612848acd..72fc62a125 100644 --- a/public/openapi/read/user/userslug/chats/roomid.yaml +++ b/public/openapi/read/user/userslug/chats/roomid.yaml @@ -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 diff --git a/public/openapi/read/users.yaml b/public/openapi/read/users.yaml index a591bd61a5..160aa927d0 100644 --- a/public/openapi/read/users.yaml +++ b/public/openapi/read/users.yaml @@ -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 diff --git a/src/user/data.js b/src/user/data.js index c1fb6be11f..920c19086b 100644 --- a/src/user/data.js +++ b/src/user/data.js @@ -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() : ''); } diff --git a/src/views/admin/settings/user.tpl b/src/views/admin/settings/user.tpl index f9f56e2eee..fc17a4e2f0 100644 --- a/src/views/admin/settings/user.tpl +++ b/src/views/admin/settings/user.tpl @@ -77,6 +77,12 @@ [[admin/settings/user:hide-email]] +
+ +