running eslint again

v1.18.x
Julian Lam 8 years ago
parent 72e77772db
commit ddea9f534e

@ -182,7 +182,7 @@ define('forum/account/header', [
require(['flags'], function (flags) { require(['flags'], function (flags) {
flags.showFlagModal({ flags.showFlagModal({
type: 'user', type: 'user',
id: ajaxify.data.uid id: ajaxify.data.uid,
}); });
}); });
} }

@ -14,34 +14,32 @@ define('forum/flags/detail', ['forum/flags/list', 'components', 'translator'], f
var action = this.getAttribute('data-action'); var action = this.getAttribute('data-action');
switch (action) { switch (action) {
case 'update': case 'update':
socket.emit('flags.update', { socket.emit('flags.update', {
flagId: ajaxify.data.flagId, flagId: ajaxify.data.flagId,
data: $('#attributes').serializeArray() data: $('#attributes').serializeArray(),
}, function (err, history) { }, function (err, history) {
if (err) { if (err) {
return app.alertError(err.message); return app.alertError(err.message);
} else { }
app.alertSuccess('[[flags:updated]]'); app.alertSuccess('[[flags:updated]]');
Flags.reloadHistory(history); Flags.reloadHistory(history);
} });
}); break;
break;
case 'appendNote':
case 'appendNote': socket.emit('flags.appendNote', {
socket.emit('flags.appendNote', { flagId: ajaxify.data.flagId,
flagId: ajaxify.data.flagId, note: document.getElementById('note').value,
note: document.getElementById('note').value }, function (err, payload) {
}, function (err, payload) { if (err) {
if (err) { return app.alertError(err.message);
return app.alertError(err.message); }
} else { app.alertSuccess('[[flags:note-added]]');
app.alertSuccess('[[flags:note-added]]'); Flags.reloadNotes(payload.notes);
Flags.reloadNotes(payload.notes); Flags.reloadHistory(payload.history);
Flags.reloadHistory(payload.history); });
} break;
});
break;
} }
}); });
@ -50,7 +48,7 @@ define('forum/flags/detail', ['forum/flags/list', 'components', 'translator'], f
Flags.reloadNotes = function (notes) { Flags.reloadNotes = function (notes) {
templates.parse('flags/detail', 'notes', { templates.parse('flags/detail', 'notes', {
notes: notes notes: notes,
}, function (html) { }, function (html) {
var wrapperEl = components.get('flag/notes'); var wrapperEl = components.get('flag/notes');
wrapperEl.empty(); wrapperEl.empty();
@ -62,7 +60,7 @@ define('forum/flags/detail', ['forum/flags/list', 'components', 'translator'], f
Flags.reloadHistory = function (history) { Flags.reloadHistory = function (history) {
templates.parse('flags/detail', 'history', { templates.parse('flags/detail', 'history', {
history: history history: history,
}, function (html) { }, function (html) {
translator.translate(html, function (translated) { translator.translate(html, function (translated) {
var wrapperEl = components.get('flag/history'); var wrapperEl = components.get('flag/history');

@ -47,17 +47,17 @@ define('forum/flags/list', ['components', 'Chart'], function (components, Chart)
labels: dailyLabels, labels: dailyLabels,
datasets: [ datasets: [
{ {
label: "", label: '',
backgroundColor: "rgba(151,187,205,0.2)", backgroundColor: 'rgba(151,187,205,0.2)',
borderColor: "rgba(151,187,205,1)", borderColor: 'rgba(151,187,205,1)',
pointBackgroundColor: "rgba(151,187,205,1)", pointBackgroundColor: 'rgba(151,187,205,1)',
pointHoverBackgroundColor: "#fff", pointHoverBackgroundColor: '#fff',
pointBorderColor: "#fff", pointBorderColor: '#fff',
pointHoverBorderColor: "rgba(151,187,205,1)", pointHoverBorderColor: 'rgba(151,187,205,1)',
data: ajaxify.data.analytics data: ajaxify.data.analytics,
} },
] ],
} },
}; };
dailyCanvas.width = $(dailyCanvas).parent().width(); dailyCanvas.width = $(dailyCanvas).parent().width();
@ -68,17 +68,17 @@ define('forum/flags/list', ['components', 'Chart'], function (components, Chart)
responsive: true, responsive: true,
animation: false, animation: false,
legend: { legend: {
display: false display: false,
}, },
scales: { scales: {
yAxes: [{ yAxes: [{
ticks: { ticks: {
beginAtZero: true, beginAtZero: true,
stepSize: 1 stepSize: 1,
} },
}] }],
} },
} },
}); });
}; };

@ -119,7 +119,7 @@ define('forum/topic/postTools', [
require(['flags'], function (flags) { require(['flags'], function (flags) {
flags.showFlagModal({ flags.showFlagModal({
type: 'post', type: 'post',
id: pid id: pid,
}); });
}); });
}); });

@ -72,7 +72,7 @@ module.exports = function (Categories) {
next(null, category); next(null, category);
}, },
function (category, next) { function (category, next) {
plugins.fireHook('action:category.create', {category: category}); plugins.fireHook('action:category.create', { category: category });
next(null, category); next(null, category);
}, },
], callback); ], callback);
@ -143,14 +143,14 @@ module.exports = function (Categories) {
plugins.fireHook('filter:categories.copyPrivilegesFrom', { plugins.fireHook('filter:categories.copyPrivilegesFrom', {
privileges: privileges.privilegeList, privileges: privileges.privilegeList,
fromCid: fromCid, fromCid: fromCid,
toCid: toCid toCid: toCid,
}, next); }, next);
}, },
function (data, next) { function (data, next) {
async.each(data.privileges, function (privilege, next) { async.each(data.privileges, function (privilege, next) {
copyPrivilege(privilege, data.fromCid, data.toCid, next); copyPrivilege(privilege, data.fromCid, data.toCid, next);
}, next); }, next);
} },
], callback); ], callback);
}; };

@ -30,7 +30,7 @@ module.exports = function (Categories) {
purgeCategory(cid, next); purgeCategory(cid, next);
}, },
function (next) { function (next) {
plugins.fireHook('action:category.delete', {cid: cid, uid: uid}); plugins.fireHook('action:category.delete', { cid: cid, uid: uid });
next(); next();
}, },
], callback); ], callback);

@ -124,7 +124,7 @@ helpers.getUserDataByUserSlug = function (userslug, callerUID, callback) {
other: !isSelf, other: !isSelf,
moderator: isModerator, moderator: isModerator,
globalMod: isGlobalModerator, globalMod: isGlobalModerator,
admin: isAdmin admin: isAdmin,
}); });
userData.sso = results.sso.associations; userData.sso = results.sso.associations;
@ -174,7 +174,7 @@ function filterLinks(links, states) {
other: true, other: true,
moderator: true, moderator: true,
globalMod: true, globalMod: true,
admin: true admin: true,
}, link.visibility); }, link.visibility);
// Iterate through states and permit if every test passes (or is not defined) // Iterate through states and permit if every test passes (or is not defined)

