mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-26 15:50:24 +02:00
Merge branch 'develop' into activitypub
This commit is contained in:
@@ -29,6 +29,8 @@ module.exports = function (User) {
|
||||
'cover:position', 'groupTitle', 'mutedUntil', 'mutedReason',
|
||||
];
|
||||
|
||||
let customFieldWhiteList = null;
|
||||
|
||||
User.guestData = {
|
||||
uid: 0,
|
||||
username: '[[global:guest]]',
|
||||
@@ -47,6 +49,10 @@ module.exports = function (User) {
|
||||
|
||||
let iconBackgrounds;
|
||||
|
||||
User.reloadCustomFieldWhitelist = async () => {
|
||||
customFieldWhiteList = await db.getSortedSetRange('user-custom-fields', 0, -1);
|
||||
};
|
||||
|
||||
User.getUsersFields = async function (uids, fields) {
|
||||
if (!Array.isArray(uids) || !uids.length) {
|
||||
return [];
|
||||
@@ -68,10 +74,13 @@ module.exports = function (User) {
|
||||
|
||||
const uniqueUids = _.uniq(uids).filter(uid => isFinite(uid) && uid > 0);
|
||||
const remoteIds = _.uniq(uids).filter(uid => !isFinite(uid));
|
||||
if (!customFieldWhiteList) {
|
||||
await User.reloadCustomFieldWhitelist();
|
||||
}
|
||||
|
||||
const results = await plugins.hooks.fire('filter:user.whitelistFields', {
|
||||
uids: uids,
|
||||
whitelist: fieldWhitelist.slice(),
|
||||
whitelist: _.uniq(fieldWhitelist.concat(customFieldWhiteList)),
|
||||
});
|
||||
if (!fields.length) {
|
||||
fields = results.whitelist;
|
||||
|
||||
@@ -12,12 +12,14 @@ const db = require('../database');
|
||||
const groups = require('../groups');
|
||||
const plugins = require('../plugins');
|
||||
const api = require('../api');
|
||||
const tx = require('../translator');
|
||||
|
||||
module.exports = function (User) {
|
||||
User.updateProfile = async function (uid, data, extraFields) {
|
||||
let fields = [
|
||||
'username', 'email', 'fullname', 'website', 'location',
|
||||
'groupTitle', 'birthday', 'signature', 'aboutme',
|
||||
...await db.getSortedSetRange('user-custom-fields', 0, -1),
|
||||
];
|
||||
if (Array.isArray(extraFields)) {
|
||||
fields = _.uniq(fields.concat(extraFields));
|
||||
@@ -84,6 +86,49 @@ module.exports = function (User) {
|
||||
isLocationValid(data);
|
||||
isBirthdayValid(data);
|
||||
isGroupTitleValid(data);
|
||||
await validateCustomFields(data);
|
||||
}
|
||||
|
||||
async function validateCustomFields(data) {
|
||||
const keys = await db.getSortedSetRange('user-custom-fields', 0, -1);
|
||||
const fields = (await db.getObjects(keys.map(k => `user-custom-field:${k}`))).filter(Boolean);
|
||||
const reputation = await User.getUserField(data.uid, 'reputation');
|
||||
|
||||
fields.forEach((field) => {
|
||||
const { key, type } = field;
|
||||
if (data.hasOwnProperty(key)) {
|
||||
const value = data[key];
|
||||
const minRep = field['min:rep'] || 0;
|
||||
if (reputation < minRep && !meta.config['reputation:disabled']) {
|
||||
throw new Error(tx.compile(
|
||||
'error:not-enough-reputation-custom-field', minRep, field.name
|
||||
));
|
||||
}
|
||||
|
||||
if (typeof value === 'string' && value.length > 255) {
|
||||
throw new Error(tx.compile(
|
||||
'error:custom-user-field-value-too-long', field.name
|
||||
));
|
||||
}
|
||||
|
||||
if (type === 'input-number' && !utils.isNumber(value)) {
|
||||
throw new Error(tx.compile(
|
||||
'error:custom-user-field-invalid-number', field.name
|
||||
));
|
||||
} else if (value && field.type === 'input-link' && !validator.isURL(String(value))) {
|
||||
throw new Error(tx.compile(
|
||||
'error:custom-user-field-invalid-link', field.name
|
||||
));
|
||||
} else if (field.type === 'select') {
|
||||
const opts = field['select-options'].split('\n').filter(Boolean);
|
||||
if (!opts.includes(value)) {
|
||||
throw new Error(tx.compile(
|
||||
'error:custom-user-field-select-value-invalid', field.name
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function isEmailValid(data) {
|
||||
|
||||
Reference in New Issue
Block a user