Merge remote-tracking branch 'origin/master' into acp-privileges-redux

This commit is contained in:
Julian Lam
2020-06-03 14:00:42 -04:00
30 changed files with 574 additions and 538 deletions

View File

@@ -79,7 +79,7 @@
"mousetrap": "^1.6.5",
"@nodebb/mubsub": "^1.6.0",
"nconf": "^0.10.0",
"nodebb-plugin-composer-default": "6.3.33",
"nodebb-plugin-composer-default": "6.3.34",
"nodebb-plugin-dbsearch": "4.0.7",
"nodebb-plugin-emoji": "^3.3.0",
"nodebb-plugin-emoji-android": "2.0.0",
@@ -89,9 +89,9 @@
"nodebb-plugin-spam-be-gone": "0.7.1",
"nodebb-rewards-essentials": "0.1.3",
"nodebb-theme-lavender": "5.0.11",
"nodebb-theme-persona": "10.1.43",
"nodebb-theme-persona": "10.1.44",
"nodebb-theme-slick": "1.2.29",
"nodebb-theme-vanilla": "11.1.18",
"nodebb-theme-vanilla": "11.1.19",
"nodebb-widget-essentials": "4.1.0",
"nodemailer": "^6.4.6",
"passport": "^0.4.1",
@@ -143,7 +143,7 @@
"grunt-contrib-watch": "1.1.0",
"husky": "4.2.5",
"jsdom": "16.2.2",
"lint-staged": "10.2.7",
"lint-staged": "10.2.8",
"mocha": "7.2.0",
"mocha-lcov-reporter": "1.3.0",
"nyc": "15.0.1",

View File

@@ -87,22 +87,22 @@ Loader.addWorkerEvents = function (worker) {
worker.on('message', function (message) {
if (message && typeof message === 'object' && message.action) {
switch (message.action) {
case 'restart':
console.log('[cluster] Restarting...');
Loader.restart();
break;
case 'pubsub':
workers.forEach(function (w) {
w.send(message);
});
break;
case 'socket.io':
workers.forEach(function (w) {
if (w !== worker) {
case 'restart':
console.log('[cluster] Restarting...');
Loader.restart();
break;
case 'pubsub':
workers.forEach(function (w) {
w.send(message);
}
});
break;
});
break;
case 'socket.io':
workers.forEach(function (w) {
if (w !== worker) {
w.send(message);
}
});
break;
}
}
});

View File

@@ -32,6 +32,9 @@
"view-profile": "View Profile",
"start-new-chat": "Start New Chat",
"go-to-target": "View Flag Target",
"delete-post": "Delete Post",
"purge-post": "Purge Post",
"restore-post": "Restore Post",
"user-view": "View Profile",
"user-edit": "Edit Profile",

View File

@@ -15,25 +15,25 @@ define('admin/advanced/logs', function () {
var action = btnEl.attr('data-action');
switch (action) {
case 'reload':
socket.emit('admin.logs.get', function (err, logs) {
if (!err) {
logsEl.text(logs);
logsEl.scrollTop(logsEl.prop('scrollHeight'));
} else {
app.alertError(err.message);
}
});
break;
case 'reload':
socket.emit('admin.logs.get', function (err, logs) {
if (!err) {
logsEl.text(logs);
logsEl.scrollTop(logsEl.prop('scrollHeight'));
} else {
app.alertError(err.message);
}
});
break;
case 'clear':
socket.emit('admin.logs.clear', function (err) {
if (!err) {
app.alertSuccess('[[admin/advanced/logs:clear-success]]');
btnEl.prev().click();
}
});
break;
case 'clear':
socket.emit('admin.logs.clear', function (err) {
if (!err) {
app.alertSuccess('[[admin/advanced/logs:clear-success]]');
btnEl.prev().click();
}
});
break;
}
});
};

View File