@ -127,12 +127,10 @@ function getUsers(set, section, min, max, req, res, next) {
count: function (next) { count: function (next) {
if (byScore) { if (byScore) {
db.sortedSetCount(set, min, max, next); db.sortedSetCount(set, min, max, next);
} else if (set === 'users:banned' || set === 'users:notvalidated') {
db.sortedSetCard(set, next);
} else { } else {
if (set === 'users:banned' || set === 'users:notvalidated') { db.getObjectField('global', 'userCount', next);
db.sortedSetCard(set, next);
} else {
db.getObjectField('global', 'userCount', next);
}
} }
}, },
users: function (next) { users: function (next) {

@ -330,7 +330,7 @@ authenticationController.onSuccessfulLogin = function (req, uid, callback) {
// Force session check for all connected socket.io clients with the same session id // Force session check for all connected socket.io clients with the same session id
sockets.in('sess_' + req.sessionID).emit('checkSession', uid); sockets.in('sess_' + req.sessionID).emit('checkSession', uid);
plugins.fireHook('action:user.loggedIn', {uid: uid, req: req}); plugins.fireHook('action:user.loggedIn', { uid: uid, req: req });
callback(); callback();
}); });
}; };

@ -8,7 +8,7 @@ var flags = require('../flags');
var analytics = require('../analytics'); var analytics = require('../analytics');
var modsController = { var modsController = {
flags: {} flags: {},
}; };
modsController.flags.list = function (req, res, next) { modsController.flags.list = function (req, res, next) {
@ -58,7 +58,7 @@ modsController.flags.list = function (req, res, next) {
async.parallel({ async.parallel({
flags: async.apply(flags.list, filters, req.uid), flags: async.apply(flags.list, filters, req.uid),
analytics: async.apply(analytics.getDailyStatsForSet, 'analytics:flags', Date.now(), 30), analytics: async.apply(analytics.getDailyStatsForSet, 'analytics:flags', Date.now(), 30),
categories: async.apply(categories.buildForSelect, req.uid) categories: async.apply(categories.buildForSelect, req.uid),
}, function (err, data) { }, function (err, data) {
if (err) { if (err) {
return next(err); return next(err);
@ -92,7 +92,7 @@ modsController.flags.list = function (req, res, next) {
categories: data.categories, categories: data.categories,
hasFilter: hasFilter, hasFilter: hasFilter,
filters: filters, filters: filters,
title: '[[pages:flags]]' title: '[[pages:flags]]',
}); });
}); });
}); });
@ -103,7 +103,7 @@ modsController.flags.detail = function (req, res, next) {
isAdminOrGlobalMod: async.apply(user.isAdminOrGlobalMod, req.uid), isAdminOrGlobalMod: async.apply(user.isAdminOrGlobalMod, req.uid),
moderatedCids: async.apply(user.getModeratedCids, req.uid), moderatedCids: async.apply(user.getModeratedCids, req.uid),
flagData: async.apply(flags.get, req.params.flagId), flagData: async.apply(flags.get, req.params.flagId),
assignees: async.apply(user.getAdminsandGlobalModsandModerators) assignees: async.apply(user.getAdminsandGlobalModsandModerators),
}, function (err, results) { }, function (err, results) {
if (err || !results.flagData) { if (err || !results.flagData) {
return next(err || new Error('[[error:invalid-data]]')); return next(err || new Error('[[error:invalid-data]]'));
@ -122,7 +122,7 @@ modsController.flags.detail = function (req, res, next) {
return memo; return memo;
}, {}), }, {}),
title: '[[pages:flag-details, ' + req.params.flagId + ']]' title: '[[pages:flag-details, ' + req.params.flagId + ']]',
})); }));
}); });
}; };

