mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-03 19:11:22 +01:00
refactor: closes #7155,
display registered-users as Registered Users display administators as Administrators handle missing slug in group data
This commit is contained in:
@@ -107,10 +107,10 @@
|
|||||||
"nodebb-plugin-spam-be-gone": "2.3.2",
|
"nodebb-plugin-spam-be-gone": "2.3.2",
|
||||||
"nodebb-plugin-web-push": "0.7.6",
|
"nodebb-plugin-web-push": "0.7.6",
|
||||||
"nodebb-rewards-essentials": "1.0.2",
|
"nodebb-rewards-essentials": "1.0.2",
|
||||||
"nodebb-theme-harmony": "2.2.25",
|
"nodebb-theme-harmony": "2.2.26",
|
||||||
"nodebb-theme-lavender": "7.1.21",
|
"nodebb-theme-lavender": "7.1.21",
|
||||||
"nodebb-theme-peace": "2.2.51",
|
"nodebb-theme-peace": "2.2.51",
|
||||||
"nodebb-theme-persona": "14.2.17",
|
"nodebb-theme-persona": "14.2.19",
|
||||||
"nodebb-widget-essentials": "7.0.42",
|
"nodebb-widget-essentials": "7.0.42",
|
||||||
"nodemailer": "8.0.1",
|
"nodemailer": "8.0.1",
|
||||||
"nprogress": "0.2.0",
|
"nprogress": "0.2.0",
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ const plugins = require('../plugins');
|
|||||||
const utils = require('../utils');
|
const utils = require('../utils');
|
||||||
const translator = require('../translator');
|
const translator = require('../translator');
|
||||||
const coverPhoto = require('../coverPhoto');
|
const coverPhoto = require('../coverPhoto');
|
||||||
|
const slugify = require('../slugify');
|
||||||
|
|
||||||
const relative_path = nconf.get('relative_path');
|
const relative_path = nconf.get('relative_path');
|
||||||
|
|
||||||
@@ -68,74 +69,81 @@ module.exports = function (Groups) {
|
|||||||
await db.setObjectField(`group:${groupName}`, field, value);
|
await db.setObjectField(`group:${groupName}`, field, value);
|
||||||
plugins.hooks.fire('action:group.set', { field: field, value: value, type: 'set' });
|
plugins.hooks.fire('action:group.set', { field: field, value: value, type: 'set' });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function modifyGroup(group, fields) {
|
||||||
|
if (group) {
|
||||||
|
const hasField = utils.createFieldChecker(fields);
|
||||||
|
|
||||||
|
if (hasField('private')) {
|
||||||
|
// Default to private if not set, as groups are private by default
|
||||||
|
group.private = ([null, undefined].includes(group.private)) ? 1 : group.private;
|
||||||
|
}
|
||||||
|
|
||||||
|
db.parseIntFields(group, intFields, fields);
|
||||||
|
|
||||||
|
escapeGroupData(group, hasField);
|
||||||
|
|
||||||
|
if (hasField('slug') && group.name && !group.slug) {
|
||||||
|
group.slug = slugify(group.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasField('labelColor')) {
|
||||||
|
group.labelColor = validator.escape(String(group.labelColor || '#000000'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasField('textColor')) {
|
||||||
|
group.textColor = validator.escape(String(group.textColor || '#ffffff'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasField('icon')) {
|
||||||
|
group.icon = validator.escape(String(group.icon || ''));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasField('createtime')) {
|
||||||
|
group.createtimeISO = utils.toISOString(group.createtime);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasField('memberPostCids')) {
|
||||||
|
group.memberPostCids = group.memberPostCids || '';
|
||||||
|
group.memberPostCidsArray = group.memberPostCids.split(',').map(cid => parseInt(cid, 10)).filter(Boolean);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasField('cover:thumb:url')) {
|
||||||
|
group['cover:thumb:url'] = group['cover:thumb:url'] || group['cover:url'];
|
||||||
|
|
||||||
|
group['cover:thumb:url'] = group['cover:thumb:url'] ?
|
||||||
|
prependRelativePath(group['cover:thumb:url']) :
|
||||||
|
coverPhoto.getDefaultGroupCover(group.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasField('cover:url')) {
|
||||||
|
group['cover:url'] = group['cover:url'] ?
|
||||||
|
prependRelativePath(group['cover:url']) :
|
||||||
|
coverPhoto.getDefaultGroupCover(group.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasField('cover:position')) {
|
||||||
|
group['cover:position'] = validator.escape(String(group['cover:position'] || '50% 50%'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeGroupData(group, hasField) {
|
||||||
|
if (group) {
|
||||||
|
if (hasField('name')) {
|
||||||
|
group.nameEncoded = encodeURIComponent(group.name);
|
||||||
|
group.displayName = validator.escape(String(group.name));
|
||||||
|
if (Groups.systemGroups.includes(group.name)) {
|
||||||
|
group.displayName = group.displayName.replace(/-/g, ' ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hasField('description')) {
|
||||||
|
group.description = validator.escape(String(group.description || ''));
|
||||||
|
}
|
||||||
|
if (hasField('userTitle')) {
|
||||||
|
group.userTitle = validator.escape(String(group.userTitle || ''));
|
||||||
|
group.userTitleEscaped = translator.escape(group.userTitle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function modifyGroup(group, fields) {
|
|
||||||
if (group) {
|
|
||||||
const hasField = utils.createFieldChecker(fields);
|
|
||||||
|
|
||||||
if (hasField('private')) {
|
|
||||||
// Default to private if not set, as groups are private by default
|
|
||||||
group.private = ([null, undefined].includes(group.private)) ? 1 : group.private;
|
|
||||||
}
|
|
||||||
|
|
||||||
db.parseIntFields(group, intFields, fields);
|
|
||||||
|
|
||||||
escapeGroupData(group, hasField);
|
|
||||||
|
|
||||||
if (hasField('labelColor')) {
|
|
||||||
group.labelColor = validator.escape(String(group.labelColor || '#000000'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasField('textColor')) {
|
|
||||||
group.textColor = validator.escape(String(group.textColor || '#ffffff'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasField('icon')) {
|
|
||||||
group.icon = validator.escape(String(group.icon || ''));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasField('createtime')) {
|
|
||||||
group.createtimeISO = utils.toISOString(group.createtime);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasField('memberPostCids')) {
|
|
||||||
group.memberPostCids = group.memberPostCids || '';
|
|
||||||
group.memberPostCidsArray = group.memberPostCids.split(',').map(cid => parseInt(cid, 10)).filter(Boolean);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasField('cover:thumb:url')) {
|
|
||||||
group['cover:thumb:url'] = group['cover:thumb:url'] || group['cover:url'];
|
|
||||||
|
|
||||||
group['cover:thumb:url'] = group['cover:thumb:url'] ?
|
|
||||||
prependRelativePath(group['cover:thumb:url']) :
|
|
||||||
coverPhoto.getDefaultGroupCover(group.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasField('cover:url')) {
|
|
||||||
group['cover:url'] = group['cover:url'] ?
|
|
||||||
prependRelativePath(group['cover:url']) :
|
|
||||||
coverPhoto.getDefaultGroupCover(group.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasField('cover:position')) {
|
|
||||||
group['cover:position'] = validator.escape(String(group['cover:position'] || '50% 50%'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function escapeGroupData(group, hasField) {
|
|
||||||
if (group) {
|
|
||||||
if (hasField('name')) {
|
|
||||||
group.nameEncoded = encodeURIComponent(group.name);
|
|
||||||
group.displayName = validator.escape(String(group.name));
|
|
||||||
}
|
|
||||||
if (hasField('description')) {
|
|
||||||
group.description = validator.escape(String(group.description || ''));
|
|
||||||
}
|
|
||||||
if (hasField('userTitle')) {
|
|
||||||
group.userTitle = validator.escape(String(group.userTitle || ''));
|
|
||||||
group.userTitleEscaped = translator.escape(group.userTitle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user