@@ -56,18 +56,18 @@ define('admin/extend/rewards', ['translator', 'benchpress'], function (translato
function select(el) {
el.val(el.attr('data-selected'));
switch (el.attr('name')) {
case 'rid':
selectReward(el);
break;
case 'rid':
selectReward(el);
break;
}
}
function update(el) {
el.attr('data-selected', el.val());
switch (el.attr('name')) {
case 'rid':
selectReward(el);
break;
case 'rid':
selectReward(el);
break;
}
}
@@ -94,15 +94,15 @@ define('admin/extend/rewards', ['translator', 'benchpress'], function (translato
inputs.forEach(function (input) {
html += '<label for="' + input.name + '">' + input.label + '<br />';
switch (input.type) {
case 'select':
html += '<select name="' + input.name + '">';
input.values.forEach(function (value) {
html += '<option value="' + value.value + '">' + value.name + '</option>';
});
break;
case 'text':
html += '<input type="text" name="' + input.name + '" />';
break;
case 'select':
html += '<select name="' + input.name + '">';
input.values.forEach(function (value) {
html += '<option value="' + value.value + '">' + value.name + '</option>';
});
break;
case 'text':
html += '<input type="text" name="' + input.name + '" />';
break;
}
html += '</label><br />';
});

View File

@@ -45,36 +45,36 @@ define('admin/manage/group', [
var action = btnEl.attr('data-action');
switch (action) {
case 'toggleOwnership':
socket.emit('groups.' + (isOwner ? 'rescind' : 'grant'), {
toUid: uid,
groupName: groupName,
}, function (err) {
if (err) {
return app.alertError(err.message);
}
ownerFlagEl.toggleClass('invisible');
});
break;
case 'kick':
bootbox.confirm('[[admin/manage/groups:edit.confirm-remove-user]]', function (confirm) {
if (!confirm) {
return;
}
socket.emit('admin.groups.leave', {
uid: uid,
case 'toggleOwnership':
socket.emit('groups.' + (isOwner ? 'rescind' : 'grant'), {
toUid: uid,
groupName: groupName,
}, function (err) {
if (err) {
return app.alertError(err.message);
}
userRow.slideUp().remove();
ownerFlagEl.toggleClass('invisible');
});
});
break;
default:
break;
break;
case 'kick':
bootbox.confirm('[[admin/manage/groups:edit.confirm-remove-user]]', function (confirm) {
if (!confirm) {
return;
}
socket.emit('admin.groups.leave', {
uid: uid,
groupName: groupName,
}, function (err) {
if (err) {
return app.alertError(err.message);
}
userRow.slideUp().remove();
});
});
break;
default:
break;
}
});

View File

@@ -58,21 +58,21 @@ define('admin/manage/groups', ['translator', 'benchpress'], function (translator
var groupName = el.parents('tr[data-groupname]').attr('data-groupname');
switch (action) {
case 'delete':
bootbox.confirm('[[admin/manage/groups:alerts.confirm-delete]]', function (confirm) {
if (confirm) {
socket.emit('groups.delete', {
groupName: groupName,
}, function (err) {
if (err) {
return app.alertError(err.message);
}
case 'delete':
bootbox.confirm('[[admin/manage/groups:alerts.confirm-delete]]', function (confirm) {
if (confirm) {
socket.emit('groups.delete', {
groupName: groupName,
}, function (err) {
if (err) {
return app.alertError(err.message);
}
ajaxify.refresh();
});
}
});
break;
ajaxify.refresh();
});
}
});
break;
}
});
};

View File

@@ -156,17 +156,17 @@ define('admin/settings', ['uploader'], function (uploader) {
if (field.is('input')) {
inputType = field.attr('type');
switch (inputType) {
case 'text':
case 'password':
case 'hidden':
case 'textarea':
case 'number':
value = field.val();
break;
case 'text':
case 'password':
case 'hidden':
case 'textarea':
case 'number':
value = field.val();
break;
case 'checkbox':
value = field.prop('checked') ? '1' : '0';
break;
case 'checkbox':
value = field.prop('checked') ? '1' : '0';
break;
}
} else if (field.is('textarea') || field.is('select')) {
value = field.val();

View File

@@ -275,25 +275,25 @@ app.cacheBuster = null;
function showAlert(type, message) {
switch (messages[type].format) {
case 'alert':
app.alert({
type: 'success',
title: messages[type].title,
message: messages[type].message,
timeout: 5000,
});
break;
case 'alert':
app.alert({
type: 'success',
title: messages[type].title,
message: messages[type].message,
timeout: 5000,
});
break;
case 'modal':
require(['translator'], function (translator) {
translator.translate(message || messages[type].message, function (translated) {
bootbox.alert({
title: messages[type].title,
message: translated,
case 'modal':
require(['translator'], function (translator) {
translator.translate(message || messages[type].message, function (translated) {
bootbox.alert({
title: messages[type].title,
message: translated,
});
});
});
});
break;
break;
}
}

View File

@@ -61,13 +61,13 @@ define('forum/account/settings', ['forum/account/header', 'components', 'sounds'
}
switch (input.attr('type')) {
case 'text':
case 'textarea':
settings[setting] = input.val();
break;
case 'checkbox':
settings[setting] = input.is(':checked') ? 1 : 0;
break;
case 'text':
case 'textarea':
settings[setting] = input.val();
break;
case 'checkbox':
settings[setting] = input.is(':checked') ? 1 : 0;
break;
}
});

View File

@@ -157,18 +157,18 @@ define('forum/chats', [
var action = this.getAttribute('data-action');
switch (action) {
case 'edit':
var inputEl = $('[data-roomid="' + roomId + '"] [component="chat/input"]');
messages.prepEdit(inputEl, messageId, roomId);
break;
case 'edit':
var inputEl = $('[data-roomid="' + roomId + '"] [component="chat/input"]');
messages.prepEdit(inputEl, messageId, roomId);
break;
case 'delete':
messages.delete(messageId, roomId);
break;
case 'delete':
messages.delete(messageId, roomId);
break;
case 'restore':
messages.restore(messageId, roomId);
break;
case 'restore':
messages.restore(messageId, roomId);
break;
}
});
};

View File

@@ -13,50 +13,83 @@ define('forum/flags/detail', ['forum/flags/list', 'components', 'translator', 'b
var uid = $(this).parents('[data-uid]').attr('data-uid');
switch (action) {
case 'update':
socket.emit('flags.update', {
flagId: ajaxify.data.flagId,
data: $('#attributes').serializeArray(),
}, function (err, history) {
if (err) {
return app.alertError(err.message);
}
app.alertSuccess('[[flags:updated]]');
Detail.reloadHistory(history);
});
break;
case 'update':
socket.emit('flags.update', {
flagId: ajaxify.data.flagId,
data: $('#attributes').serializeArray(),
}, function (err, history) {
if (err) {
return app.alertError(err.message);
}
app.alertSuccess('[[flags:updated]]');
Detail.reloadHistory(history);
});
break;
case 'appendNote':
socket.emit('flags.appendNote', {
flagId: ajaxify.data.flagId,
note: document.getElementById('note').value,
}, function (err, payload) {
if (err) {
return app.alertError(err.message);
}
app.alertSuccess('[[flags:note-added]]');
Detail.reloadNotes(payload.notes);
Detail.reloadHistory(payload.history);
});
break;
case 'appendNote':
socket.emit('flags.appendNote', {
flagId: ajaxify.data.flagId,
note: document.getElementById('note').value,
}, function (err, payload) {
if (err) {
return app.alertError(err.message);
}
app.alertSuccess('[[flags:note-added]]');
Detail.reloadNotes(payload.notes);
Detail.reloadHistory(payload.history);
});
break;
case 'chat':
app.newChat(uid);
break;
case 'chat':
app.newChat(uid);
break;
case 'ban':
AccountHeader.banAccount(uid, ajaxify.refresh);
break;
case 'ban':
AccountHeader.banAccount(uid, ajaxify.refresh);
break;
case 'delete':
AccountHeader.deleteAccount(uid, ajaxify.refresh);
break;
case 'delete-account':
AccountHeader.deleteAccount(uid, ajaxify.refresh);
break;
case 'delete-post':
postAction('delete', ajaxify.data.target.pid, ajaxify.data.target.tid);
break;
case 'purge-post':
postAction('purge', ajaxify.data.target.pid, ajaxify.data.target.tid);
break;
case 'restore-post':
postAction('restore', ajaxify.data.target.pid, ajaxify.data.target.tid);
break;
}
});
FlagsList.enableFilterForm();
};
function postAction(action, pid, tid) {
translator.translate('[[topic:post_' + action + '_confirm]]', function (msg) {
bootbox.confirm(msg, function (confirm) {
if (!confirm) {
return;
}
socket.emit('posts.' + action, {
pid: pid,
tid: tid,
}, function (err) {
if (err) {
app.alertError(err.message);
}
ajaxify.refresh();
});
});
});
}
Detail.reloadNotes = function (notes) {
Benchpress.parse('flags/detail', 'notes', {
notes: notes,

View File

@@ -63,69 +63,69 @@ define('forum/groups/details', [
var action = btnEl.attr('data-action');
switch (action) {
case 'toggleOwnership':
socket.emit('groups.' + (isOwner ? 'rescind' : 'grant'), {
toUid: uid,
groupName: groupName,
}, function (err) {
if (!err) {
ownerFlagEl.toggleClass('invisible');
} else {
app.alertError(err.message);
}
});
break;
case 'kick':
translator.translate('[[groups:details.kick_confirm]]', function (translated) {
bootbox.confirm(translated, function (confirm) {
if (!confirm) {
return;
case 'toggleOwnership':
socket.emit('groups.' + (isOwner ? 'rescind' : 'grant'), {
toUid: uid,
groupName: groupName,
}, function (err) {
if (!err) {
ownerFlagEl.toggleClass('invisible');
} else {
app.alertError(err.message);
}
});
break;
socket.emit('groups.kick', {
uid: uid,
groupName: groupName,
}, function (err) {
if (!err) {
userRow.slideUp().remove();
} else {
app.alertError(err.message);
case 'kick':
translator.translate('[[groups:details.kick_confirm]]', function (translated) {
bootbox.confirm(translated, function (confirm) {
if (!confirm) {
return;
}
socket.emit('groups.kick', {
uid: uid,
groupName: groupName,
}, function (err) {
if (!err) {
userRow.slideUp().remove();
} else {
app.alertError(err.message);
}
});
});
});
});
break;
break;
case 'update':
Details.update();
break;
case 'update':
Details.update();
break;
case 'delete':
Details.deleteGroup();
break;
case 'delete':
Details.deleteGroup();
break;
case 'join': // intentional fall-throughs!
case 'leave':
case 'accept':
case 'reject':
case 'issueInvite':
case 'rescindInvite':
case 'acceptInvite':
case 'rejectInvite':
case 'acceptAll':
case 'rejectAll':
socket.emit('groups.' + action, {
toUid: uid,
groupName: groupName,
}, function (err) {
if (!err) {
ajaxify.refresh();
} else {
app.alertError(err.message);
}
});
break;
case 'join': // intentional fall-throughs!
case 'leave':
case 'accept':
case 'reject':
case 'issueInvite':
case 'rescindInvite':
case 'acceptInvite':
case 'rejectInvite':
case 'acceptAll':
case 'rejectAll':
socket.emit('groups.' + action, {
toUid: uid,
groupName: groupName,
}, function (err) {
if (!err) {
ajaxify.refresh();
} else {
app.alertError(err.message);
}
});
break;
}
});
};

View File

@@ -107,16 +107,16 @@ $('document').ready(function () {
}
switch (type) {
case 'admin:username':
return validateUsername(field);
case 'admin:password':
return validatePassword(field);
case 'admin:passwordConfirm':
return validateConfirmPassword(field);
case 'admin:email':
return validateEmail(field);
case 'database':
return switchDatabase(field);
case 'admin:username':
return validateUsername(field);
case 'admin:password':
return validatePassword(field);
case 'admin:passwordConfirm':
return validateConfirmPassword(field);
case 'admin:email':
return validateEmail(field);
case 'database':
return switchDatabase(field);
}
}

View File

@@ -225,49 +225,49 @@
var icons = '';
switch (data.platform) {
case 'Linux':
icons += '<i class="fa fa-fw fa-linux"></i>';
break;
case 'Microsoft Windows':
icons += '<i class="fa fa-fw fa-windows"></i>';
break;
case 'Apple Mac':
icons += '<i class="fa fa-fw fa-apple"></i>';
break;
case 'Android':
icons += '<i class="fa fa-fw fa-android"></i>';
break;
case 'iPad':
icons += '<i class="fa fa-fw fa-tablet"></i>';
break;
case 'iPod': // intentional fall-through
case 'iPhone':
icons += '<i class="fa fa-fw fa-mobile"></i>';
break;
default:
icons += '<i class="fa fa-fw fa-question-circle"></i>';
break;
case 'Linux':
icons += '<i class="fa fa-fw fa-linux"></i>';
break;
case 'Microsoft Windows':
icons += '<i class="fa fa-fw fa-windows"></i>';
break;
case 'Apple Mac':
icons += '<i class="fa fa-fw fa-apple"></i>';
break;
case 'Android':
icons += '<i class="fa fa-fw fa-android"></i>';
break;
case 'iPad':
icons += '<i class="fa fa-fw fa-tablet"></i>';
break;
case 'iPod': // intentional fall-through
case 'iPhone':
icons += '<i class="fa fa-fw fa-mobile"></i>';
break;
default:
icons += '<i class="fa fa-fw fa-question-circle"></i>';
break;
}
switch (data.browser) {
case 'Chrome':
icons += '<i class="fa fa-fw fa-chrome"></i>';
break;
case 'Firefox':
icons += '<i class="fa fa-fw fa-firefox"></i>';
break;
case 'Safari':
icons += '<i class="fa fa-fw fa-safari"></i>';
break;
case 'IE':
icons += '<i class="fa fa-fw fa-internet-explorer"></i>';
break;
case 'Edge':
icons += '<i class="fa fa-fw fa-edge"></i>';
break;
default:
icons += '<i class="fa fa-fw fa-question-circle"></i>';
break;
case 'Chrome':
icons += '<i class="fa fa-fw fa-chrome"></i>';
break;
case 'Firefox':
icons += '<i class="fa fa-fw fa-firefox"></i>';
break;
case 'Safari':
icons += '<i class="fa fa-fw fa-safari"></i>';
break;
case 'IE':
icons += '<i class="fa fa-fw fa-internet-explorer"></i>';
break;
case 'Edge':
icons += '<i class="fa fa-fw fa-edge"></i>';
break;
default:
icons += '<i class="fa fa-fw fa-question-circle"></i>';
break;
}
return icons;

View File

@@ -141,28 +141,28 @@ define('settings/key', function () {
for (var i = 0; i < parts.length; i += 1) {
var part = parts[i];
switch (part) {
case 'C':
case 'Ctrl':
key.c = true;
break;
case 'A':
case 'Alt':
key.a = true;
break;
case 'S':
case 'Shift':
key.s = true;
break;
case 'M':
case 'Meta':
key.m = true;
break;
default:
var num = /\d+/.exec(part);
if (num != null) {
key.code = num[0];
}
key.char = convertKeyCodeToChar(key.code);
case 'C':
case 'Ctrl':
key.c = true;
break;
case 'A':
case 'Alt':
key.a = true;
break;
case 'S':
case 'Shift':
key.s = true;
break;
case 'M':
case 'Meta':
key.m = true;
break;
default:
var num = /\d+/.exec(part);
if (num != null) {
key.code = num[0];
}
key.char = convertKeyCodeToChar(key.code);
}
}
return key;

View File

@@ -183,18 +183,18 @@ define('taskbar', ['benchpress', 'translator'], function (Benchpress, translator
var processUpdate = function (element, key, value) {
switch (key) {
case 'title':
element.find('[component="taskbar/title"]').text(value);
break;
case 'icon':
element.find('i').attr('class', 'fa fa-' + value);
break;
case 'image':
element.find('a').css('background-image', 'url("' + value + '")');
break;
case 'background-color':
element.find('a').css('background-color', value);
break;
case 'title':
element.find('[component="taskbar/title"]').text(value);
break;
case 'icon':
element.find('i').attr('class', 'fa fa-' + value);
break;
case 'image':
element.find('a').css('background-image', 'url("' + value + '")');
break;
case 'background-color':
element.find('a').css('background-color', value);
break;
}
};

View File

@@ -109,30 +109,30 @@ app.isConnected = false;
var room;
switch (url_parts[0]) {
case 'user':
room = 'user/' + (ajaxify.data ? ajaxify.data.theirid : 0);
break;
case 'topic':
room = 'topic_' + url_parts[1];
break;
case 'category':
room = 'category_' + url_parts[1];
break;
case 'recent':
room = 'recent_topics';
break;
case 'unread':
room = 'unread_topics';
break;
case 'popular':
room = 'popular_topics';
break;
case 'admin':
room = 'admin';
break;
case 'categories':
room = 'categories';
break;
case 'user':
room = 'user/' + (ajaxify.data ? ajaxify.data.theirid : 0);
break;
case 'topic':
room = 'topic_' + url_parts[1];
break;
case 'category':
room = 'category_' + url_parts[1];
break;
case 'recent':
room = 'recent_topics';
break;
case 'unread':
room = 'unread_topics';
break;
case 'popular':
room = 'popular_topics';
break;
case 'admin':
room = 'admin';
break;
case 'categories':
room = 'categories';
break;
}
app.currentRoom = '';
app.enterRoom(room);

View File

@@ -175,15 +175,15 @@ function info() {
var config = require('../../config.json');
switch (config.database) {
case 'redis':
console.log(' version: ' + info.redis_version);
console.log(' disk sync: ' + info.rdb_last_bgsave_status);
break;
case 'redis':
console.log(' version: ' + info.redis_version);
console.log(' disk sync: ' + info.rdb_last_bgsave_status);
break;
case 'mongo':
console.log(' version: ' + info.version);
console.log(' engine: ' + info.storageEngine);
break;
case 'mongo':
console.log(' version: ' + info.version);
console.log(' engine: ' + info.storageEngine);
break;
}
next();

View File

@@ -43,17 +43,17 @@ function installAll() {
const packageManager = require('nconf').get('package_manager');
if (supportedPackageManagerList.indexOf(packageManager) >= 0) {
switch (packageManager) {
case 'yarn':
command = 'yarn';
break;
case 'pnpm':
command = 'pnpm install';
break;
case 'cnpm':
command = 'cnpm install';
break;
default:
break;
case 'yarn':
command = 'yarn';
break;
case 'pnpm':
command = 'pnpm install';
break;
case 'cnpm':
command = 'cnpm install';
break;
default:
break;
}
}
} catch (e) {

View File

@@ -151,25 +151,25 @@ userController.exportUploads = function (req, res, next) {
archive.on('warning', function (err) {
switch (err.code) {
case 'ENOENT':
winston.warn('[user/export/uploads] File not found: ' + trimPath(err.path));
break;
case 'ENOENT':
winston.warn('[user/export/uploads] File not found: ' + trimPath(err.path));
break;
default:
winston.warn('[user/export/uploads] Unexpected warning: ' + err.message);
break;
default:
winston.warn('[user/export/uploads] Unexpected warning: ' + err.message);
break;
}
});
archive.on('error', function (err) {
switch (err.code) {
case 'EACCES':
winston.error('[user/export/uploads] File inaccessible: ' + trimPath(err.path));
break;
case 'EACCES':
winston.error('[user/export/uploads] File inaccessible: ' + trimPath(err.path));
break;
default:
winston.error('[user/export/uploads] Unable to construct archive: ' + err.message);
break;
default:
winston.error('[user/export/uploads] Unable to construct archive: ' + err.message);
break;
}
res.sendStatus(500);

View File

@@ -63,9 +63,9 @@ Flags.init = async function () {
perPage: function () { /* noop */ },
quick: function (sets, orSets, key, uid) {
switch (key) {
case 'mine':
sets.push('flags:byAssignee:' + uid);
break;
case 'mine':
sets.push('flags:byAssignee:' + uid);
break;
}
},
},

View File

@@ -31,18 +31,18 @@ module.exports = function (Groups) {
Groups.sort = function (strategy, groups) {
switch (strategy) {
case 'count':
groups.sort((a, b) => a.slug > b.slug)
.sort((a, b) => b.memberCount - a.memberCount);
break;
case 'count':
groups.sort((a, b) => a.slug > b.slug)
.sort((a, b) => b.memberCount - a.memberCount);
break;
case 'date':
groups.sort((a, b) => b.createtime - a.createtime);
break;
case 'date':
groups.sort((a, b) => b.createtime - a.createtime);
break;
case 'alpha': // intentional fall-through
default:
groups.sort((a, b) => (a.slug > b.slug ? 1 : -1));
case 'alpha': // intentional fall-through
default:
groups.sort((a, b) => (a.slug > b.slug ? 1 : -1));
}
return groups;

View File

@@ -87,44 +87,44 @@ async function getThemes(themePath) {
Themes.set = async (data) => {
switch (data.type) {
case 'local': {
const current = await Meta.configs.get('theme:id');
if (current !== data.id) {
let config = await fsReadfile(path.join(nconf.get('themes_path'), data.id, 'theme.json'), 'utf8');
config = JSON.parse(config);
case 'local': {
const current = await Meta.configs.get('theme:id');
if (current !== data.id) {
let config = await fsReadfile(path.join(nconf.get('themes_path'), data.id, 'theme.json'), 'utf8');
config = JSON.parse(config);
await db.sortedSetRemove('plugins:active', current);
const numPlugins = await db.sortedSetCard('plugins:active');
await db.sortedSetAdd('plugins:active', numPlugins, data.id);
// Re-set the themes path (for when NodeBB is reloaded)
Themes.setPath(config);
await db.sortedSetRemove('plugins:active', current);
const numPlugins = await db.sortedSetCard('plugins:active');
await db.sortedSetAdd('plugins:active', numPlugins, data.id);
// Re-set the themes path (for when NodeBB is reloaded)
Themes.setPath(config);
await Meta.configs.setMultiple({
'theme:type': data.type,
'theme:id': data.id,
'theme:staticDir': config.staticDir ? config.staticDir : '',
'theme:templates': config.templates ? config.templates : '',
'theme:src': '',
bootswatchSkin: '',
});
await Meta.configs.setMultiple({
'theme:type': data.type,
'theme:id': data.id,
'theme:staticDir': config.staticDir ? config.staticDir : '',
'theme:templates': config.templates ? config.templates : '',
'theme:src': '',
bootswatchSkin: '',
});
await events.log({
type: 'theme-set',
uid: parseInt(data.uid, 10) || 0,
ip: data.ip || '127.0.0.1',
text: data.id,
});
await events.log({
type: 'theme-set',
uid: parseInt(data.uid, 10) || 0,
ip: data.ip || '127.0.0.1',
text: data.id,
});
Meta.reloadRequired = true;
Meta.reloadRequired = true;
}
break;
}
break;
}
case 'bootswatch':
await Meta.configs.setMultiple({
'theme:src': data.src,
bootswatchSkin: data.id.toLowerCase(),
});
break;
case 'bootswatch':
await Meta.configs.setMultiple({
'theme:src': data.src,
bootswatchSkin: data.id.toLowerCase(),
});
break;
}
};

View File

@@ -373,30 +373,30 @@ Notifications.merge = async function (notifications) {
}
switch (mergeId) {
case 'notifications:upvoted_your_post_in':
case 'notifications:user_started_following_you':
case 'notifications:user_posted_to':
case 'notifications:user_flagged_post_in':
case 'notifications:user_flagged_user':
var usernames = _.uniq(set.map(notifObj => notifObj && notifObj.user && notifObj.user.username));
var numUsers = usernames.length;
case 'notifications:upvoted_your_post_in':
case 'notifications:user_started_following_you':
case 'notifications:user_posted_to':
case 'notifications:user_flagged_post_in':
case 'notifications:user_flagged_user':
var usernames = _.uniq(set.map(notifObj => notifObj && notifObj.user && notifObj.user.username));
var numUsers = usernames.length;
var title = utils.decodeHTMLEntities(notifications[modifyIndex].topicTitle || '');
var titleEscaped = title.replace(/%/g, '&#37;').replace(/,/g, '&#44;');
titleEscaped = titleEscaped ? (', ' + titleEscaped) : '';
var title = utils.decodeHTMLEntities(notifications[modifyIndex].topicTitle || '');
var titleEscaped = title.replace(/%/g, '&#37;').replace(/,/g, '&#44;');
titleEscaped = titleEscaped ? (', ' + titleEscaped) : '';
if (numUsers === 2) {
notifications[modifyIndex].bodyShort = '[[' + mergeId + '_dual, ' + usernames.join(', ') + titleEscaped + ']]';
} else if (numUsers > 2) {
notifications[modifyIndex].bodyShort = '[[' + mergeId + '_multiple, ' + usernames[0] + ', ' + (numUsers - 1) + titleEscaped + ']]';
}
if (numUsers === 2) {
notifications[modifyIndex].bodyShort = '[[' + mergeId + '_dual, ' + usernames.join(', ') + titleEscaped + ']]';
} else if (numUsers > 2) {
notifications[modifyIndex].bodyShort = '[[' + mergeId + '_multiple, ' + usernames[0] + ', ' + (numUsers - 1) + titleEscaped + ']]';
}
notifications[modifyIndex].path = set[set.length - 1].path;
break;
notifications[modifyIndex].path = set[set.length - 1].path;
break;
case 'new_register':
notifications[modifyIndex].bodyShort = '[[notifications:' + mergeId + '_multiple, ' + set.length + ']]';
break;
case 'new_register':
notifications[modifyIndex].bodyShort = '[[notifications:' + mergeId + '_multiple, ' + set.length + ']]';
break;
}
// Filter out duplicates

View File

@@ -90,20 +90,20 @@ module.exports = function (Plugins) {
// clear old data before build
fields.forEach((field) => {
switch (field) {
case 'clientScripts':
case 'acpScripts':
case 'cssFiles':
case 'lessFiles':
case 'acpLessFiles':
Plugins[field].length = 0;
break;
case 'soundpack':
Plugins.soundpacks.length = 0;
break;
case 'languageData':
Plugins.languageData.languages = [];
Plugins.languageData.namespaces = [];
break;
case 'clientScripts':
case 'acpScripts':
case 'cssFiles':
case 'lessFiles':
case 'acpLessFiles':
Plugins[field].length = 0;
break;
case 'soundpack':
Plugins.soundpacks.length = 0;
break;
case 'languageData':
Plugins.languageData.languages = [];
Plugins.languageData.namespaces = [];
break;
// do nothing for modules and staticDirs
}
});

View File

@@ -15,55 +15,55 @@ Email.test = function (socket, data, callback) {
};
switch (data.template) {
case 'digest':
userDigest.execute({
interval: 'alltime',
subscribers: [socket.uid],
}, callback);
break;
case 'digest':
userDigest.execute({
interval: 'alltime',
subscribers: [socket.uid],
}, callback);
break;
case 'banned':
Object.assign(payload, {
username: 'test-user',
until: utils.toISOString(Date.now()),
reason: 'Test Reason',
});
emailer.send(data.template, socket.uid, payload, callback);
break;
case 'banned':
Object.assign(payload, {
username: 'test-user',
until: utils.toISOString(Date.now()),
reason: 'Test Reason',
});
emailer.send(data.template, socket.uid, payload, callback);
break;
case 'welcome':
userEmail.sendValidationEmail(socket.uid, {
force: 1,
}, callback);
break;
case 'welcome':
userEmail.sendValidationEmail(socket.uid, {
force: 1,
}, callback);
break;
case 'notification':
async.waterfall([
function (next) {
notifications.create({
type: 'test',
bodyShort: '[[email:notif.test.short]]',
bodyLong: '[[email:notif.test.long]]',
nid: 'uid:' + socket.uid + ':test',
path: '/',
from: socket.uid,
}, next);
},
function (notifObj, next) {
emailer.send('notification', socket.uid, {
path: notifObj.path,
subject: utils.stripHTMLTags(notifObj.subject || '[[notifications:new_notification]]'),
intro: utils.stripHTMLTags(notifObj.bodyShort),
body: notifObj.bodyLong || '',
notification: notifObj,
showUnsubscribe: true,
}, next);
},
], callback);
break;
case 'notification':
async.waterfall([
function (next) {
notifications.create({
type: 'test',
bodyShort: '[[email:notif.test.short]]',
bodyLong: '[[email:notif.test.long]]',
nid: 'uid:' + socket.uid + ':test',
path: '/',
from: socket.uid,
}, next);
},
function (notifObj, next) {
emailer.send('notification', socket.uid, {
path: notifObj.path,
subject: utils.stripHTMLTags(notifObj.subject || '[[notifications:new_notification]]'),
intro: utils.stripHTMLTags(notifObj.bodyShort),
body: notifObj.bodyLong || '',
notification: notifObj,
showUnsubscribe: true,
}, next);
},
], callback);
break;
default:
emailer.send(data.template, socket.uid, payload, callback);
break;
default:
emailer.send(data.template, socket.uid, payload, callback);
break;
}
};

View File

@@ -50,17 +50,17 @@ start.start = async function () {
}
} catch (err) {
switch (err.message) {
case 'dependencies-out-of-date':
winston.error('One or more of NodeBB\'s dependent packages are out-of-date. Please run the following command to update them:');
winston.error(' ./nodebb upgrade');
break;
case 'dependencies-missing':
winston.error('One or more of NodeBB\'s dependent packages are missing. Please run the following command to update them:');
winston.error(' ./nodebb upgrade');
break;
default:
winston.error(err.stack);
break;
case 'dependencies-out-of-date':
winston.error('One or more of NodeBB\'s dependent packages are out-of-date. Please run the following command to update them:');
winston.error(' ./nodebb upgrade');
break;
case 'dependencies-missing':
winston.error('One or more of NodeBB\'s dependent packages are missing. Please run the following command to update them:');
winston.error(' ./nodebb upgrade');
break;
default:
winston.error(err.stack);
break;
}
// Either way, bad stuff happened. Abort start.

View File

@@ -120,35 +120,35 @@ describe('Read API', async () => {
assert(response[prop] !== null, '"' + prop + '" was null, but schema does not specify it to be a nullable property (path: ' + path + ', context: ' + context + ')');
switch (schema[prop].type) {
case 'string':
assert.strictEqual(typeof response[prop], 'string', '"' + prop + '" was expected to be a string, but was ' + typeof response[prop] + ' instead (path: ' + path + ', context: ' + context + ')');
break;
case 'boolean':
assert.strictEqual(typeof response[prop], 'boolean', '"' + prop + '" was expected to be a boolean, but was ' + typeof response[prop] + ' instead (path: ' + path + ', context: ' + context + ')');
break;
case 'object':
assert.strictEqual(typeof response[prop], 'object', '"' + prop + '" was expected to be an object, but was ' + typeof response[prop] + ' instead (path: ' + path + ', context: ' + context + ')');
compare(schema[prop], response[prop], context ? [context, prop].join('.') : prop);
break;
case 'array':
assert.strictEqual(Array.isArray(response[prop]), true, '"' + prop + '" was expected to be an array, but was ' + typeof response[prop] + ' instead (path: ' + path + ', context: ' + context + ')');
case 'string':
assert.strictEqual(typeof response[prop], 'string', '"' + prop + '" was expected to be a string, but was ' + typeof response[prop] + ' instead (path: ' + path + ', context: ' + context + ')');
break;
case 'boolean':
assert.strictEqual(typeof response[prop], 'boolean', '"' + prop + '" was expected to be a boolean, but was ' + typeof response[prop] + ' instead (path: ' + path + ', context: ' + context + ')');
break;
case 'object':
assert.strictEqual(typeof response[prop], 'object', '"' + prop + '" was expected to be an object, but was ' + typeof response[prop] + ' instead (path: ' + path + ', context: ' + context + ')');
compare(schema[prop], response[prop], context ? [context, prop].join('.') : prop);
break;
case 'array':
assert.strictEqual(Array.isArray(response[prop]), true, '"' + prop + '" was expected to be an array, but was ' + typeof response[prop] + ' instead (path: ' + path + ', context: ' + context + ')');
if (schema[prop].items) {
if (schema[prop].items) {
// Ensure the array items have a schema defined
assert(schema[prop].items.type || schema[prop].items.allOf, '"' + prop + '" is defined to be an array, but its items have no schema defined (path: ' + path + ', context: ' + context + ')');
assert(schema[prop].items.type || schema[prop].items.allOf, '"' + prop + '" is defined to be an array, but its items have no schema defined (path: ' + path + ', context: ' + context + ')');
// Compare types
if (schema[prop].items.type === 'object' || Array.isArray(schema[prop].items.allOf)) {
response[prop].forEach((res) => {
compare(schema[prop].items, res, context ? [context, prop].join('.') : prop);
});
} else if (response[prop].length) { // for now
response[prop].forEach((item) => {
assert.strictEqual(typeof item, schema[prop].items.type, '"' + prop + '" should have ' + schema[prop].items.type + ' items, but found ' + typeof items + ' instead (path: ' + path + ', context: ' + context + ')');
});
// Compare types
if (schema[prop].items.type === 'object' || Array.isArray(schema[prop].items.allOf)) {
response[prop].forEach((res) => {
compare(schema[prop].items, res, context ? [context, prop].join('.') : prop);
});
} else if (response[prop].length) { // for now
response[prop].forEach((item) => {
assert.strictEqual(typeof item, schema[prop].items.type, '"' + prop + '" should have ' + schema[prop].items.type + ' items, but found ' + typeof items + ' instead (path: ' + path + ', context: ' + context + ')');
});
}
}
}
break;
break;
}
}
});
@@ -176,15 +176,15 @@ describe('Read API', async () => {
assert(param.example !== null && param.example !== undefined, path + ' has parameters without examples');
switch (param.in) {
case 'path':
testPath = testPath.replace('{' + param.name + '}', param.example);
break;
case 'header':
headers[param.name] = param.example;
break;
case 'query':
qs[param.name] = param.example;
break;
case 'path':
testPath = testPath.replace('{' + param.name + '}', param.example);
break;
case 'header':
headers[param.name] = param.example;
break;
case 'query':
qs[param.name] = param.example;
break;
}
});
}

View File

@@ -293,13 +293,13 @@ describe('Flags', function () {
history.forEach(function (change) {
switch (change.attribute) {
case 'state':
assert.strictEqual('[[flags:state-wip]]', change.value);
break;
case 'state':
assert.strictEqual('[[flags:state-wip]]', change.value);
break;
case 'assignee':
assert.strictEqual(1, change.value);
break;
case 'assignee':
assert.strictEqual(1, change.value);
break;
}
});