@ -24,13 +24,13 @@ Flags.get = function (flagId, callback) {
async.apply(async.parallel, { async.apply(async.parallel, {
base: async.apply(db.getObject.bind(db), 'flag:' + flagId), base: async.apply(db.getObject.bind(db), 'flag:' + flagId),
history: async.apply(Flags.getHistory, flagId), history: async.apply(Flags.getHistory, flagId),
notes: async.apply(Flags.getNotes, flagId) notes: async.apply(Flags.getNotes, flagId),
}), }),
function (data, next) { function (data, next) {
// Second stage // Second stage
async.parallel({ async.parallel({
userObj: async.apply(user.getUserFields, data.base.uid, ['username', 'userslug', 'picture']), userObj: async.apply(user.getUserFields, data.base.uid, ['username', 'userslug', 'picture']),
targetObj: async.apply(Flags.getTarget, data.base.type, data.base.targetId, data.base.uid) targetObj: async.apply(Flags.getTarget, data.base.type, data.base.targetId, data.base.uid),
}, function (err, payload) { }, function (err, payload) {
// Final object return construction // Final object return construction
next(err, Object.assign(data.base, { next(err, Object.assign(data.base, {
@ -39,10 +39,10 @@ Flags.get = function (flagId, callback) {
target: payload.targetObj, target: payload.targetObj,
history: data.history, history: data.history,
notes: data.notes, notes: data.notes,
reporter: payload.userObj reporter: payload.userObj,
})); }));
}); });
} },
], callback); ], callback);
}; };
@ -63,44 +63,44 @@ Flags.list = function (filters, uid, callback) {
}); });
} else { } else {
// Empty array, do nothing // Empty array, do nothing
return;
} }
}; };
if (Object.keys(filters).length > 0) { if (Object.keys(filters).length > 0) {
for (var type in filters) { for (var type in filters) {
switch (type) { switch (type) {
case 'type': case 'type':
prepareSets('flags:byType:', filters[type]); prepareSets('flags:byType:', filters[type]);
break; break;
case 'state': case 'state':
prepareSets('flags:byState:', filters[type]); prepareSets('flags:byState:', filters[type]);
break; break;
case 'reporterId':
prepareSets('flags:byReporter:', filters[type]);
break;
case 'assignee':
prepareSets('flags:byAssignee:', filters[type]);
break;
case 'targetUid': case 'reporterId':
prepareSets('flags:byTargetUid:', filters[type]); prepareSets('flags:byReporter:', filters[type]);
break; break;
case 'cid': case 'assignee':
prepareSets('flags:byCid:', filters[type]); prepareSets('flags:byAssignee:', filters[type]);
break; break;
case 'quick': case 'targetUid':
switch (filters.quick) { prepareSets('flags:byTargetUid:', filters[type]);
case 'mine': break;
sets.push('flags:byAssignee:' + uid);
break; case 'cid':
} prepareSets('flags:byCid:', filters[type]);
break;
case 'quick':
switch (filters.quick) {
case 'mine':
sets.push('flags:byAssignee:' + uid);
break; break;
}
break;
} }
} }
} }
@ -147,38 +147,38 @@ Flags.list = function (filters, uid, callback) {
username: userObj.username, username: userObj.username,
picture: userObj.picture, picture: userObj.picture,
'icon:bgColor': userObj['icon:bgColor'], 'icon:bgColor': userObj['icon:bgColor'],
'icon:text': userObj['icon:text'] 'icon:text': userObj['icon:text'],
} },
})); }));
}); });
} },
], function (err, flagObj) { ], function (err, flagObj) {
if (err) { if (err) {
return next(err); return next(err);
} }
switch(flagObj.state) { switch (flagObj.state) {
case 'open': case 'open':
flagObj.labelClass = 'info'; flagObj.labelClass = 'info';
break; break;
case 'wip': case 'wip':
flagObj.labelClass = 'warning'; flagObj.labelClass = 'warning';
break; break;
case 'resolved': case 'resolved':
flagObj.labelClass = 'success'; flagObj.labelClass = 'success';
break; break;
case 'rejected': case 'rejected':
flagObj.labelClass = 'danger'; flagObj.labelClass = 'danger';
break; break;
} }
next(null, Object.assign(flagObj, { next(null, Object.assign(flagObj, {
target_readable: flagObj.type.charAt(0).toUpperCase() + flagObj.type.slice(1) + ' ' + flagObj.targetId, target_readable: flagObj.type.charAt(0).toUpperCase() + flagObj.type.slice(1) + ' ' + flagObj.targetId,
datetimeISO: new Date(parseInt(flagObj.datetime, 10)).toISOString() datetimeISO: new Date(parseInt(flagObj.datetime, 10)).toISOString(),
})); }));
}); });
}, next); }, next);
} },
], callback); ], callback);
}; };
@ -186,7 +186,7 @@ Flags.validate = function (payload, callback) {
async.parallel({ async.parallel({
targetExists: async.apply(Flags.targetExists, payload.type, payload.id), targetExists: async.apply(Flags.targetExists, payload.type, payload.id),
target: async.apply(Flags.getTarget, payload.type, payload.id, payload.uid), target: async.apply(Flags.getTarget, payload.type, payload.id, payload.uid),
reporter: async.apply(user.getUserData, payload.uid) reporter: async.apply(user.getUserData, payload.uid),
}, function (err, data) { }, function (err, data) {
if (err) { if (err) {
return callback(err); return callback(err);
@ -199,42 +199,42 @@ Flags.validate = function (payload, callback) {
} }
switch (payload.type) { switch (payload.type) {
case 'post': case 'post':
privileges.posts.canEdit(payload.id, payload.uid, function (err, editable) { privileges.posts.canEdit(payload.id, payload.uid, function (err, editable) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
var minimumReputation = utils.isNumber(meta.config['privileges:flag']) ? parseInt(meta.config['privileges:flag'], 10) : 1; var minimumReputation = utils.isNumber(meta.config['privileges:flag']) ? parseInt(meta.config['privileges:flag'], 10) : 1;
// Check if reporter meets rep threshold (or can edit the target post, in which case threshold does not apply) // Check if reporter meets rep threshold (or can edit the target post, in which case threshold does not apply)
if (!editable.flag && parseInt(data.reporter.reputation, 10) < minimumReputation) { if (!editable.flag && parseInt(data.reporter.reputation, 10) < minimumReputation) {
return callback(new Error('[[error:not-enough-reputation-to-flag]]')); return callback(new Error('[[error:not-enough-reputation-to-flag]]'));
} }
callback(); callback();
}); });
break; break;
case 'user':
privileges.users.canEdit(payload.uid, payload.id, function (err, editable) {
if (err) {
return callback(err);
}
var minimumReputation = utils.isNumber(meta.config['privileges:flag']) ? parseInt(meta.config['privileges:flag'], 10) : 1; case 'user':
privileges.users.canEdit(payload.uid, payload.id, function (err, editable) {
if (err) {
return callback(err);
}
var minimumReputation = utils.isNumber(meta.config['privileges:flag']) ? parseInt(meta.config['privileges:flag'], 10) : 1;
// Check if reporter meets rep threshold (or can edit the target user, in which case threshold does not apply) // Check if reporter meets rep threshold (or can edit the target user, in which case threshold does not apply)
if (!editable && parseInt(data.reporter.reputation, 10) < minimumReputation) { if (!editable && parseInt(data.reporter.reputation, 10) < minimumReputation) {
return callback(new Error('[[error:not-enough-reputation-to-flag]]')); return callback(new Error('[[error:not-enough-reputation-to-flag]]'));
} }
callback(); callback();
}); });
break; break;
default: default:
callback(new Error('[[error:invalid-data]]')); callback(new Error('[[error:invalid-data]]'));
break; break;
} }
}); });
}; };
@ -252,7 +252,7 @@ Flags.getNotes = function (flagId, callback) {
uid: noteObj[0], uid: noteObj[0],
content: noteObj[1], content: noteObj[1],
datetime: note.score, datetime: note.score,
datetimeISO: new Date(parseInt(note.score, 10)).toISOString() datetimeISO: new Date(parseInt(note.score, 10)).toISOString(),
}; };
} catch (e) { } catch (e) {
return next(e); return next(e);
@ -271,7 +271,7 @@ Flags.getNotes = function (flagId, callback) {
return note; return note;
})); }));
}); });
} },
], callback); ], callback);
}; };
@ -296,7 +296,7 @@ Flags.create = function (type, id, uid, reason, timestamp, callback) {
// Extra data for zset insertion // Extra data for zset insertion
async.apply(Flags.getTargetUid, type, id), async.apply(Flags.getTargetUid, type, id),
async.apply(Flags.getTargetCid, type, id) async.apply(Flags.getTargetCid, type, id),
], function (err, checks) { ], function (err, checks) {
if (err) { if (err) {
return next(err); return next(err);
@ -309,9 +309,8 @@ Flags.create = function (type, id, uid, reason, timestamp, callback) {
return next(new Error('[[error:already-flagged]]')); return next(new Error('[[error:already-flagged]]'));
} else if (!checks[1]) { } else if (!checks[1]) {
return next(new Error('[[error:invalid-data]]')); return next(new Error('[[error:invalid-data]]'));
} else {
next();
} }
next();
}); });
}, },
async.apply(db.incrObjectField, 'global', 'nextFlagId'), async.apply(db.incrObjectField, 'global', 'nextFlagId'),
@ -323,13 +322,13 @@ Flags.create = function (type, id, uid, reason, timestamp, callback) {
targetId: id, targetId: id,
description: reason, description: reason,
uid: uid, uid: uid,
datetime: timestamp datetime: timestamp,
}), }),
async.apply(db.sortedSetAdd.bind(db), 'flags:datetime', timestamp, flagId), // by time, the default async.apply(db.sortedSetAdd.bind(db), 'flags:datetime', timestamp, flagId), // by time, the default
async.apply(db.sortedSetAdd.bind(db), 'flags:byReporter:' + uid, timestamp, flagId), // by reporter async.apply(db.sortedSetAdd.bind(db), 'flags:byReporter:' + uid, timestamp, flagId), // by reporter
async.apply(db.sortedSetAdd.bind(db), 'flags:byType:' + type, timestamp, flagId), // by flag type async.apply(db.sortedSetAdd.bind(db), 'flags:byType:' + type, timestamp, flagId), // by flag type
async.apply(db.sortedSetAdd.bind(db), 'flags:hash', flagId, [type, id, uid].join(':')), // save zset for duplicate checking async.apply(db.sortedSetAdd.bind(db), 'flags:hash', flagId, [type, id, uid].join(':')), // save zset for duplicate checking
async.apply(analytics.increment, 'flags') // some fancy analytics async.apply(analytics.increment, 'flags'), // some fancy analytics
]; ];
if (targetUid) { if (targetUid) {
@ -341,20 +340,20 @@ Flags.create = function (type, id, uid, reason, timestamp, callback) {
if (type === 'post') { if (type === 'post') {
tasks.push(async.apply(db.sortedSetAdd.bind(db), 'flags:byPid:' + id, timestamp, flagId)); // by target pid tasks.push(async.apply(db.sortedSetAdd.bind(db), 'flags:byPid:' + id, timestamp, flagId)); // by target pid
} }
async.parallel(tasks, function (err, data) { async.parallel(tasks, function (err, data) {
if (err) { if (err) {
return next(err); return next(err);
} }
if (doHistoryAppend) { if (doHistoryAppend) {
Flags.update(flagId, uid, { "state": "open" }); Flags.update(flagId, uid, { state: 'open' });
} }
next(null, flagId); next(null, flagId);
}); });
}, },
async.apply(Flags.get) async.apply(Flags.get),
], callback); ], callback);
}; };
@ -368,72 +367,72 @@ Flags.getTarget = function (type, id, uid, callback) {
function (exists, next) { function (exists, next) {
if (exists) { if (exists) {
switch (type) { switch (type) {
case 'post': case 'post':
async.waterfall([ async.waterfall([
async.apply(posts.getPostsByPids, [id], uid), async.apply(posts.getPostsByPids, [id], uid),
function (posts, next) { function (posts, next) {
topics.addPostData(posts, uid, next); topics.addPostData(posts, uid, next);
} },
], function (err, posts) { ], function (err, posts) {
next(err, posts[0]); next(err, posts[0]);
}); });
break; break;
case 'user': case 'user':
user.getUsersData([id], function (err, users) { user.getUsersData([id], function (err, users) {
next(err, users ? users[0] : undefined); next(err, users ? users[0] : undefined);
}); });
break; break;
default: default:
next(new Error('[[error:invalid-data]]')); next(new Error('[[error:invalid-data]]'));
break; break;
} }
} else { } else {
// Target used to exist (otherwise flag creation'd fail), but no longer // Target used to exist (otherwise flag creation'd fail), but no longer
next(null, {}); next(null, {});
} }
} },
], callback); ], callback);
}; };
Flags.targetExists = function (type, id, callback) { Flags.targetExists = function (type, id, callback) {
switch (type) { switch (type) {
case 'post': case 'post':
posts.exists(id, callback); posts.exists(id, callback);
break; break;
case 'user':
user.exists(id, callback);
break;
default: case 'user':
callback(new Error('[[error:invalid-data]]')); user.exists(id, callback);
break; break;
default:
callback(new Error('[[error:invalid-data]]'));
break;
} }
}; };
Flags.getTargetUid = function (type, id, callback) { Flags.getTargetUid = function (type, id, callback) {
switch (type) { switch (type) {
case 'post': case 'post':
posts.getPostField(id, 'uid', callback); posts.getPostField(id, 'uid', callback);
break; break;
default: default:
setImmediate(callback, null, id); setImmediate(callback, null, id);
break; break;
} }
}; };
Flags.getTargetCid = function (type, id, callback) { Flags.getTargetCid = function (type, id, callback) {
switch (type) { switch (type) {
case 'post': case 'post':
posts.getCidByPid(id, callback); posts.getCidByPid(id, callback);
break; break;
default: default:
setImmediate(callback, null, id); setImmediate(callback, null, id);
break; break;
} }
}; };
@ -453,14 +452,14 @@ Flags.update = function (flagId, uid, changeset, callback) {
} else { } else {
// Add tasks as necessary // Add tasks as necessary
switch (prop) { switch (prop) {
case 'state': case 'state':
tasks.push(async.apply(db.sortedSetAdd.bind(db), 'flags:byState:' + changeset[prop], now, flagId)); tasks.push(async.apply(db.sortedSetAdd.bind(db), 'flags:byState:' + changeset[prop], now, flagId));
tasks.push(async.apply(db.sortedSetRemove.bind(db), 'flags:byState:' + current[prop], flagId)); tasks.push(async.apply(db.sortedSetRemove.bind(db), 'flags:byState:' + current[prop], flagId));
break; break;
case 'assignee': case 'assignee':
tasks.push(async.apply(db.sortedSetAdd.bind(db), 'flags:byAssignee:' + changeset[prop], now, flagId)); tasks.push(async.apply(db.sortedSetAdd.bind(db), 'flags:byAssignee:' + changeset[prop], now, flagId));
break; break;
} }
} }
} }
@ -483,7 +482,7 @@ Flags.update = function (flagId, uid, changeset, callback) {
async.parallel(tasks, function (err, data) { async.parallel(tasks, function (err, data) {
return next(err); return next(err);
}); });
} },
], callback); ], callback);
}; };
@ -512,12 +511,12 @@ Flags.getHistory = function (flagId, callback) {
uid: entry.value[0], uid: entry.value[0],
fields: changeset, fields: changeset,
datetime: entry.score, datetime: entry.score,
datetimeISO: new Date(parseInt(entry.score, 10)).toISOString() datetimeISO: new Date(parseInt(entry.score, 10)).toISOString(),
}; };
}); });
user.getUsersFields(uids, ['username', 'userslug', 'picture'], next); user.getUsersFields(uids, ['username', 'userslug', 'picture'], next);
} },
], function (err, users) { ], function (err, users) {
if (err) { if (err) {
return callback(err); return callback(err);
@ -564,8 +563,8 @@ Flags.appendNote = function (flagId, uid, note, datetime, callback) {
async.apply(db.sortedSetAdd, 'flag:' + flagId + ':notes', datetime, payload), async.apply(db.sortedSetAdd, 'flag:' + flagId + ':notes', datetime, payload),
async.apply(Flags.appendHistory, flagId, uid, { async.apply(Flags.appendHistory, flagId, uid, {
notes: null, notes: null,
datetime: datetime datetime: datetime,
}) }),
], callback); ], callback);
}; };
@ -576,88 +575,88 @@ Flags.notify = function (flagObj, uid, callback) {
} }
switch (flagObj.type) { switch (flagObj.type) {
case 'post': case 'post':
async.parallel({ async.parallel({
post: function (next) { post: function (next) {
async.waterfall([ async.waterfall([
async.apply(posts.getPostData, flagObj.targetId), async.apply(posts.getPostData, flagObj.targetId),
async.apply(posts.parsePost) async.apply(posts.parsePost),
], next); ], next);
}, },
title: async.apply(topics.getTitleByPid, flagObj.targetId), title: async.apply(topics.getTitleByPid, flagObj.targetId),
admins: async.apply(groups.getMembers, 'administrators', 0, -1), admins: async.apply(groups.getMembers, 'administrators', 0, -1),
globalMods: async.apply(groups.getMembers, 'Global Moderators', 0, -1), globalMods: async.apply(groups.getMembers, 'Global Moderators', 0, -1),
moderators: function (next) { moderators: function (next) {
async.waterfall([ async.waterfall([
async.apply(posts.getCidByPid, flagObj.targetId), async.apply(posts.getCidByPid, flagObj.targetId),
function (cid, next) { function (cid, next) {
groups.getMembers('cid:' + cid + ':privileges:mods', 0, -1, next); groups.getMembers('cid:' + cid + ':privileges:mods', 0, -1, next);
} },
], next); ], next);
} },
}, function (err, results) { }, function (err, results) {
if (err) { if (err) {
return callback(err);
}
var title = S(results.title).decodeHTMLEntities().s;
var titleEscaped = title.replace(/%/g, '&#37;').replace(/,/g, '&#44;');
notifications.create({
bodyShort: '[[notifications:user_flagged_post_in, ' + flagObj.reporter.username + ', ' + titleEscaped + ']]',
bodyLong: flagObj.description,
pid: flagObj.targetId,
path: '/post/' + flagObj.targetId,
nid: 'flag:post:' + flagObj.targetId + ':uid:' + uid,
from: uid,
mergeId: 'notifications:user_flagged_post_in|' + flagObj.targetId,
topicTitle: results.title,
}, function (err, notification) {
if (err || !notification) {
return callback(err); return callback(err);
} }
var title = S(results.title).decodeHTMLEntities().s; plugins.fireHook('action:flag.create', {
var titleEscaped = title.replace(/%/g, '&#37;').replace(/,/g, '&#44;'); flag: flagObj,
notifications.create({
bodyShort: '[[notifications:user_flagged_post_in, ' + flagObj.reporter.username + ', ' + titleEscaped + ']]',
bodyLong: flagObj.description,
pid: flagObj.targetId,
path: '/post/' + flagObj.targetId,
nid: 'flag:post:' + flagObj.targetId + ':uid:' + uid,
from: uid,
mergeId: 'notifications:user_flagged_post_in|' + flagObj.targetId,
topicTitle: results.title
}, function (err, notification) {
if (err || !notification) {
return callback(err);
}
plugins.fireHook('action:flag.create', {
flag: flagObj
});
notifications.push(notification, results.admins.concat(results.moderators).concat(results.globalMods), callback);
}); });
notifications.push(notification, results.admins.concat(results.moderators).concat(results.globalMods), callback);
}); });
break; });
break;
case 'user':
async.parallel({
admins: async.apply(groups.getMembers, 'administrators', 0, -1),
globalMods: async.apply(groups.getMembers, 'Global Moderators', 0, -1),
}, function (err, results) {
if (err) {
return callback(err);
}
case 'user': notifications.create({
async.parallel({ bodyShort: '[[notifications:user_flagged_user, ' + flagObj.reporter.username + ', ' + flagObj.target.username + ']]',
admins: async.apply(groups.getMembers, 'administrators', 0, -1), bodyLong: flagObj.description,
globalMods: async.apply(groups.getMembers, 'Global Moderators', 0, -1), path: '/uid/' + flagObj.targetId,
}, function (err, results) { nid: 'flag:user:' + flagObj.targetId + ':uid:' + uid,
if (err) { from: uid,
mergeId: 'notifications:user_flagged_user|' + flagObj.targetId,
}, function (err, notification) {
if (err || !notification) {
return callback(err); return callback(err);
} }
notifications.create({ plugins.fireHook('action:flag.create', {
bodyShort: '[[notifications:user_flagged_user, ' + flagObj.reporter.username + ', ' + flagObj.target.username + ']]', flag: flagObj,
bodyLong: flagObj.description,
path: '/uid/' + flagObj.targetId,
nid: 'flag:user:' + flagObj.targetId + ':uid:' + uid,
from: uid,
mergeId: 'notifications:user_flagged_user|' + flagObj.targetId
}, function (err, notification) {
if (err || !notification) {
return callback(err);
}
plugins.fireHook('action:flag.create', {
flag: flagObj
});
notifications.push(notification, results.admins.concat(results.globalMods), callback);
}); });
notifications.push(notification, results.admins.concat(results.globalMods), callback);
}); });
break; });
break;
default:
callback(new Error('[[error:invalid-data]]')); default:
break; callback(new Error('[[error:invalid-data]]'));
break;
} }
}; };
module.exports = Flags; module.exports = Flags;

