From 45731abbe58bfdd950f0cccfa1f57dd3af1d5d16 Mon Sep 17 00:00:00 2001 From: Trish Harsono Date: Sat, 24 Jan 2026 00:35:03 +0000 Subject: [PATCH 1/2] simplified isGroupTitleValid by adding helper functions --- src/user/profile.js | 53 +++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/user/profile.js b/src/user/profile.js index 3009d0a3d5..f1c5d8b700 100644 --- a/src/user/profile.js +++ b/src/user/profile.js @@ -241,41 +241,42 @@ module.exports = function (User) { } function isGroupTitleValid(data) { - function checkTitle(title) { - if (title === 'registered-users' || groups.isPrivilegeGroup(title)) { - throw new Error('[[error:invalid-group-title]]'); - } - } if (!data.groupTitle) { return; } - let groupTitles = []; - if (validator.isJSON(data.groupTitle)) { - groupTitles = JSON.parse(data.groupTitle); - if (!Array.isArray(groupTitles)) { + + const groupTitles = parseGroupTitles(data.groupTitle); + validateGroupTitles(groupTitles); + enforceMultipleBadgeLimit(data, groupTitles); + } + + function parseGroupTitles(groupTitle) { + if (!validator.isJSON(groupTitle)) { + return [groupTitle]; + } + + const parsed = JSON.parse(groupTitle); + if (!Array.isArray(parsed)) { + throw new Error('[[error:invalid-group-title]]'); + } + + return parsed; + } + + function validateGroupTitles(titles) { + titles.forEach((groupTitle) => { + if (groupTitle === 'registered-users' || groups.isPrivilegeGroup(groupTitle)) { throw new Error('[[error:invalid-group-title]]'); } - groupTitles.forEach(title => checkTitle(title)); - } else { - groupTitles = [data.groupTitle]; - checkTitle(data.groupTitle); - } + }); + } + + function enforceMultipleBadgeLimit(data, groupTitles) { if (!meta.config.allowMultipleBadges && groupTitles.length > 1) { data.groupTitle = JSON.stringify(groupTitles[0]); } } - - User.checkMinReputation = async function (callerUid, uid, setting) { - const isSelf = parseInt(callerUid, 10) === parseInt(uid, 10); - if (!isSelf || meta.config['reputation:disabled']) { - return; - } - const reputation = await User.getUserField(uid, 'reputation'); - if (reputation < meta.config[setting]) { - throw new Error(`[[error:not-enough-reputation-${setting.replace(/:/g, '-')}, ${meta.config[setting]}]]`); - } - }; - + async function updateEmail(uid, newEmail) { let oldEmail = await db.getObjectField(`user:${uid}`, 'email'); oldEmail = oldEmail || ''; From 83b7819c7d011e0ac7f22cd891799fec7eadde13 Mon Sep 17 00:00:00 2001 From: Trish Harsono Date: Sat, 24 Jan 2026 03:34:10 +0000 Subject: [PATCH 2/2] Adding deleted code, fixed email error issue --- src/user/profile.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/user/profile.js b/src/user/profile.js index f1c5d8b700..59741ecb9a 100644 --- a/src/user/profile.js +++ b/src/user/profile.js @@ -276,7 +276,18 @@ module.exports = function (User) { data.groupTitle = JSON.stringify(groupTitles[0]); } } - + + User.checkMinReputation = async function (callerUid, uid, setting) { + const isSelf = parseInt(callerUid, 10) === parseInt(uid, 10); + if (!isSelf || meta.config['reputation:disabled']) { + return; + } + const reputation = await User.getUserField(uid, 'reputation'); + if (reputation < meta.config[setting]) { + throw new Error(`[[error:not-enough-reputation-${setting.replace(/:/g, '-')}, ${meta.config[setting]}]]`); + } + }; + async function updateEmail(uid, newEmail) { let oldEmail = await db.getObjectField(`user:${uid}`, 'email'); oldEmail = oldEmail || '';