Merge remote-tracking branch 'origin/master' into develop

v1.18.x
Julian Lam 8 years ago
commit 3861b2dd80

1
.gitignore vendored

@ -36,6 +36,7 @@ pidfile
/public/acp.min.js.map /public/acp.min.js.map
/public/installer.css /public/installer.css
/public/installer.min.js /public/installer.min.js
/public/logo.png
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
*.iml *.iml

@ -61,5 +61,6 @@
"new-group.group_name": "Group Name:", "new-group.group_name": "Group Name:",
"upload-group-cover": "Upload group cover", "upload-group-cover": "Upload group cover",
"bulk-invite-instructions": "Enter a list of comma separated usernames to invite to this group", "bulk-invite-instructions": "Enter a list of comma separated usernames to invite to this group",
"bulk-invite": "Bulk Invite" "bulk-invite": "Bulk Invite",
"remove_group_cover_confirm": "Are you sure you want to remove the cover picture?"
} }

@ -68,6 +68,7 @@
"upload_a_picture": "Upload a picture", "upload_a_picture": "Upload a picture",
"remove_uploaded_picture" : "Remove Uploaded Picture", "remove_uploaded_picture" : "Remove Uploaded Picture",
"upload_cover_picture": "Upload cover picture", "upload_cover_picture": "Upload cover picture",
"remove_cover_picture_confirm": "Are you sure you want to remove the cover picture?",
"settings": "Settings", "settings": "Settings",
"show_email": "Show My Email", "show_email": "Show My Email",

