From a9dbdc75af9831ba0a2294d2a3644995b6f8bfdd Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Wed, 26 Jul 2017 14:32:53 -0400 Subject: [PATCH] closes #5825 --- package.json | 4 +- .../language/en-GB/admin/settings/user.json | 4 +- src/controllers/accounts/helpers.js | 4 +- src/controllers/accounts/settings.js | 3 ++ src/controllers/user.js | 4 +- src/posts/user.js | 3 ++ src/topics.js | 7 +++ src/views/admin/settings/user.tpl | 12 +++++ test/user.js | 50 +++++++++++++++++++ 9 files changed, 84 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 7befecc2df..d761108513 100644 --- a/package.json +++ b/package.json @@ -65,9 +65,9 @@ "nodebb-plugin-spam-be-gone": "0.5.0", "nodebb-rewards-essentials": "0.0.9", "nodebb-theme-lavender": "4.0.5", - "nodebb-theme-persona": "5.0.14", + "nodebb-theme-persona": "5.0.15", "nodebb-theme-slick": "1.1.0", - "nodebb-theme-vanilla": "6.0.11", + "nodebb-theme-vanilla": "6.0.12", "nodebb-widget-essentials": "3.0.1", "nodemailer": "2.6.4", "nodemailer-sendmail-transport": "1.0.0", diff --git a/public/language/en-GB/admin/settings/user.json b/public/language/en-GB/admin/settings/user.json index fa8049c3a9..a8bc2b176e 100644 --- a/public/language/en-GB/admin/settings/user.json +++ b/public/language/en-GB/admin/settings/user.json @@ -13,7 +13,9 @@ "disable-email-changes": "Disable email changes", "disable-password-changes": "Disable password changes", "allow-account-deletion": "Allow account deletion", - "user-info-private": "Make user info private", + "user-info-private": "Hide user list and data from guests", + "hide-fullname": "Hide fullname from users", + "hide-email": "Hide email from users", "themes": "Themes", "disable-user-skins": "Prevent users from choosing a custom skin", "account-protection": "Account Protection", diff --git a/src/controllers/accounts/helpers.js b/src/controllers/accounts/helpers.js index 6086bf4cf8..5bd65a33af 100644 --- a/src/controllers/accounts/helpers.js +++ b/src/controllers/accounts/helpers.js @@ -85,13 +85,13 @@ helpers.getUserDataByUserSlug = function (userslug, callerUID, callback) { userData.emailClass = 'hide'; - if (!(isAdmin || isGlobalModerator || isSelf || (userData.email && userSettings.showemail))) { + if (!isAdmin && !isGlobalModerator && !isSelf && (!userSettings.showemail || parseInt(meta.config.hideEmail, 10) === 1)) { userData.email = ''; } else if (!userSettings.showemail) { userData.emailClass = ''; } - if (!isAdmin && !isGlobalModerator && !isSelf && !userSettings.showfullname) { + if (!isAdmin && !isGlobalModerator && !isSelf && (!userSettings.showfullname || parseInt(meta.config.hideFullname, 10) === 1)) { userData.fullname = ''; } diff --git a/src/controllers/accounts/settings.js b/src/controllers/accounts/settings.js index 0bcdc75c9c..2285f5e2dc 100644 --- a/src/controllers/accounts/settings.js +++ b/src/controllers/accounts/settings.js @@ -142,6 +142,9 @@ settingsController.get = function (req, res, callback) { userData.allowUserHomePage = parseInt(meta.config.allowUserHomePage, 10) === 1; + userData.hideFullname = parseInt(meta.config.hideFullname, 10) === 1; + userData.hideEmail = parseInt(meta.config.hideEmail, 10) === 1; + userData.inTopicSearchAvailable = plugins.hasListeners('filter:topic.search'); userData.title = '[[pages:account/settings]]'; diff --git a/src/controllers/user.js b/src/controllers/user.js index 0f93f549b3..ea027b9406 100644 --- a/src/controllers/user.js +++ b/src/controllers/user.js @@ -91,8 +91,8 @@ userController.getUserDataByUID = function (callerUid, uid, callback) { return callback(err || new Error('[[error:no-user]]')); } - results.userData.email = results.settings.showemail ? results.userData.email : undefined; - results.userData.fullname = results.settings.showfullname ? results.userData.fullname : undefined; + results.userData.email = results.settings.showemail && parseInt(meta.config.hideEmail, 10) !== 1 ? results.userData.email : undefined; + results.userData.fullname = results.settings.showfullname && parseInt(meta.config.hideFullname, 10) !== 1 ? results.userData.fullname : undefined; callback(null, results.userData); }); diff --git a/src/posts/user.js b/src/posts/user.js index 00fa1c0631..dd050ddd3e 100644 --- a/src/posts/user.js +++ b/src/posts/user.js @@ -49,6 +49,9 @@ module.exports = function (Posts) { userData.status = user.getStatus(userData); userData.signature = validator.escape(String(userData.signature || '')); userData.fullname = validator.escape(String(userData.fullname || '')); + if (parseInt(meta.config.hideFullname, 10) === 1) { + userData.fullname = undefined; + } }); async.map(userData, function (userData, next) { diff --git a/src/topics.js b/src/topics.js index 8dd5df0c13..45e0f5bb19 100644 --- a/src/topics.js +++ b/src/topics.js @@ -7,6 +7,7 @@ var db = require('./database'); var posts = require('./posts'); var utils = require('./utils'); var plugins = require('./plugins'); +var meta = require('./meta'); var user = require('./user'); var categories = require('./categories'); var privileges = require('./privileges'); @@ -135,6 +136,12 @@ Topics.getTopicsByTids = function (tids, uid, callback) { }, next); }, function (results, next) { + if (parseInt(meta.config.hideFullname, 10) === 1) { + results.users.forEach(function (user) { + user.fullname = undefined; + }); + } + var users = _.zipObject(uids, results.users); var categories = _.zipObject(cids, results.categories); diff --git a/src/views/admin/settings/user.tpl b/src/views/admin/settings/user.tpl index db7f078f29..9d933b54e1 100644 --- a/src/views/admin/settings/user.tpl +++ b/src/views/admin/settings/user.tpl @@ -71,6 +71,18 @@ [[admin/settings/user:user-info-private]] +
+ +
+
+ +
diff --git a/test/user.js b/test/user.js index a7204b01ca..9b747e27b7 100644 --- a/test/user.js +++ b/test/user.js @@ -1532,4 +1532,54 @@ describe('User', function () { }); }); }); + + describe('hideEmail/hideFullname', function () { + var uid; + after(function (done) { + meta.config.hideEmail = 0; + meta.config.hideFullname = 0; + done(); + }); + + it('should hide email and fullname', function (done) { + meta.config.hideEmail = 1; + meta.config.hideFullname = 1; + + User.create({ + username: 'hiddenemail', + email: 'should@be.hidden', + fullname: 'baris soner usakli', + }, function (err, _uid) { + uid = _uid; + assert.ifError(err); + request(nconf.get('url') + '/api/user/hiddenemail', { json: true }, function (err, res, body) { + assert.ifError(err); + assert.equal(body.fullname, ''); + assert.equal(body.email, ''); + + done(); + }); + }); + }); + + it('should hide fullname in topic list and topic', function (done) { + Topics.post({ + uid: uid, + title: 'Topic hidden', + content: 'lorem ipsum', + cid: testCid, + }, function (err) { + assert.ifError(err); + request(nconf.get('url') + '/api/recent', { json: true }, function (err, res, body) { + assert.ifError(err); + assert(!body.topics[0].user.hasOwnProperty('fullname')); + request(nconf.get('url') + '/api/topic/' + body.topics[0].slug, { json: true }, function (err, res, body) { + assert.ifError(err); + assert(!body.posts[0].user.hasOwnProperty('fullname')); + done(); + }); + }); + }); + }); + }); });