Skip to content

Commit

Permalink
fix: use user.hidePrivateData(); more consistently across user retr…
Browse files Browse the repository at this point in the history
…ieval endpoints
  • Loading branch information
julianlam committed Jun 29, 2022
1 parent 39b2599 commit 8a243e6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
15 changes: 3 additions & 12 deletions src/controllers/accounts/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
9 changes: 2 additions & 7 deletions src/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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;
};
Expand Down

0 comments on commit 8a243e6

Please sign in to comment.