Skip to content

Node.js based forum software built for the modern web

add groupTitle test for guests

Barış Soner Uşaklıa6864a8055ae
diff --git a/src/user/data.js b/src/user/data.js
index 32ffe0624a..ec3a51000f 100644
--- a/src/user/data.js
+++ b/src/user/data.js
@@ -141,9 +141,6 @@ module.exports = function (User) {
db.parseIntFields(user, intFields, requestedFields);
- if (user.hasOwnProperty('groupTitle')) {
- parseGroupTitle(user);
- }
if (user.hasOwnProperty('username')) {
user.username = validator.escape(user.username ? user.username.toString() : '');
}
@@ -155,6 +152,11 @@ module.exports = function (User) {
user.picture = User.getDefaultAvatar();
user['icon:text'] = '?';
user['icon:bgColor'] = '#aaa';
+ user.groupTitle = '';
+ }
+
+ if (user.hasOwnProperty('groupTitle')) {
+ parseGroupTitle(user);
}
if (user.picture && user.picture === user.uploadedpicture) {
@@ -204,12 +206,20 @@ module.exports = function (User) {
try {
user.groupTitleArray = JSON.parse(user.groupTitle);
} catch (err) {
- user.groupTitleArray = [user.groupTitle];
+ if (user.groupTitle) {
+ user.groupTitleArray = [user.groupTitle];
+ } else {
+ user.groupTitleArray = [];
+ }
}
if (!Array.isArray(user.groupTitleArray)) {
- user.groupTitleArray = [user.groupTitleArray];
+ if (user.groupTitleArray) {
+ user.groupTitleArray = [user.groupTitleArray];
+ } else {
+ user.groupTitleArray = [];
+ }
}
- if (!meta.config.allowMultipleBadges) {
+ if (!meta.config.allowMultipleBadges && user.groupTitleArray.length) {
user.groupTitleArray = [user.groupTitleArray[0]];
}
}
diff --git a/test/user.js b/test/user.js
index ef349acccd..387b038ba2 100644
--- a/test/user.js
+++ b/test/user.js
@@ -605,6 +605,15 @@ describe('User', function () {
done();
});
});
+
+ it('should not get groupTitle for guests', function (done) {
+ User.getUserData(0, function (err, userData) {
+ assert.ifError(err);
+ assert.strictEqual(userData.groupTitle, '');
+ assert.deepStrictEqual(userData.groupTitleArray, []);
+ done();
+ });
+ });
});
describe('not logged in', function () {