@ -69,7 +69,7 @@ module.exports = function (Groups) {
async.series(tasks, next); async.series(tasks, next);
}, },
function (results, next) { function (results, next) {
plugins.fireHook('action:group.create', {group: groupData}); plugins.fireHook('action:group.create', { group: groupData });
next(null, groupData); next(null, groupData);
}, },
], callback); ], callback);

@ -42,7 +42,7 @@ module.exports = function (Groups) {
return callback(err); return callback(err);
} }
Groups.resetCache(); Groups.resetCache();
plugins.fireHook('action:group.destroy', {group: groupObj}); plugins.fireHook('action:group.destroy', { group: groupObj });
callback(); callback();
}); });
}); });

@ -20,7 +20,7 @@ Minifier.js.minify = function (scripts, minify, callback) {
if (err) { if (err) {
return next(err); return next(err);
} }
if (!exists) { if (!exists) {
console.warn('[minifier] file not found, ' + script); console.warn('[minifier] file not found, ' + script);
} }
@ -30,7 +30,7 @@ Minifier.js.minify = function (scripts, minify, callback) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
if (minify) { if (minify) {
minifyScripts(scripts, callback); minifyScripts(scripts, callback);
} else { } else {

@ -86,9 +86,8 @@ middleware.ensureSelfOrPrivileged = function (req, res, next) {
return next(err); return next(err);
} else if (ok) { } else if (ok) {
return next(); return next();
} else {
controllers.helpers.notAllowed(req, res);
} }
controllers.helpers.notAllowed(req, res);
}); });
} else { } else {
controllers.helpers.notAllowed(req, res); controllers.helpers.notAllowed(req, res);

@ -155,7 +155,7 @@ var plugins = require('./plugins');
pid: pid, pid: pid,
}; };
data[field] = value; data[field] = value;
plugins.fireHook('action:post.setFields', {data: data}); plugins.fireHook('action:post.setFields', { data: data });
callback(); callback();
}); });
}; };
@ -166,7 +166,7 @@ var plugins = require('./plugins');
return callback(err); return callback(err);
} }
data.pid = pid; data.pid = pid;
plugins.fireHook('action:post.setFields', {data: data}); plugins.fireHook('action:post.setFields', { data: data });
callback(); callback();
}); });
}; };