@ -87,7 +87,7 @@
url = url url = url
.replace(/\/\d+$/, '') .replace(/\/\d+$/, '')
.split('/').slice(0, 3).join('/') .split('/').slice(0, 3).join('/')
.split('?')[0].replace(/(\/+$)|(^\/+)/, ''); .split(/[?#]/)[0].replace(/(\/+$)|(^\/+)/, '');
// If index is requested, load the dashboard // If index is requested, load the dashboard
if (url === 'admin') { if (url === 'admin') {

@ -178,6 +178,12 @@ define('forum/account/header', [
} }
function removeCover() { function removeCover() {
translator.translate('[[user:remove_cover_picture_confirm]]', function (translated) {
bootbox.confirm(translated, function (confirm) {
if (!confirm) {
return;
}
socket.emit('user.removeCover', { socket.emit('user.removeCover', {
uid: ajaxify.data.uid uid: ajaxify.data.uid
}, function (err) { }, function (err) {
@ -187,6 +193,8 @@ define('forum/account/header', [
app.alertError(err.message); app.alertError(err.message);
} }
}); });
});
});
} }
return AccountHeader; return AccountHeader;

@ -7,8 +7,9 @@ define('forum/groups/details', [
'components', 'components',
'coverPhoto', 'coverPhoto',
'uploader', 'uploader',
'translator',
'vendor/colorpicker/colorpicker' 'vendor/colorpicker/colorpicker'
], function (memberList, iconSelect, components, coverPhoto, uploader) { ], function (memberList, iconSelect, components, coverPhoto, uploader, translator) {
var Details = {}; var Details = {};
var groupName; var groupName;
@ -265,6 +266,12 @@ define('forum/groups/details', [
} }
function removeCover() { function removeCover() {
translator.translate('[[groups:remove_group_cover_confirm]]', function (translated) {
bootbox.confirm(translated, function (confirm) {
if (!confirm) {
return;
}
socket.emit('groups.cover.remove', { socket.emit('groups.cover.remove', {
groupName: ajaxify.data.group.name groupName: ajaxify.data.group.name
}, function (err) { }, function (err) {
@ -274,6 +281,8 @@ define('forum/groups/details', [
app.alertError(err.message); app.alertError(err.message);
} }
}); });
});
});
} }
return Details; return Details;

@ -8,8 +8,9 @@ define('chat', [
'sounds', 'sounds',
'forum/chats', 'forum/chats',
'forum/chats/messages', 'forum/chats/messages',
'translator' 'translator',
], function (components, taskbar, S, sounds, Chats, ChatsMessages, translator) { 'scrollStop'
], function (components, taskbar, S, sounds, Chats, ChatsMessages, translator, scrollStop) {
var module = {}; var module = {};
var newMessage = false; var newMessage = false;
@ -197,6 +198,8 @@ define('chat', [
}); });
}); });
scrollStop.apply(chatModal.find('[component="chat/messages"]'));
chatModal.find('#chat-close-btn').on('click', function () { chatModal.find('#chat-close-btn').on('click', function () {
module.close(chatModal); module.close(chatModal);
}); });

@ -21,7 +21,7 @@ define('scrollStop', function () {
if ( if (
(e.originalEvent.deltaY < 0 && scrollTop === 0) || // scroll up (e.originalEvent.deltaY < 0 && scrollTop === 0) || // scroll up
(e.originalEvent.deltaY > 0 && (elementHeight + scrollTop) > scrollHeight) // scroll down (e.originalEvent.deltaY > 0 && (elementHeight + scrollTop) >= scrollHeight) // scroll down
) { ) {
return false; return false;
} }

@ -319,7 +319,7 @@ authenticationController.onSuccessfulLogin = function (req, uid, callback) {
user.auth.addSession(uid, req.sessionID, next); user.auth.addSession(uid, req.sessionID, next);
}, },
function (next) { function (next) {
db.setObjectField('uid:' + uid + 'sessionUUID:sessionId', uuid, req.sessionID, next); db.setObjectField('uid:' + uid + ':sessionUUID:sessionId', uuid, req.sessionID, next);
}, },
function (next) { function (next) {
user.updateLastOnlineTime(uid, next); user.updateLastOnlineTime(uid, next);

@ -116,7 +116,7 @@ module.exports = function (Groups) {
} }
Groups.removeCover = function (data, callback) { Groups.removeCover = function (data, callback) {
db.deleteObjectFields('group:' + data.groupName, ['cover:url', 'cover:thumb:url'], callback); db.deleteObjectFields('group:' + data.groupName, ['cover:url', 'cover:thumb:url', 'cover:position'], callback);
}; };
}; };

@ -2,7 +2,6 @@
var async = require('async'); var async = require('async');
var winston = require('winston');
var S = require('string'); var S = require('string');
var db = require('./database'); var db = require('./database');
@ -10,11 +9,10 @@ var user = require('./user');
var plugins = require('./plugins'); var plugins = require('./plugins');
var meta = require('./meta'); var meta = require('./meta');
var utils = require('../public/src/utils'); var utils = require('../public/src/utils');
var notifications = require('./notifications');
var userNotifications = require('./user/notifications');
(function (Messaging) { var Messaging = module.exports;
require('./messaging/data')(Messaging);
require('./messaging/create')(Messaging); require('./messaging/create')(Messaging);
require('./messaging/delete')(Messaging); require('./messaging/delete')(Messaging);
require('./messaging/edit')(Messaging); require('./messaging/edit')(Messaging);
@ -22,23 +20,6 @@ var userNotifications = require('./user/notifications');
require('./messaging/unread')(Messaging); require('./messaging/unread')(Messaging);
require('./messaging/notifications')(Messaging); require('./messaging/notifications')(Messaging);
Messaging.getMessageField = function (mid, field, callback) {
Messaging.getMessageFields(mid, [field], function (err, fields) {
callback(err, fields ? fields[field] : null);
});
};
Messaging.getMessageFields = function (mid, fields, callback) {
db.getObjectFields('message:' + mid, fields, callback);
};
Messaging.setMessageField = function (mid, field, content, callback) {
db.setObjectField('message:' + mid, field, content, callback);
};
Messaging.setMessageFields = function (mid, data, callback) {
db.setObject('message:' + mid, data, callback);
};
Messaging.getMessages = function (params, callback) { Messaging.getMessages = function (params, callback) {
var uid = params.uid; var uid = params.uid;
@ -50,7 +31,7 @@ var userNotifications = require('./user/notifications');
var indices = {}; var indices = {};
async.waterfall([ async.waterfall([
function (next) { function (next) {
canGetMessages(params.callerUid, params.uid, next); canGet('filter:messaging.canGetMessages', params.callerUid, params.uid, next);
}, },
function (canGet, next) { function (canGet, next) {
if (!canGet) { if (!canGet) {
@ -80,8 +61,8 @@ var userNotifications = require('./user/notifications');
], callback); ], callback);
}; };
function canGetMessages(callerUid, uid, callback) { function canGet(hook, callerUid, uid, callback) {
plugins.fireHook('filter:messaging.canGetMessages', { plugins.fireHook(hook, {
callerUid: callerUid, callerUid: callerUid,
uid: uid, uid: uid,
canGet: parseInt(callerUid, 10) === parseInt(uid, 10) canGet: parseInt(callerUid, 10) === parseInt(uid, 10)
@ -90,113 +71,6 @@ var userNotifications = require('./user/notifications');
}); });
} }
Messaging.getMessagesData = function (mids, uid, roomId, isNew, callback) {
var keys = mids.map(function (mid) {
return 'message:' + mid;
});
var messages;
async.waterfall([
function (next) {
db.getObjects(keys, next);
},
function (_messages, next) {
messages = _messages.map(function (msg, idx) {
if (msg) {
msg.messageId = parseInt(mids[idx], 10);
}
return msg;
}).filter(Boolean);
var uids = messages.map(function (msg) {
return msg && msg.fromuid;
});
user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture', 'status'], next);
},
function (users, next) {
messages.forEach(function (message, index) {
message.fromUser = users[index];
var self = parseInt(message.fromuid, 10) === parseInt(uid, 10);
message.self = self ? 1 : 0;
message.timestampISO = utils.toISOString(message.timestamp);
message.newSet = false;
message.roomId = String(message.roomId || roomId);
if (message.hasOwnProperty('edited')) {
message.editedISO = new Date(parseInt(message.edited, 10)).toISOString();
}
});
async.map(messages, function (message, next) {
Messaging.parse(message.content, message.fromuid, uid, roomId, isNew, function (err, result) {
if (err) {
return next(err);
}
message.content = result;
message.cleanedContent = S(result).stripTags().decodeHTMLEntities().s;
next(null, message);
});
}, next);
},
function (messages, next) {
if (messages.length > 1) {
// Add a spacer in between messages with time gaps between them
messages = messages.map(function (message, index) {
// Compare timestamps with the previous message, and check if a spacer needs to be added
if (index > 0 && parseInt(message.timestamp, 10) > parseInt(messages[index - 1].timestamp, 10) + (1000 * 60 * 5)) {
// If it's been 5 minutes, this is a new set of messages
message.newSet = true;
} else if (index > 0 && message.fromuid !== messages[index - 1].fromuid) {
// If the previous message was from the other person, this is also a new set
message.newSet = true;
}
return message;
});
next(undefined, messages);
} else if (messages.length === 1) {
// For single messages, we don't know the context, so look up the previous message and compare
var key = 'uid:' + uid + ':chat:room:' + roomId + ':mids';
async.waterfall([
async.apply(db.sortedSetRank, key, messages[0].messageId),
function (index, next) {
// Continue only if this isn't the first message in sorted set
if (index > 0) {
db.getSortedSetRange(key, index - 1, index - 1, next);
} else {
messages[0].newSet = true;
return next(undefined, messages);
}
},
function (mid, next) {
Messaging.getMessageFields(mid, ['fromuid', 'timestamp'], next);
}
], function (err, fields) {
if (err) {
return next(err);
}
if (
(parseInt(messages[0].timestamp, 10) > parseInt(fields.timestamp, 10) + (1000 * 60 * 5)) ||
(parseInt(messages[0].fromuid, 10) !== parseInt(fields.fromuid, 10))
) {
// If it's been 5 minutes, this is a new set of messages
messages[0].newSet = true;
}
next(undefined, messages);
});
} else {
next(null, []);
}
}
], callback);
};
Messaging.parse = function (message, fromuid, uid, roomId, isNew, callback) { Messaging.parse = function (message, fromuid, uid, roomId, isNew, callback) {
plugins.fireHook('filter:parse.raw', message, function (err, parsed) { plugins.fireHook('filter:parse.raw', message, function (err, parsed) {
if (err) { if (err) {
@ -240,7 +114,7 @@ var userNotifications = require('./user/notifications');
Messaging.getRecentChats = function (callerUid, uid, start, stop, callback) { Messaging.getRecentChats = function (callerUid, uid, start, stop, callback) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
canGetRecentChats(callerUid, uid, next); canGet('filter:messaging.canGetRecentChats', callerUid, uid, next);
}, },
function (canGet, next) { function (canGet, next) {
if (!canGet) { if (!canGet) {
@ -310,16 +184,6 @@ var userNotifications = require('./user/notifications');
}).join(', '); }).join(', ');
}; };
function canGetRecentChats(callerUid, uid, callback) {
plugins.fireHook('filter:messaging.canGetRecentChats', {
callerUid: callerUid,
uid: uid,
canGet: parseInt(callerUid, 10) === parseInt(uid, 10)
}, function (err, data) {
callback(err, data ? data.canGet : false);
});
}
Messaging.getTeaser = function (uid, roomId, callback) { Messaging.getTeaser = function (uid, roomId, callback) {
var teaser; var teaser;
async.waterfall([ async.waterfall([
@ -475,6 +339,3 @@ var userNotifications = require('./user/notifications');
} }
], callback); ], callback);
}; };
}(exports));

@ -0,0 +1,136 @@
'use strict';
var async = require('async');
var S = require('string');
var db = require('../database');
var user = require('../user');
var utils = require('../../public/src/utils');
module.exports = function (Messaging) {
Messaging.getMessageField = function (mid, field, callback) {
Messaging.getMessageFields(mid, [field], function (err, fields) {
callback(err, fields ? fields[field] : null);
});
};
Messaging.getMessageFields = function (mid, fields, callback) {
db.getObjectFields('message:' + mid, fields, callback);
};
Messaging.setMessageField = function (mid, field, content, callback) {
db.setObjectField('message:' + mid, field, content, callback);
};
Messaging.setMessageFields = function (mid, data, callback) {
db.setObject('message:' + mid, data, callback);
};
Messaging.getMessagesData = function (mids, uid, roomId, isNew, callback) {
var messages;
async.waterfall([
function (next) {
var keys = mids.map(function (mid) {
return 'message:' + mid;
});
db.getObjects(keys, next);
},
function (_messages, next) {
messages = _messages.map(function (msg, idx) {
if (msg) {
msg.messageId = parseInt(mids[idx], 10);
}
return msg;
}).filter(Boolean);
var uids = messages.map(function (msg) {
return msg && msg.fromuid;
});
user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture', 'status'], next);
},
function (users, next) {
messages.forEach(function (message, index) {
message.fromUser = users[index];
var self = parseInt(message.fromuid, 10) === parseInt(uid, 10);
message.self = self ? 1 : 0;
message.timestampISO = utils.toISOString(message.timestamp);
message.newSet = false;
message.roomId = String(message.roomId || roomId);
if (message.hasOwnProperty('edited')) {
message.editedISO = new Date(parseInt(message.edited, 10)).toISOString();
}
});
async.map(messages, function (message, next) {
Messaging.parse(message.content, message.fromuid, uid, roomId, isNew, function (err, result) {
if (err) {
return next(err);
}
message.content = result;
message.cleanedContent = S(result).stripTags().decodeHTMLEntities().s;
next(null, message);
});
}, next);
},
function (messages, next) {
if (messages.length > 1) {
// Add a spacer in between messages with time gaps between them
messages = messages.map(function (message, index) {
// Compare timestamps with the previous message, and check if a spacer needs to be added
if (index > 0 && parseInt(message.timestamp, 10) > parseInt(messages[index - 1].timestamp, 10) + (1000 * 60 * 5)) {
// If it's been 5 minutes, this is a new set of messages
message.newSet = true;
} else if (index > 0 && message.fromuid !== messages[index - 1].fromuid) {
// If the previous message was from the other person, this is also a new set
message.newSet = true;
}
return message;
});
next(undefined, messages);
} else if (messages.length === 1) {
// For single messages, we don't know the context, so look up the previous message and compare
var key = 'uid:' + uid + ':chat:room:' + roomId + ':mids';
async.waterfall([
async.apply(db.sortedSetRank, key, messages[0].messageId),
function (index, next) {
// Continue only if this isn't the first message in sorted set
if (index > 0) {
db.getSortedSetRange(key, index - 1, index - 1, next);
} else {
messages[0].newSet = true;
return next(undefined, messages);
}
},
function (mid, next) {
Messaging.getMessageFields(mid, ['fromuid', 'timestamp'], next);
}
], function (err, fields) {
if (err) {
return next(err);
}
if (
(parseInt(messages[0].timestamp, 10) > parseInt(fields.timestamp, 10) + (1000 * 60 * 5)) ||
(parseInt(messages[0].fromuid, 10) !== parseInt(fields.fromuid, 10))
) {
// If it's been 5 minutes, this is a new set of messages
messages[0].newSet = true;
}
next(undefined, messages);
});
} else {
next(null, []);
}
}
], callback);
};
};

@ -195,19 +195,19 @@ module.exports = function (Plugins) {
} }
function mapClientSideScripts(pluginData, callback) { function mapClientSideScripts(pluginData, callback) {
function mapScripts(scripts, globalScripts) { function mapScripts(scripts, param) {
if (Array.isArray(scripts) && scripts.length) { if (Array.isArray(scripts) && scripts.length) {
if (global.env === 'development') { if (global.env === 'development') {
winston.verbose('[plugins] Found ' + scripts.length + ' js file(s) for plugin ' + pluginData.id); winston.verbose('[plugins] Found ' + scripts.length + ' js file(s) for plugin ' + pluginData.id);
} }
globalScripts = globalScripts.concat(scripts.map(function (file) { Plugins[param] = Plugins[param].concat(scripts.map(function (file) {
return resolveModulePath(path.join(__dirname, '../../node_modules/', pluginData.id, file), file); return resolveModulePath(path.join(__dirname, '../../node_modules/', pluginData.id, file), file);
})).filter(Boolean); })).filter(Boolean);
} }
} }
mapScripts(pluginData.scripts, Plugins.clientScripts); mapScripts(pluginData.scripts, 'clientScripts');
mapScripts(pluginData.acpScripts, Plugins.acpScripts); mapScripts(pluginData.acpScripts, 'acpScripts');
callback(); callback();
} }

@ -23,7 +23,7 @@ module.exports = function (SocketUser) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
user.isAdminOrSelf(socket.uid, data.uid, next); user.isAdminOrGlobalModOrSelf(socket.uid, data.uid, next);
}, },
function (next) { function (next) {
switch(type) { switch(type) {

@ -277,6 +277,18 @@ var meta = require('./meta');
}); });
}; };
User.isAdminOrGlobalModOrSelf = function (callerUid, uid, callback) {
if (parseInt(callerUid, 10) === parseInt(uid, 10)) {
return callback();
}
User.isAdminOrGlobalMod(callerUid, function (err, isAdminOrGlobalMod) {
if (err || !isAdminOrGlobalMod) {
return callback(err || new Error('[[error:no-privileges]]'));
}
callback();
});
};
User.getAdminsandGlobalMods = function (callback) { User.getAdminsandGlobalMods = function (callback) {
async.parallel({ async.parallel({
admins: async.apply(groups.getMembers, 'administrators', 0, -1), admins: async.apply(groups.getMembers, 'administrators', 0, -1),

@ -222,6 +222,6 @@ module.exports = function (User) {
}; };
User.removeCoverPicture = function (data, callback) { User.removeCoverPicture = function (data, callback) {
db.deleteObjectField('user:' + data.uid, 'cover:url', callback); db.deleteObjectFields('user:' + data.uid, ['cover:url', 'cover:position'], callback);
}; };
}; };

@ -120,11 +120,16 @@ describe('authentication', function () {
assert(body); assert(body);
assert.equal(body.username, 'regular'); assert.equal(body.username, 'regular');
assert.equal(body.email, 'regular@nodebb.org'); assert.equal(body.email, 'regular@nodebb.org');
db.getObject('uid:' + regularUid + ':sessionUUID:sessionId', function (err, sessions) {
assert.ifError(err);
assert(sessions);
assert(Object.keys(sessions).length > 0);
done(); done();
}); });
}); });
}); });
}); });
});
it('should revoke all sessions', function (done) { it('should revoke all sessions', function (done) {
var socketAdmin = require('../src/socket.io/admin'); var socketAdmin = require('../src/socket.io/admin');

@ -13,6 +13,8 @@ var Meta = require('../src/meta');
var Password = require('../src/password'); var Password = require('../src/password');
var groups = require('../src/groups'); var groups = require('../src/groups');
var helpers = require('./helpers'); var helpers = require('./helpers');
var meta = require('../src/meta');
var plugins = require('../src/plugins');
describe('User', function () { describe('User', function () {
var userData; var userData;
@ -507,6 +509,106 @@ describe('User', function () {
}); });
}); });
it('should return error if profile image uploads disabled', function (done) {
meta.config.allowProfileImageUploads = 0;
var path = require('path');
var picture = {
path: path.join(nconf.get('base_dir'), 'public', 'logo.png'),
size: 7189,
name: 'logo.png'
};
User.uploadPicture(uid, picture, function (err, uploadedPicture) {
assert.equal(err.message, '[[error:profile-image-uploads-disabled]]');
done();
});
});
it('should return error if profile image is too big', function (done) {
meta.config.allowProfileImageUploads = 1;
var path = require('path');
var picture = {
path: path.join(nconf.get('base_dir'), 'public', 'logo.png'),
size: 265000,
name: 'logo.png'
};
User.uploadPicture(uid, picture, function (err, uploadedPicture) {
assert.equal(err.message, '[[error:file-too-big, 256]]');
done();
});
});
it('should return error if profile image file has no extension', function (done) {
var path = require('path');
var picture = {
path: path.join(nconf.get('base_dir'), 'public', 'logo.png'),
size: 7189,
name: 'logo'
};
User.uploadPicture(uid, picture, function (err, uploadedPicture) {
assert.equal(err.message, '[[error:invalid-image-extension]]');
done();
});
});
it('should return error if no plugins listening for filter:uploadImage when uploading from url', function (done) {
var url = nconf.get('url') + '/logo.png';
User.uploadFromUrl(uid, url, function (err, uploadedPicture) {
assert.equal(err.message, '[[error:no-plugin]]');
done();
});
});
it('should return error if the extension is invalid when uploading from url', function (done) {
var url = nconf.get('url') + '/favicon.ico';
function filterMethod(data, callback) {
data.foo += 5;
callback(null, data);
}
plugins.registerHook('test-plugin', {hook: 'filter:uploadImage', method: filterMethod});
User.uploadFromUrl(uid, url, function (err, uploadedPicture) {
assert.equal(err.message, '[[error:invalid-image-extension]]');
done();
});
});
it('should return error if the file is too big when uploading from url', function (done) {
var url = nconf.get('url') + '/logo.png';
meta.config.maximumProfileImageSize = 1;
function filterMethod(data, callback) {
data.foo += 5;
callback(null, data);
}
plugins.registerHook('test-plugin', {hook: 'filter:uploadImage', method: filterMethod});
User.uploadFromUrl(uid, url, function (err, uploadedPicture) {
assert.equal(err.message, '[[error:file-too-big, ' + meta.config.maximumProfileImageSize + ']]');
done();
});
});
it('should upload picture when uploading from url', function (done) {
var url = nconf.get('url') + '/logo.png';
meta.config.maximumProfileImageSize = '';
function filterMethod(data, callback) {
data.foo += 5;
callback(null, {url: url});
}
plugins.registerHook('test-plugin', {hook: 'filter:uploadImage', method: filterMethod});
User.uploadFromUrl(uid, url, function (err, uploadedPicture) {
assert.ifError(err);
assert.equal(uploadedPicture.url, url);
done();
});
});
it('should get profile pictures', function (done) { it('should get profile pictures', function (done) {
io.emit('user.getProfilePictures', {uid: uid}, function (err, data) { io.emit('user.getProfilePictures', {uid: uid}, function (err, data) {
assert.ifError(err); assert.ifError(err);

Loading…
Cancel
Save