refactor: improvements

v1.18.x
gasoved 4 years ago committed by Julian Lam
parent 53e0d4d2e0
commit 970bd06fd2

@ -91,6 +91,7 @@ helpers.getUserDataByUserSlug = async function (userslug, callerUID) {
});
userData.sso = results.sso.associations;
userData.banned = Boolean(userData.banned);
userData.website = validator.escape(String(userData.website || ''));
userData.websiteLink = !userData.website.startsWith('http') ? 'http://' + userData.website : userData.website;
userData.websiteName = userData.website.replace(validator.escape('http://'), '').replace(validator.escape('https://'), '');

@ -31,7 +31,7 @@ module.exports = {
await db.sortedSetAdd(
'group:banned-users:members',
uids.map(() => now),
uids.map(uid => uid)
uids
);
await db.sortedSetRemove(
@ -41,7 +41,7 @@ module.exports = {
'group:unverified-users:members',
'group:Global Moderators:members',
],
uids.map(uid => uid)
uids
);
}, {
batch: 500,

@ -116,13 +116,11 @@ module.exports = function (User) {
User.bans.calcExpiredFromUserData = async function (userData) {
const isArray = Array.isArray(userData);
userData = isArray ? userData : [userData];
userData = await Promise.all(userData.map(async function (userData) {
const banned = await groups.isMember(userData.uid, groups.BANNED_USERS);
return {
banned: banned,
'banned:expire': userData && userData['banned:expire'],
banExpired: userData && userData['banned:expire'] <= Date.now() && userData['banned:expire'] !== 0,
};
const banned = await groups.isMembers(userData.map(u => u.uid), groups.BANNED_USERS);
userData = userData.map((userData, index) => ({
banned: banned[index],
'banned:expire': userData && userData['banned:expire'],
banExpired: userData && userData['banned:expire'] <= Date.now() && userData['banned:expire'] !== 0,
}));
return isArray ? userData : userData[0];
};

Loading…
Cancel
Save