fix: use `user.hidePrivateData();` more consistently across user retrieval endpoints

isekai-main
Julian Lam 3 years ago
parent c26be43ac5
commit 0529f2fb5d

@ -28,7 +28,7 @@ helpers.getUserDataByUserSlug = async function (userslug, callerUID, query = {})
}
await parseAboutMe(results.userData);
const { userData } = results;
let { userData } = results;
const { userSettings } = results;
const { isAdmin } = results;
const { isGlobalModerator } = results;
@ -41,17 +41,8 @@ helpers.getUserDataByUserSlug = async function (userslug, callerUID, query = {})
userData.birthday ? Math.floor((new Date().getTime() - new Date(userData.birthday).getTime()) / 31536000000) : 0
);
userData.emailClass = 'hide';
if (!results.canEdit && (!userSettings.showemail || meta.config.hideEmail)) {
userData.email = '';
} else if (!userSettings.showemail) {
userData.emailClass = '';
}
if (!results.canEdit && (!userSettings.showfullname || meta.config.hideFullname)) {
userData.fullname = '';
}
userData = await user.hidePrivateData(userData, callerUID);
userData.emailClass = userSettings.showemail ? 'hide' : '';
if (isAdmin || isSelf || (canViewInfo && !results.isTargetAdmin)) {
userData.ips = results.ips;

@ -3,7 +3,6 @@
const path = require('path');
const user = require('../user');
const meta = require('../meta');
const privileges = require('../privileges');
const accountHelpers = require('./accounts/helpers');
@ -68,17 +67,13 @@ userController.getUserDataByUID = async function (callerUid, uid) {
if (!canView) {
throw new Error('[[error:no-privileges]]');
}
const [userData, settings] = await Promise.all([
user.getUserData(uid),
user.getSettings(uid),
]);
let userData = await user.getUserData(uid);
if (!userData) {
throw new Error('[[error:no-user]]');
}
userData.email = settings.showemail && !meta.config.hideEmail ? userData.email : undefined;
userData.fullname = settings.showfullname && !meta.config.hideFullname ? userData.fullname : undefined;
userData = await user.hidePrivateData(userData, callerUid);
return userData;
};

Loading…
Cancel
Save