mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-04 10:29:44 +02:00
Merge remote-tracking branch 'refs/remotes/origin/master' into chat-permission
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
var packageInstall = require('../meta/package-install');
|
||||
var packageInstall = require('./package-install');
|
||||
var dirname = require('./paths').baseDir;
|
||||
|
||||
// check to make sure dependencies are installed
|
||||
@@ -12,12 +12,17 @@ try {
|
||||
} catch (e) {
|
||||
if (e.code === 'ENOENT') {
|
||||
console.warn('package.json not found.');
|
||||
console.log('Populating package.json...\n');
|
||||
console.log('Populating package.json...');
|
||||
|
||||
packageInstall.updatePackageFile();
|
||||
packageInstall.preserveExtraneousPlugins();
|
||||
|
||||
console.log('OK'.green + '\n'.reset);
|
||||
try {
|
||||
require('colors');
|
||||
console.log('OK'.green);
|
||||
} catch (e) {
|
||||
console.log('OK');
|
||||
}
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
@@ -33,7 +38,7 @@ try {
|
||||
console.warn('Dependencies not yet installed.');
|
||||
console.log('Installing them now...\n');
|
||||
|
||||
packageInstall.npmInstallProduction();
|
||||
packageInstall.installAll();
|
||||
|
||||
require('colors');
|
||||
console.log('OK'.green + '\n'.reset);
|
||||
|
||||
@@ -29,15 +29,27 @@ function updatePackageFile() {
|
||||
|
||||
exports.updatePackageFile = updatePackageFile;
|
||||
|
||||
function npmInstallProduction() {
|
||||
process.stdout.write('\n');
|
||||
cproc.execSync('npm i --production', {
|
||||
function installAll() {
|
||||
process.stdout.write(' started\n'.green);
|
||||
|
||||
var prod = global.env !== 'development';
|
||||
var command = 'npm install';
|
||||
try {
|
||||
var packageManager = require('nconf').get('package_manager');
|
||||
if (packageManager === 'yarn') {
|
||||
command = 'yarn';
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
cproc.execSync(command + (prod ? ' --production' : ''), {
|
||||
cwd: path.join(__dirname, '../../'),
|
||||
stdio: [0, 1, 2],
|
||||
});
|
||||
}
|
||||
|
||||
exports.npmInstallProduction = npmInstallProduction;
|
||||
exports.installAll = installAll;
|
||||
|
||||
function preserveExtraneousPlugins() {
|
||||
// Skip if `node_modules/` is not found or inaccessible
|
||||
@@ -7,9 +7,18 @@ var cproc = require('child_process');
|
||||
var semver = require('semver');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var nconf = require('nconf');
|
||||
|
||||
var paths = require('./paths');
|
||||
|
||||
var packageManager = nconf.get('package_manager');
|
||||
var packageManagerExecutable = packageManager === 'yarn' ? 'yarn' : 'npm';
|
||||
var packageManagerInstallArgs = packageManager === 'yarn' ? ['add'] : ['install', '--save'];
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
packageManagerExecutable += '.cmd';
|
||||
}
|
||||
|
||||
var dirname = paths.baseDir;
|
||||
|
||||
function getModuleVersions(modules, callback) {
|
||||
@@ -85,7 +94,7 @@ function getInstalledPlugins(callback) {
|
||||
}
|
||||
|
||||
function getCurrentVersion(callback) {
|
||||
fs.readFile(path.join(dirname, 'package.json'), { encoding: 'utf-8' }, function (err, pkg) {
|
||||
fs.readFile(path.join(dirname, 'install/package.json'), { encoding: 'utf-8' }, function (err, pkg) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -106,8 +115,8 @@ function checkPlugins(standalone, callback) {
|
||||
|
||||
async.waterfall([
|
||||
async.apply(async.parallel, {
|
||||
plugins: async.apply(getInstalledPlugins),
|
||||
version: async.apply(getCurrentVersion),
|
||||
plugins: getInstalledPlugins,
|
||||
version: getCurrentVersion,
|
||||
}),
|
||||
function (payload, next) {
|
||||
var toCheck = Object.keys(payload.plugins);
|
||||
@@ -194,17 +203,16 @@ function upgradePlugins(callback) {
|
||||
|
||||
if (['y', 'Y', 'yes', 'YES'].indexOf(result.upgrade) !== -1) {
|
||||
console.log('\nUpgrading packages...');
|
||||
var args = ['i'];
|
||||
found.forEach(function (suggestObj) {
|
||||
args.push(suggestObj.name + '@' + suggestObj.suggested);
|
||||
});
|
||||
var args = packageManagerInstallArgs.concat(found.map(function (suggestObj) {
|
||||
return suggestObj.name + '@' + suggestObj.suggested;
|
||||
}));
|
||||
|
||||
cproc.execFile((process.platform === 'win32') ? 'npm.cmd' : 'npm', args, { stdio: 'ignore' }, function (err) {
|
||||
callback(err, true);
|
||||
cproc.execFile(packageManagerExecutable, args, { stdio: 'ignore' }, function (err) {
|
||||
callback(err, false);
|
||||
});
|
||||
} else {
|
||||
console.log('Package upgrades skipped'.yellow + '. Check for upgrades at any time by running "'.reset + './nodebb upgrade -p'.green + '".'.reset);
|
||||
callback(null, true);
|
||||
callback();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
var async = require('async');
|
||||
var nconf = require('nconf');
|
||||
|
||||
var packageInstall = require('../meta/package-install');
|
||||
var packageInstall = require('./package-install');
|
||||
var upgrade = require('../upgrade');
|
||||
var build = require('../meta/build');
|
||||
var db = require('../database');
|
||||
@@ -16,13 +16,14 @@ var steps = {
|
||||
handler: function (next) {
|
||||
packageInstall.updatePackageFile();
|
||||
packageInstall.preserveExtraneousPlugins();
|
||||
process.stdout.write(' OK\n'.green);
|
||||
next();
|
||||
},
|
||||
},
|
||||
install: {
|
||||
message: 'Bringing base dependencies up to date...',
|
||||
handler: function (next) {
|
||||
packageInstall.npmInstallProduction();
|
||||
packageInstall.installAll();
|
||||
next();
|
||||
},
|
||||
},
|
||||
@@ -54,11 +55,8 @@ function runSteps(tasks) {
|
||||
tasks = tasks.map(function (key, i) {
|
||||
return function (next) {
|
||||
process.stdout.write('\n' + ((i + 1) + '. ').bold + steps[key].message.yellow);
|
||||
return steps[key].handler(function (err, inhibitOk) {
|
||||
return steps[key].handler(function (err) {
|
||||
if (err) { return next(err); }
|
||||
if (!inhibitOk) {
|
||||
process.stdout.write(' OK'.green + '\n'.reset);
|
||||
}
|
||||
next();
|
||||
});
|
||||
};
|
||||
|
||||
@@ -108,6 +108,7 @@ module.exports = function (db, module) {
|
||||
if (!data) {
|
||||
return callback(null, null);
|
||||
}
|
||||
delete data.expireAt;
|
||||
var keys = Object.keys(data);
|
||||
if (keys.length === 4 && data.hasOwnProperty('_key') && data.hasOwnProperty('score') && data.hasOwnProperty('value')) {
|
||||
return callback(null, 'zset');
|
||||
|
||||
@@ -212,7 +212,7 @@ function build(targets, callback) {
|
||||
}
|
||||
|
||||
winston.info('[build] Asset compilation successful. Completed in ' + totalTime + 'sec.');
|
||||
callback(null, true);
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ var jsesc = require('jsesc');
|
||||
|
||||
var db = require('../database');
|
||||
var user = require('../user');
|
||||
var topics = require('../topics');
|
||||
var messaging = require('../messaging');
|
||||
var meta = require('../meta');
|
||||
var plugins = require('../plugins');
|
||||
var navigation = require('../navigation');
|
||||
@@ -113,10 +115,16 @@ module.exports = function (middleware) {
|
||||
next(null, translated);
|
||||
});
|
||||
},
|
||||
navigation: async.apply(navigation.get),
|
||||
navigation: navigation.get,
|
||||
tags: async.apply(meta.tags.parse, req, data, res.locals.metaTags, res.locals.linkTags),
|
||||
banned: async.apply(user.isBanned, req.uid),
|
||||
banReason: async.apply(user.getBannedReason, req.uid),
|
||||
|
||||
unreadTopicCount: async.apply(topics.getTotalUnread, req.uid),
|
||||
unreadNewTopicCount: async.apply(topics.getTotalUnread, req.uid, 'new'),
|
||||
unreadWatchedTopicCount: async.apply(topics.getTotalUnread, req.uid, 'watched'),
|
||||
unreadChatCount: async.apply(messaging.getUnreadCount, req.uid),
|
||||
unreadNotificationCount: async.apply(user.notifications.getUnreadCount, req.uid),
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -136,8 +144,45 @@ module.exports = function (middleware) {
|
||||
|
||||
setBootswatchCSS(templateValues, res.locals.config);
|
||||
|
||||
var unreadCount = {
|
||||
topic: results.unreadTopicCount || 0,
|
||||
newTopic: results.unreadNewTopicCount || 0,
|
||||
watchedTopic: results.unreadWatchedTopicCount || 0,
|
||||
chat: results.unreadChatCount || 0,
|
||||
notification: results.unreadNotificationCount || 0,
|
||||
};
|
||||
Object.keys(unreadCount).forEach(function (key) {
|
||||
if (unreadCount[key] > 99) {
|
||||
unreadCount[key] = '99+';
|
||||
}
|
||||
});
|
||||
|
||||
results.navigation = results.navigation.map(function (item) {
|
||||
if (item.originalRoute === '/unread' && results.unreadTopicCount > 0) {
|
||||
return Object.assign({}, item, {
|
||||
content: unreadCount.topic,
|
||||
iconClass: item.iconClass + ' unread-count',
|
||||
});
|
||||
}
|
||||
if (item.originalRoute === '/unread/new' && results.unreadNewTopicCount > 0) {
|
||||
return Object.assign({}, item, {
|
||||
content: unreadCount.newTopic,
|
||||
iconClass: item.iconClass + ' unread-count',
|
||||
});
|
||||
}
|
||||
if (item.originalRoute === '/unread/watched' && results.unreadWatchedTopicCount > 0) {
|
||||
return Object.assign({}, item, {
|
||||
content: unreadCount.watchedTopic,
|
||||
iconClass: item.iconClass + ' unread-count',
|
||||
});
|
||||
}
|
||||
|
||||
return item;
|
||||
});
|
||||
|
||||
templateValues.browserTitle = results.browserTitle;
|
||||
templateValues.navigation = results.navigation;
|
||||
templateValues.unreadCount = unreadCount;
|
||||
templateValues.metaTags = results.tags.meta;
|
||||
templateValues.linkTags = results.tags.link;
|
||||
templateValues.isAdmin = results.user.isAdmin;
|
||||
|
||||
@@ -19,15 +19,16 @@ navigation.get = function (callback) {
|
||||
data = data.filter(function (item) {
|
||||
return item && item.enabled;
|
||||
}).map(function (item) {
|
||||
item.originalRoute = item.route;
|
||||
|
||||
if (!item.route.startsWith('http')) {
|
||||
item.route = nconf.get('relative_path') + item.route;
|
||||
}
|
||||
|
||||
for (var i in item) {
|
||||
if (item.hasOwnProperty(i)) {
|
||||
item[i] = translator.unescape(item[i]);
|
||||
}
|
||||
}
|
||||
Object.keys(item).forEach(function (key) {
|
||||
item[key] = translator.unescape(item[key]);
|
||||
});
|
||||
|
||||
return item;
|
||||
});
|
||||
|
||||
|
||||
@@ -220,7 +220,7 @@ function pushToUids(uids, notification, callback) {
|
||||
async.eachLimit(uids, 3, function (uid, next) {
|
||||
emailer.send('notification', uid, {
|
||||
path: notification.path,
|
||||
subject: '[[notifications:new_notification_from, ' + meta.config.title + ']]',
|
||||
subject: notification.subject || '[[notifications:new_notification_from, ' + meta.config.title + ']]',
|
||||
intro: utils.stripHTMLTags(notification.bodyShort),
|
||||
body: utils.stripHTMLTags(notification.bodyLong || ''),
|
||||
showUnsubscribe: true,
|
||||
|
||||
@@ -13,6 +13,23 @@ var meta = require('../meta');
|
||||
var pubsub = require('../pubsub');
|
||||
var events = require('../events');
|
||||
|
||||
var packageManager = nconf.get('package_manager') === 'yarn' ? 'yarn' : 'npm';
|
||||
var packageManagerExecutable = packageManager;
|
||||
var packageManagerCommands = {
|
||||
yarn: {
|
||||
install: 'add',
|
||||
uninstall: 'remove',
|
||||
},
|
||||
npm: {
|
||||
install: 'install',
|
||||
uninstall: 'uninstall',
|
||||
},
|
||||
};
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
packageManagerExecutable += '.cmd';
|
||||
}
|
||||
|
||||
module.exports = function (Plugins) {
|
||||
if (nconf.get('isPrimary') === 'true') {
|
||||
pubsub.on('plugins:toggleInstall', function (data) {
|
||||
@@ -95,7 +112,7 @@ module.exports = function (Plugins) {
|
||||
setImmediate(next);
|
||||
},
|
||||
function (next) {
|
||||
runNpmCommand(type, id, version || 'latest', next);
|
||||
runPackageManagerCommand(type, id, version || 'latest', next);
|
||||
},
|
||||
function (next) {
|
||||
Plugins.get(id, next);
|
||||
@@ -107,8 +124,12 @@ module.exports = function (Plugins) {
|
||||
], callback);
|
||||
}
|
||||
|
||||
function runNpmCommand(command, pkgName, version, callback) {
|
||||
cproc.execFile((process.platform === 'win32') ? 'npm.cmd' : 'npm', [command, pkgName + (command === 'install' ? '@' + version : ''), '--save'], function (err, stdout) {
|
||||
function runPackageManagerCommand(command, pkgName, version, callback) {
|
||||
cproc.execFile(packageManagerExecutable, [
|
||||
packageManagerCommands[packageManager][command],
|
||||
pkgName + (command === 'install' ? '@' + version : ''),
|
||||
'--save',
|
||||
], function (err, stdout) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -125,7 +146,7 @@ module.exports = function (Plugins) {
|
||||
|
||||
function upgrade(id, version, callback) {
|
||||
async.waterfall([
|
||||
async.apply(runNpmCommand, 'install', id, version || 'latest'),
|
||||
async.apply(runPackageManagerCommand, 'install', id, version || 'latest'),
|
||||
function (next) {
|
||||
Plugins.isActive(id, next);
|
||||
},
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var winston = require('winston');
|
||||
|
||||
var user = require('../../user');
|
||||
var meta = require('../../meta');
|
||||
@@ -112,7 +113,12 @@ module.exports = function (SocketUser) {
|
||||
reason: reason,
|
||||
};
|
||||
|
||||
emailer.send('banned', uid, data, next);
|
||||
emailer.send('banned', uid, data, function (err) {
|
||||
if (err) {
|
||||
winston.error('[emailer.send] ' + err.message);
|
||||
}
|
||||
next();
|
||||
});
|
||||
},
|
||||
function (next) {
|
||||
user.ban(uid, until, reason, next);
|
||||
|
||||
@@ -9,6 +9,7 @@ var notifications = require('../notifications');
|
||||
var privileges = require('../privileges');
|
||||
var plugins = require('../plugins');
|
||||
var utils = require('../utils');
|
||||
var meta = require('../meta');
|
||||
|
||||
module.exports = function (Topics) {
|
||||
Topics.toggleFollow = function (tid, uid, callback) {
|
||||
@@ -219,6 +220,7 @@ module.exports = function (Topics) {
|
||||
|
||||
notifications.create({
|
||||
type: 'new-reply',
|
||||
subject: '[' + (meta.config.title || 'NodeBB') + '] ' + title,
|
||||
bodyShort: '[[notifications:user_posted_to, ' + postData.user.username + ', ' + titleEscaped + ']]',
|
||||
bodyLong: postData.content,
|
||||
pid: postData.pid,
|
||||
|
||||
@@ -205,7 +205,7 @@ Upgrade.incrementProgress = function (value) {
|
||||
if (this.total) {
|
||||
percentage = Math.floor((this.current / this.total) * 100) + '%';
|
||||
filled = Math.floor((this.current / this.total) * 15);
|
||||
unfilled = Math.min(0, 15 - filled);
|
||||
unfilled = Math.max(0, 15 - filled);
|
||||
}
|
||||
|
||||
readline.cursorTo(process.stdout, 0);
|
||||
|
||||
@@ -31,7 +31,7 @@ widgets.render = function (uid, options, callback) {
|
||||
var returnData = {};
|
||||
|
||||
async.each(locations, function (location, done) {
|
||||
widgetsByLocation[location] = (data.global[location] || []).concat(data[options.template][location] || []);
|
||||
widgetsByLocation[location] = (data[options.template][location] || []).concat(data.global[location] || []);
|
||||
|
||||
if (!widgetsByLocation[location].length) {
|
||||
return done(null, { location: location, widgets: [] });
|
||||
|
||||
Reference in New Issue
Block a user