@ -106,7 +106,7 @@ module.exports = function (Posts) {
}, },
function (postData, next) { function (postData, next) {
postData.isMain = isMain; postData.isMain = isMain;
plugins.fireHook('action:post.save', {post: _.clone(postData)}); plugins.fireHook('action:post.save', { post: _.clone(postData) });
next(null, postData); next(null, postData);
}, },
], callback); ], callback);

@ -65,7 +65,7 @@ module.exports = function (Posts) {
postData.cid = results.topic.cid; postData.cid = results.topic.cid;
postData.topic = results.topic; postData.topic = results.topic;
plugins.fireHook('action:post.edit', {post: _.clone(postData), uid: data.uid}); plugins.fireHook('action:post.edit', { post: _.clone(postData), uid: data.uid });
cache.del(String(postData.pid)); cache.del(String(postData.pid));
pubsub.publish('post:edit', String(postData.pid)); pubsub.publish('post:edit', String(postData.pid));
@ -136,7 +136,7 @@ module.exports = function (Posts) {
function (tags, next) { function (tags, next) {
topicData.tags = data.tags; topicData.tags = data.tags;
topicData.oldTitle = results.topic.title; topicData.oldTitle = results.topic.title;
plugins.fireHook('action:topic.edit', {topic: topicData, uid: data.uid}); plugins.fireHook('action:topic.edit', { topic: topicData, uid: data.uid });
next(null, { next(null, {
tid: tid, tid: tid,
cid: results.topic.cid, cid: results.topic.cid,

@ -29,12 +29,12 @@ SocketFlags.create = function (socket, data, callback) {
async.apply(flags.validate, { async.apply(flags.validate, {
uid: socket.uid, uid: socket.uid,
type: data.type, type: data.type,
id: data.id id: data.id,
}), }),
function (next) { function (next) {
// If we got here, then no errors occurred // If we got here, then no errors occurred
flags.create(data.type, data.id, socket.uid, data.reason, next); flags.create(data.type, data.id, socket.uid, data.reason, next);
} },
], function (err, flagObj) { ], function (err, flagObj) {
if (err) { if (err) {
return callback(err); return callback(err);
@ -56,7 +56,7 @@ SocketFlags.update = function (socket, data, callback) {
function (next) { function (next) {
async.parallel([ async.parallel([
async.apply(user.isAdminOrGlobalMod, socket.uid), async.apply(user.isAdminOrGlobalMod, socket.uid),
async.apply(user.isModeratorOfAnyCategory, socket.uid) async.apply(user.isModeratorOfAnyCategory, socket.uid),
], function (err, results) { ], function (err, results) {
next(err, results[0] || results[1]); next(err, results[0] || results[1]);
}); });
@ -74,7 +74,7 @@ SocketFlags.update = function (socket, data, callback) {
flags.update(data.flagId, socket.uid, payload, next); flags.update(data.flagId, socket.uid, payload, next);
}, },
async.apply(flags.getHistory, data.flagId) async.apply(flags.getHistory, data.flagId),
], callback); ], callback);
}; };
@ -87,7 +87,7 @@ SocketFlags.appendNote = function (socket, data, callback) {
function (next) { function (next) {
async.parallel([ async.parallel([
async.apply(user.isAdminOrGlobalMod, socket.uid), async.apply(user.isAdminOrGlobalMod, socket.uid),
async.apply(user.isModeratorOfAnyCategory, socket.uid) async.apply(user.isModeratorOfAnyCategory, socket.uid),
], function (err, results) { ], function (err, results) {
next(err, results[0] || results[1]); next(err, results[0] || results[1]);
}); });
@ -101,10 +101,10 @@ SocketFlags.appendNote = function (socket, data, callback) {
}, },
function (next) { function (next) {
async.parallel({ async.parallel({
"notes": async.apply(flags.getNotes, data.flagId), notes: async.apply(flags.getNotes, data.flagId),
"history": async.apply(flags.getHistory, data.flagId) history: async.apply(flags.getHistory, data.flagId),
}, next); }, next);
} },
], callback); ], callback);
}; };

@ -95,7 +95,7 @@ module.exports = function (SocketTopics) {
var start = parseInt(data.after, 10); var start = parseInt(data.after, 10);
var stop = start + 9; var stop = start + 9;
topics.getUnreadTopics({cid: data.cid, uid: socket.uid, start: start, stop: stop, filter: data.filter}, callback); topics.getUnreadTopics({ cid: data.cid, uid: socket.uid, start: start, stop: stop, filter: data.filter }, callback);
}; };
SocketTopics.loadMoreRecentTopics = function (socket, data, callback) { SocketTopics.loadMoreRecentTopics = function (socket, data, callback) {

@ -50,7 +50,7 @@ module.exports = function (SocketTopics) {
SocketTopics.markCategoryTopicsRead = function (socket, cid, callback) { SocketTopics.markCategoryTopicsRead = function (socket, cid, callback) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
topics.getUnreadTids({cid: cid, uid: socket.uid, filter: ''}, next); topics.getUnreadTids({ cid: cid, uid: socket.uid, filter: '' }, next);
}, },
function (tids, next) { function (tids, next) {
SocketTopics.markAsRead(socket, tids, next); SocketTopics.markAsRead(socket, tids, next);

@ -82,7 +82,7 @@ module.exports = function (Topics) {
], next); ], next);
}, },
function (results, next) { function (results, next) {
plugins.fireHook('action:topic.save', {topic: _.clone(topicData)}); plugins.fireHook('action:topic.save', { topic: _.clone(topicData) });
next(null, topicData.tid); next(null, topicData.tid);
}, },
], callback); ], callback);
@ -174,7 +174,7 @@ module.exports = function (Topics) {
data.postData.index = 0; data.postData.index = 0;
analytics.increment(['topics', 'topics:byCid:' + data.topicData.cid]); analytics.increment(['topics', 'topics:byCid:' + data.topicData.cid]);
plugins.fireHook('action:topic.post', {topic: data.topicData, post: data.postData}); plugins.fireHook('action:topic.post', { topic: data.topicData, post: data.postData });
if (parseInt(uid, 10)) { if (parseInt(uid, 10)) {
user.notifications.sendTopicNotificationToFollowers(uid, data.topicData, data.postData); user.notifications.sendTopicNotificationToFollowers(uid, data.topicData, data.postData);
@ -269,7 +269,7 @@ module.exports = function (Topics) {
Topics.notifyFollowers(postData, uid); Topics.notifyFollowers(postData, uid);
analytics.increment(['posts', 'posts:byCid:' + cid]); analytics.increment(['posts', 'posts:byCid:' + cid]);
plugins.fireHook('action:topic.reply', {post: _.clone(postData)}); plugins.fireHook('action:topic.reply', { post: _.clone(postData) });
next(null, postData); next(null, postData);
}, },

@ -334,11 +334,11 @@ Upgrade.upgrade = function (callback) {
posts = posts.filter(function (post) { posts = posts.filter(function (post) {
return post.hasOwnProperty('flags'); return post.hasOwnProperty('flags');
}); });
async.each(posts, function (post, next) { async.each(posts, function (post, next) {
async.parallel({ async.parallel({
uids: async.apply(db.getSortedSetRangeWithScores, 'pid:' + post.pid + ':flag:uids', 0, -1), uids: async.apply(db.getSortedSetRangeWithScores, 'pid:' + post.pid + ':flag:uids', 0, -1),
reasons: async.apply(db.getSortedSetRange, 'pid:' + post.pid + ':flag:uid:reason', 0, -1) reasons: async.apply(db.getSortedSetRange, 'pid:' + post.pid + ':flag:uid:reason', 0, -1),
}, function (err, data) { }, function (err, data) {
if (err) { if (err) {
return next(err); return next(err);
@ -362,7 +362,7 @@ Upgrade.upgrade = function (callback) {
flags.update(flagObj.flagId, 1, { flags.update(flagObj.flagId, 1, {
state: post['flag:state'], state: post['flag:state'],
assignee: post['flag:assignee'], assignee: post['flag:assignee'],
datetime: datetime datetime: datetime,
}, next); }, next);
} else { } else {
setImmediate(next); setImmediate(next);
@ -383,7 +383,7 @@ Upgrade.upgrade = function (callback) {
} else { } else {
setImmediate(next); setImmediate(next);
} }
} },
], function (err) { ], function (err) {
if (err && err.message === '[[error:already-flagged]]') { if (err && err.message === '[[error:already-flagged]]') {
// Already flagged, no need to parse, but not an error // Already flagged, no need to parse, but not an error
@ -407,7 +407,7 @@ Upgrade.upgrade = function (callback) {
winston.info('[2016/12/07] Migrating flags to new schema (#5232) - skipped!'); winston.info('[2016/12/07] Migrating flags to new schema (#5232) - skipped!');
next(); next();
} }
} },
// Add new schema updates here // Add new schema updates here
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!! // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!!
], function (err) { ], function (err) {

@ -258,7 +258,7 @@ var meta = require('./meta');
async.parallel([ async.parallel([
async.apply(User.isAdministrator, uid), async.apply(User.isAdministrator, uid),
async.apply(User.isGlobalModerator, uid), async.apply(User.isGlobalModerator, uid),
async.apply(User.isModeratorOfAnyCategory, uid) async.apply(User.isModeratorOfAnyCategory, uid),
], function (err, results) { ], function (err, results) {
callback(err, results ? results.some(Boolean) : false); callback(err, results ? results.some(Boolean) : false);
}); });

@ -140,7 +140,7 @@ module.exports = function (User) {
if (userNameChanged) { if (userNameChanged) {
User.notifications.sendNameChangeNotification(userData.uid, userData.username); User.notifications.sendNameChangeNotification(userData.uid, userData.username);
} }
plugins.fireHook('action:user.create', {user: userData}); plugins.fireHook('action:user.create', { user: userData });
next(null, userData.uid); next(null, userData.uid);
}, },
], callback); ], callback);

@ -1,5 +1,6 @@
'use strict'; 'use strict';
/*globals require, before, after, describe, it*/
/* globals require, before, after, describe, it*/
var assert = require('assert'); var assert = require('assert');
var async = require('async'); var async = require('async');
@ -17,10 +18,10 @@ describe('Flags', function () {
before(function (done) { before(function (done) {
// Create some stuff to flag // Create some stuff to flag
async.waterfall([ async.waterfall([
async.apply(User.create, {username: 'testUser', password: 'abcdef', email: 'b@c.com'}), async.apply(User.create, { username: 'testUser', password: 'abcdef', email: 'b@c.com' }),
function (uid, next) { function (uid, next) {
Categories.create({ Categories.create({
name: 'test category' name: 'test category',
}, function (err, category) { }, function (err, category) {
if (err) { if (err) {
return done(err); return done(err);
@ -30,13 +31,13 @@ describe('Flags', function () {
cid: category.cid, cid: category.cid,
uid: uid, uid: uid,
title: 'Topic to flag', title: 'Topic to flag',
content: 'This is flaggable content' content: 'This is flaggable content',
}, next); }, next);
}); });
}, },
function (topicData, next) { function (topicData, next) {
User.create({ User.create({
username: 'testUser2', password: 'abcdef', email: 'c@d.com' username: 'testUser2', password: 'abcdef', email: 'c@d.com',
}, next); }, next);
}, },
function (uid, next) { function (uid, next) {
@ -44,9 +45,9 @@ describe('Flags', function () {
}, },
function (next) { function (next) {
User.create({ User.create({
username: 'unprivileged', password: 'abcdef', email: 'd@e.com' username: 'unprivileged', password: 'abcdef', email: 'd@e.com',
}, next); }, next);
} },
], done); ], done);
}); });
@ -59,10 +60,10 @@ describe('Flags', function () {
uid: 1, uid: 1,
targetId: 1, targetId: 1,
type: 'post', type: 'post',
description: 'Test flag' description: 'Test flag',
}; };
for(var key in compare) { for (var key in compare) {
if (compare.hasOwnProperty(key)) { if (compare.hasOwnProperty(key)) {
assert.ok(flagData[key]); assert.ok(flagData[key]);
assert.equal(flagData[key], compare[key]); assert.equal(flagData[key], compare[key]);
@ -136,10 +137,10 @@ describe('Flags', function () {
targetId: 1, targetId: 1,
type: 'post', type: 'post',
description: 'Test flag', description: 'Test flag',
state: 'open' state: 'open',
}; };
for(var key in compare) { for (var key in compare) {
if (compare.hasOwnProperty(key)) { if (compare.hasOwnProperty(key)) {
assert.ok(flagData[key]); assert.ok(flagData[key]);
assert.equal(flagData[key], compare[key]); assert.equal(flagData[key], compare[key]);
@ -157,7 +158,7 @@ describe('Flags', function () {
assert.ifError(err); assert.ifError(err);
assert.ok(Array.isArray(flags)); assert.ok(Array.isArray(flags));
assert.equal(flags.length, 1); assert.equal(flags.length, 1);
Flags.get(flags[0].flagId, function (err, flagData) { Flags.get(flags[0].flagId, function (err, flagData) {
assert.ifError(err); assert.ifError(err);
assert.equal(flags[0].flagId, flagData.flagId); assert.equal(flags[0].flagId, flagData.flagId);
@ -170,7 +171,7 @@ describe('Flags', function () {
describe('(with filters)', function () { describe('(with filters)', function () {
it('should return a filtered list of flags if said filters are passed in', function (done) { it('should return a filtered list of flags if said filters are passed in', function (done) {
Flags.list({ Flags.list({
state: 'open' state: 'open',
}, 1, function (err, flags) { }, 1, function (err, flags) {
assert.ifError(err); assert.ifError(err);
assert.ok(Array.isArray(flags)); assert.ok(Array.isArray(flags));
@ -181,7 +182,7 @@ describe('Flags', function () {
it('should return no flags if a filter with no matching flags is used', function (done) { it('should return no flags if a filter with no matching flags is used', function (done) {
Flags.list({ Flags.list({
state: 'rejected' state: 'rejected',
}, 1, function (err, flags) { }, 1, function (err, flags) {
assert.ifError(err); assert.ifError(err);
assert.ok(Array.isArray(flags)); assert.ok(Array.isArray(flags));
@ -192,7 +193,7 @@ describe('Flags', function () {
it('should return a flag when filtered by cid 1', function (done) { it('should return a flag when filtered by cid 1', function (done) {
Flags.list({ Flags.list({
cid: 1 cid: 1,
}, 1, function (err, flags) { }, 1, function (err, flags) {
assert.ifError(err); assert.ifError(err);
assert.ok(Array.isArray(flags)); assert.ok(Array.isArray(flags));
@ -203,7 +204,7 @@ describe('Flags', function () {
it('shouldn\'t return a flag when filtered by cid 2', function (done) { it('shouldn\'t return a flag when filtered by cid 2', function (done) {
Flags.list({ Flags.list({
cid: 2 cid: 2,
}, 1, function (err, flags) { }, 1, function (err, flags) {
assert.ifError(err); assert.ifError(err);
assert.ok(Array.isArray(flags)); assert.ok(Array.isArray(flags));
@ -214,7 +215,7 @@ describe('Flags', function () {
it('should return a flag when filtered by both cid 1 and 2', function (done) { it('should return a flag when filtered by both cid 1 and 2', function (done) {
Flags.list({ Flags.list({
cid: [1, 2] cid: [1, 2],
}, 1, function (err, flags) { }, 1, function (err, flags) {
assert.ifError(err); assert.ifError(err);
assert.ok(Array.isArray(flags)); assert.ok(Array.isArray(flags));
@ -226,7 +227,7 @@ describe('Flags', function () {
it('should return one flag if filtered by both cid 1 and 2 and open state', function (done) { it('should return one flag if filtered by both cid 1 and 2 and open state', function (done) {
Flags.list({ Flags.list({
cid: [1, 2], cid: [1, 2],
state: 'open' state: 'open',
}, 1, function (err, flags) { }, 1, function (err, flags) {
assert.ifError(err); assert.ifError(err);
assert.ok(Array.isArray(flags)); assert.ok(Array.isArray(flags));
@ -238,7 +239,7 @@ describe('Flags', function () {
it('should return no flag if filtered by both cid 1 and 2 and non-open state', function (done) { it('should return no flag if filtered by both cid 1 and 2 and non-open state', function (done) {
Flags.list({ Flags.list({
cid: [1, 2], cid: [1, 2],
state: 'resolved' state: 'resolved',
}, 1, function (err, flags) { }, 1, function (err, flags) {
assert.ifError(err); assert.ifError(err);
assert.ok(Array.isArray(flags)); assert.ok(Array.isArray(flags));
@ -252,8 +253,8 @@ describe('Flags', function () {
describe('.update()', function () { describe('.update()', function () {
it('should alter a flag\'s various attributes and persist them to the database', function (done) { it('should alter a flag\'s various attributes and persist them to the database', function (done) {
Flags.update(1, 1, { Flags.update(1, 1, {
"state": "wip", state: 'wip',
"assignee": 1 assignee: 1,
}, function (err) { }, function (err) {
assert.ifError(err); assert.ifError(err);
db.getObjectFields('flag:1', ['state', 'assignee'], function (err, data) { db.getObjectFields('flag:1', ['state', 'assignee'], function (err, data) {
@ -277,13 +278,13 @@ describe('Flags', function () {
history.forEach(function (change) { history.forEach(function (change) {
switch (change.attribute) { switch (change.attribute) {
case 'state': case 'state':
assert.strictEqual('[[flags:state-wip]]', change.value); assert.strictEqual('[[flags:state-wip]]', change.value);
break; break;
case 'assignee': case 'assignee':
assert.strictEqual(1, change.value); assert.strictEqual(1, change.value);
break; break;
} }
}); });
@ -299,10 +300,10 @@ describe('Flags', function () {
var compare = { var compare = {
uid: 1, uid: 1,
pid: 1, pid: 1,
content: 'This is flaggable content' content: 'This is flaggable content',
}; };
for(var key in compare) { for (var key in compare) {
if (compare.hasOwnProperty(key)) { if (compare.hasOwnProperty(key)) {
assert.ok(data[key]); assert.ok(data[key]);
assert.equal(data[key], compare[key]); assert.equal(data[key], compare[key]);
@ -319,10 +320,10 @@ describe('Flags', function () {
var compare = { var compare = {
uid: 1, uid: 1,
username: 'testUser', username: 'testUser',
email: 'b@c.com' email: 'b@c.com',
}; };
for(var key in compare) { for (var key in compare) {
if (compare.hasOwnProperty(key)) { if (compare.hasOwnProperty(key)) {
assert.ok(data[key]); assert.ok(data[key]);
assert.equal(data[key], compare[key]); assert.equal(data[key], compare[key]);
@ -352,7 +353,7 @@ describe('Flags', function () {
Flags.validate({ Flags.validate({
type: 'post', type: 'post',
id: 1, id: 1,
uid: 1 uid: 1,
}, function (err) { }, function (err) {
assert.ok(err); assert.ok(err);
assert.strictEqual('[[error:post-deleted]]', err.message); assert.strictEqual('[[error:post-deleted]]', err.message);
@ -368,7 +369,7 @@ describe('Flags', function () {
Flags.validate({ Flags.validate({
type: 'post', type: 'post',
id: 1, id: 1,
uid: 3 uid: 3,
}, function (err) { }, function (err) {
assert.ok(err); assert.ok(err);
assert.strictEqual('[[error:not-enough-reputation-to-flag]]', err.message); assert.strictEqual('[[error:not-enough-reputation-to-flag]]', err.message);
@ -382,7 +383,7 @@ describe('Flags', function () {
it('should add a note to a flag', function (done) { it('should add a note to a flag', function (done) {
Flags.appendNote(1, 1, 'this is my note', function (err) { Flags.appendNote(1, 1, 'this is my note', function (err) {
assert.ifError(err); assert.ifError(err);
db.getSortedSetRange('flag:1:notes', 0, -1, function (err, notes) { db.getSortedSetRange('flag:1:notes', 0, -1, function (err, notes) {
if (err) { if (err) {
throw err; throw err;
@ -422,11 +423,11 @@ describe('Flags', function () {
assert.ifError(err); assert.ifError(err);
var compare = { var compare = {
uid: 1, uid: 1,
content: 'this is my note' content: 'this is my note',
}; };
var data = notes[1]; var data = notes[1];
for(var key in compare) { for (var key in compare) {
if (compare.hasOwnProperty(key)) { if (compare.hasOwnProperty(key)) {
assert.ok(data[key]); assert.ok(data[key]);
assert.strictEqual(data[key], compare[key]); assert.strictEqual(data[key], compare[key]);
@ -458,7 +459,7 @@ describe('Flags', function () {
it('should add a new entry into a flag\'s history', function (done) { it('should add a new entry into a flag\'s history', function (done) {
Flags.appendHistory(1, 1, { Flags.appendHistory(1, 1, {
state: 'rejected' state: 'rejected',
}, function (err) { }, function (err) {
assert.ifError(err); assert.ifError(err);
@ -486,14 +487,16 @@ describe('Flags', function () {
describe('(websockets)', function () { describe('(websockets)', function () {
var SocketFlags = require('../src/socket.io/flags.js'); var SocketFlags = require('../src/socket.io/flags.js');
var tid, pid, flag; var tid,
pid,
flag;
before(function (done) { before(function (done) {
Topics.post({ Topics.post({
cid: 1, cid: 1,
uid: 1, uid: 1,
title: 'Another topic', title: 'Another topic',
content: 'This is flaggable content' content: 'This is flaggable content',
}, function (err, topic) { }, function (err, topic) {
tid = topic.postData.tid; tid = topic.postData.tid;
pid = topic.postData.pid; pid = topic.postData.pid;
@ -507,7 +510,7 @@ describe('Flags', function () {
SocketFlags.create({ uid: 2 }, { SocketFlags.create({ uid: 2 }, {
type: 'post', type: 'post',
id: pid, id: pid,
reason: 'foobar' reason: 'foobar',
}, function (err, flagObj) { }, function (err, flagObj) {
flag = flagObj; flag = flagObj;
assert.ifError(err); assert.ifError(err);
@ -527,8 +530,8 @@ describe('Flags', function () {
flagId: 2, flagId: 2,
data: [{ data: [{
name: 'state', name: 'state',
value: 'wip' value: 'wip',
}] }],
}, function (err, history) { }, function (err, history) {
assert.ifError(err); assert.ifError(err);
assert(Array.isArray(history)); assert(Array.isArray(history));
@ -543,7 +546,7 @@ describe('Flags', function () {
it('should append a note to the flag', function (done) { it('should append a note to the flag', function (done) {
SocketFlags.appendNote({ uid: 2 }, { SocketFlags.appendNote({ uid: 2 }, {
flagId: 2, flagId: 2,
note: 'lorem ipsum dolor sit amet' note: 'lorem ipsum dolor sit amet',
}, function (err, data) { }, function (err, data) {
assert.ifError(err); assert.ifError(err);
assert(data.hasOwnProperty('notes')); assert(data.hasOwnProperty('notes'));

Loading…
Cancel
Save