mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-09 16:17:45 +01:00
test: fix username test
move cover:url code to user/data.js like uploadedpicture
This commit is contained in:
@@ -119,13 +119,6 @@ helpers.getUserDataByUserSlug = async function (userslug, callerUID, query = {})
|
||||
userData.signature = escape(userData.signature);
|
||||
userData.birthday = validator.escape(String(userData.birthday || ''));
|
||||
userData.moderationNote = validator.escape(String(userData.moderationNote || ''));
|
||||
|
||||
if (userData['cover:url']) {
|
||||
userData['cover:url'] = userData['cover:url'].startsWith('http') ? userData['cover:url'] : (nconf.get('relative_path') + userData['cover:url']);
|
||||
} else {
|
||||
userData['cover:url'] = require('../../coverPhoto').getDefaultProfileCover(userData.uid);
|
||||
}
|
||||
|
||||
userData['cover:position'] = validator.escape(String(userData['cover:position'] || '50% 50%'));
|
||||
userData['username:disableEdit'] = !userData.isAdmin && meta.config['username:disableEdit'];
|
||||
userData['email:disableEdit'] = !userData.isAdmin && meta.config['email:disableEdit'];
|
||||
|
||||
@@ -7,6 +7,11 @@ const db = require('../database');
|
||||
const plugins = require('../plugins');
|
||||
const utils = require('../utils');
|
||||
const translator = require('../translator');
|
||||
const coverPhoto = require('../coverPhoto');
|
||||
|
||||
const relative_path = nconf.get('relative_path');
|
||||
|
||||
const prependRelativePath = url => url.startsWith('http') ? url : relative_path + url;
|
||||
|
||||
const intFields = [
|
||||
'createtime', 'memberCount', 'hidden', 'system', 'private',
|
||||
@@ -81,17 +86,13 @@ function modifyGroup(group, fields) {
|
||||
|
||||
group['cover:thumb:url'] = group['cover:thumb:url'] || group['cover:url'];
|
||||
|
||||
if (group['cover:url']) {
|
||||
group['cover:url'] = group['cover:url'].startsWith('http') ? group['cover:url'] : (nconf.get('relative_path') + group['cover:url']);
|
||||
} else {
|
||||
group['cover:url'] = require('../coverPhoto').getDefaultGroupCover(group.name);
|
||||
}
|
||||
group['cover:url'] = group['cover:url'] ?
|
||||
prependRelativePath(group['cover:url']) :
|
||||
coverPhoto.getDefaultGroupCover(group.name);
|
||||
|
||||
if (group['cover:thumb:url']) {
|
||||
group['cover:thumb:url'] = group['cover:thumb:url'].startsWith('http') ? group['cover:thumb:url'] : (nconf.get('relative_path') + group['cover:thumb:url']);
|
||||
} else {
|
||||
group['cover:thumb:url'] = require('../coverPhoto').getDefaultGroupCover(group.name);
|
||||
}
|
||||
group['cover:thumb:url'] = group['cover:thumb:url'] ?
|
||||
prependRelativePath(group['cover:thumb:url']) :
|
||||
coverPhoto.getDefaultGroupCover(group.name);
|
||||
|
||||
group['cover:position'] = validator.escape(String(group['cover:position'] || '50% 50%'));
|
||||
}
|
||||
|
||||
@@ -9,9 +9,12 @@ const meta = require('../meta');
|
||||
const plugins = require('../plugins');
|
||||
const activitypub = require('../activitypub');
|
||||
const utils = require('../utils');
|
||||
const coverPhoto = require('../coverPhoto');
|
||||
|
||||
const relative_path = nconf.get('relative_path');
|
||||
|
||||
const prependRelativePath = url => url.startsWith('http') ? url : relative_path + url;
|
||||
|
||||
const intFields = [
|
||||
'uid', 'postcount', 'topiccount', 'reputation', 'profileviews',
|
||||
'banned', 'banned:expire', 'email:confirmed', 'joindate', 'lastonline',
|
||||
@@ -257,12 +260,18 @@ module.exports = function (User) {
|
||||
parseGroupTitle(user);
|
||||
}
|
||||
|
||||
if (user.picture && user.picture === user.uploadedpicture) {
|
||||
user.uploadedpicture = user.picture.startsWith('http') ? user.picture : relative_path + user.picture;
|
||||
user.picture = user.uploadedpicture;
|
||||
} else if (user.uploadedpicture) {
|
||||
user.uploadedpicture = user.uploadedpicture.startsWith('http') ? user.uploadedpicture : relative_path + user.uploadedpicture;
|
||||
if (user.uploadedpicture || user.picture) {
|
||||
const source = (user.picture && user.picture === user.uploadedpicture) ? user.picture : user.uploadedpicture;
|
||||
if (source) {
|
||||
user.uploadedpicture = prependRelativePath(source);
|
||||
user.picture = user.uploadedpicture;
|
||||
}
|
||||
}
|
||||
|
||||
user['cover:url'] = user['cover:url'] ?
|
||||
prependRelativePath(user['cover:url']) :
|
||||
coverPhoto.getDefaultProfileCover(user.uid);
|
||||
|
||||
if (meta.config.defaultAvatar && !user.picture) {
|
||||
user.picture = User.getDefaultAvatar();
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ describe('User', () => {
|
||||
await assert.rejects(User.create({
|
||||
username: '-.-', // slug becomes .
|
||||
password: '123456',
|
||||
}), { message: '[[error:invalid-username, -.-]]' });
|
||||
}), { message: '[[error:invalid-username]]' });
|
||||
});
|
||||
|
||||
it('should create user with valid slug (-.-.- => .-.)', async () => {
|
||||
|
||||
Reference in New Issue
Block a user