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) {
flags.showFlagModal({
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');
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);
} else {
app.alertSuccess('[[flags:updated]]');
Flags.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);
} else {
app.alertSuccess('[[flags:note-added]]');
Flags.reloadNotes(payload.notes);
Flags.reloadHistory(payload.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]]');
Flags.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]]');
Flags.reloadNotes(payload.notes);
Flags.reloadHistory(payload.history);
});
break;
}
});
@ -50,7 +48,7 @@ define('forum/flags/detail', ['forum/flags/list', 'components', 'translator'], f
Flags.reloadNotes = function (notes) {
templates.parse('flags/detail', 'notes', {
notes: notes
notes: notes,
}, function (html) {
var wrapperEl = components.get('flag/notes');
wrapperEl.empty();
@ -62,7 +60,7 @@ define('forum/flags/detail', ['forum/flags/list', 'components', 'translator'], f
Flags.reloadHistory = function (history) {
templates.parse('flags/detail', 'history', {
history: history
history: history,
}, function (html) {
translator.translate(html, function (translated) {
var wrapperEl = components.get('flag/history');

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

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

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

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

@ -124,7 +124,7 @@ helpers.getUserDataByUserSlug = function (userslug, callerUID, callback) {
other: !isSelf,
moderator: isModerator,
globalMod: isGlobalModerator,
admin: isAdmin
admin: isAdmin,
});
userData.sso = results.sso.associations;
@ -174,7 +174,7 @@ function filterLinks(links, states) {
other: true,
moderator: true,
globalMod: true,
admin: true
admin: true,
}, link.visibility);
// 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) {
if (byScore) {
db.sortedSetCount(set, min, max, next);
} else if (set === 'users:banned' || set === 'users:notvalidated') {
db.sortedSetCard(set, next);
} else {
if (set === 'users:banned' || set === 'users:notvalidated') {
db.sortedSetCard(set, next);
} else {
db.getObjectField('global', 'userCount', next);
}
db.getObjectField('global', 'userCount', 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
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();
});
};

@ -8,7 +8,7 @@ var flags = require('../flags');
var analytics = require('../analytics');
var modsController = {
flags: {}
flags: {},
};
modsController.flags.list = function (req, res, next) {
@ -58,7 +58,7 @@ modsController.flags.list = function (req, res, next) {
async.parallel({
flags: async.apply(flags.list, filters, req.uid),
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) {
if (err) {
return next(err);
@ -92,7 +92,7 @@ modsController.flags.list = function (req, res, next) {
categories: data.categories,
hasFilter: hasFilter,
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),
moderatedCids: async.apply(user.getModeratedCids, req.uid),
flagData: async.apply(flags.get, req.params.flagId),
assignees: async.apply(user.getAdminsandGlobalModsandModerators)
assignees: async.apply(user.getAdminsandGlobalModsandModerators),
}, function (err, results) {
if (err || !results.flagData) {
return next(err || new Error('[[error:invalid-data]]'));
@ -122,7 +122,7 @@ modsController.flags.detail = function (req, res, next) {
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, {
base: async.apply(db.getObject.bind(db), 'flag:' + flagId),
history: async.apply(Flags.getHistory, flagId),
notes: async.apply(Flags.getNotes, flagId)
notes: async.apply(Flags.getNotes, flagId),
}),
function (data, next) {
// Second stage
async.parallel({
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) {
// Final object return construction
next(err, Object.assign(data.base, {
@ -39,10 +39,10 @@ Flags.get = function (flagId, callback) {
target: payload.targetObj,
history: data.history,
notes: data.notes,
reporter: payload.userObj
reporter: payload.userObj,
}));
});
}
},
], callback);
};
@ -63,44 +63,44 @@ Flags.list = function (filters, uid, callback) {
});
} else {
// Empty array, do nothing
return;
}
};
if (Object.keys(filters).length > 0) {
for (var type in filters) {
switch (type) {
case 'type':
prepareSets('flags:byType:', filters[type]);
break;
case 'type':
prepareSets('flags:byType:', filters[type]);
break;
case 'state':
prepareSets('flags:byState:', filters[type]);
break;
case 'reporterId':
prepareSets('flags:byReporter:', filters[type]);
break;
case 'assignee':
prepareSets('flags:byAssignee:', filters[type]);
break;
case 'state':
prepareSets('flags:byState:', filters[type]);
break;
case 'targetUid':
prepareSets('flags:byTargetUid:', filters[type]);
break;
case 'reporterId':
prepareSets('flags:byReporter:', filters[type]);
break;
case 'cid':
prepareSets('flags:byCid:', filters[type]);
break;
case 'assignee':
prepareSets('flags:byAssignee:', filters[type]);
break;
case 'quick':
switch (filters.quick) {
case 'mine':
sets.push('flags:byAssignee:' + uid);
break;
}
case 'targetUid':
prepareSets('flags:byTargetUid:', filters[type]);
break;
case 'cid':
prepareSets('flags:byCid:', filters[type]);
break;
case 'quick':
switch (filters.quick) {
case 'mine':
sets.push('flags:byAssignee:' + uid);
break;
}
break;
}
}
}
@ -147,38 +147,38 @@ Flags.list = function (filters, uid, callback) {
username: userObj.username,
picture: userObj.picture,
'icon:bgColor': userObj['icon:bgColor'],
'icon:text': userObj['icon:text']
}
'icon:text': userObj['icon:text'],
},
}));
});
}
},
], function (err, flagObj) {
if (err) {
return next(err);
}
switch(flagObj.state) {
case 'open':
flagObj.labelClass = 'info';
break;
case 'wip':
flagObj.labelClass = 'warning';
break;
case 'resolved':
flagObj.labelClass = 'success';
break;
case 'rejected':
flagObj.labelClass = 'danger';
break;
switch (flagObj.state) {
case 'open':
flagObj.labelClass = 'info';
break;
case 'wip':
flagObj.labelClass = 'warning';
break;
case 'resolved':
flagObj.labelClass = 'success';
break;
case 'rejected':
flagObj.labelClass = 'danger';
break;
}
next(null, Object.assign(flagObj, {
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);
};
@ -186,7 +186,7 @@ Flags.validate = function (payload, callback) {
async.parallel({
targetExists: async.apply(Flags.targetExists, payload.type, payload.id),
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) {
if (err) {
return callback(err);
@ -199,42 +199,42 @@ Flags.validate = function (payload, callback) {
}
switch (payload.type) {
case 'post':
privileges.posts.canEdit(payload.id, payload.uid, function (err, editable) {
if (err) {
return callback(err);
}
case 'post':
privileges.posts.canEdit(payload.id, payload.uid, function (err, editable) {
if (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)
if (!editable.flag && parseInt(data.reporter.reputation, 10) < minimumReputation) {
return callback(new Error('[[error:not-enough-reputation-to-flag]]'));
}
if (!editable.flag && parseInt(data.reporter.reputation, 10) < minimumReputation) {
return callback(new Error('[[error:not-enough-reputation-to-flag]]'));
}
callback();
});
break;
case 'user':
privileges.users.canEdit(payload.uid, payload.id, function (err, editable) {
if (err) {
return callback(err);
}
callback();
});
break;
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)
if (!editable && parseInt(data.reporter.reputation, 10) < minimumReputation) {
return callback(new Error('[[error:not-enough-reputation-to-flag]]'));
}
if (!editable && parseInt(data.reporter.reputation, 10) < minimumReputation) {
return callback(new Error('[[error:not-enough-reputation-to-flag]]'));
}
callback();
});
break;
default:
callback(new Error('[[error:invalid-data]]'));
break;
}
callback();
});
break;
default:
callback(new Error('[[error:invalid-data]]'));
break;
}
});
};
@ -252,7 +252,7 @@ Flags.getNotes = function (flagId, callback) {
uid: noteObj[0],
content: noteObj[1],
datetime: note.score,
datetimeISO: new Date(parseInt(note.score, 10)).toISOString()
datetimeISO: new Date(parseInt(note.score, 10)).toISOString(),
};
} catch (e) {
return next(e);
@ -271,7 +271,7 @@ Flags.getNotes = function (flagId, callback) {
return note;
}));
});
}
},
], callback);
};
@ -296,7 +296,7 @@ Flags.create = function (type, id, uid, reason, timestamp, callback) {
// Extra data for zset insertion
async.apply(Flags.getTargetUid, type, id),
async.apply(Flags.getTargetCid, type, id)
async.apply(Flags.getTargetCid, type, id),
], function (err, checks) {
if (err) {
return next(err);
@ -309,9 +309,8 @@ Flags.create = function (type, id, uid, reason, timestamp, callback) {
return next(new Error('[[error:already-flagged]]'));
} else if (!checks[1]) {
return next(new Error('[[error:invalid-data]]'));
} else {
next();
}
next();
});
},
async.apply(db.incrObjectField, 'global', 'nextFlagId'),
@ -323,13 +322,13 @@ Flags.create = function (type, id, uid, reason, timestamp, callback) {
targetId: id,
description: reason,
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: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: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) {
@ -341,20 +340,20 @@ Flags.create = function (type, id, uid, reason, timestamp, callback) {
if (type === 'post') {
tasks.push(async.apply(db.sortedSetAdd.bind(db), 'flags:byPid:' + id, timestamp, flagId)); // by target pid
}
async.parallel(tasks, function (err, data) {
if (err) {
return next(err);
}
if (doHistoryAppend) {
Flags.update(flagId, uid, { "state": "open" });
Flags.update(flagId, uid, { state: 'open' });
}
next(null, flagId);
});
},
async.apply(Flags.get)
async.apply(Flags.get),
], callback);
};
@ -368,72 +367,72 @@ Flags.getTarget = function (type, id, uid, callback) {
function (exists, next) {
if (exists) {
switch (type) {
case 'post':
async.waterfall([
async.apply(posts.getPostsByPids, [id], uid),
function (posts, next) {
topics.addPostData(posts, uid, next);
}
], function (err, posts) {
next(err, posts[0]);
});
break;
case 'post':
async.waterfall([
async.apply(posts.getPostsByPids, [id], uid),
function (posts, next) {
topics.addPostData(posts, uid, next);
},
], function (err, posts) {
next(err, posts[0]);
});
break;
case 'user':
user.getUsersData([id], function (err, users) {
next(err, users ? users[0] : undefined);
});
break;
case 'user':
user.getUsersData([id], function (err, users) {
next(err, users ? users[0] : undefined);
});
break;
default:
next(new Error('[[error:invalid-data]]'));
break;
default:
next(new Error('[[error:invalid-data]]'));
break;
}
} else {
// Target used to exist (otherwise flag creation'd fail), but no longer
next(null, {});
}
}
},
], callback);
};
Flags.targetExists = function (type, id, callback) {
switch (type) {
case 'post':
posts.exists(id, callback);
break;
case 'user':
user.exists(id, callback);
break;
case 'post':
posts.exists(id, callback);
break;
default:
callback(new Error('[[error:invalid-data]]'));
break;
case 'user':
user.exists(id, callback);
break;
default:
callback(new Error('[[error:invalid-data]]'));
break;
}
};
Flags.getTargetUid = function (type, id, callback) {
switch (type) {
case 'post':
posts.getPostField(id, 'uid', callback);
break;
default:
setImmediate(callback, null, id);
break;
case 'post':
posts.getPostField(id, 'uid', callback);
break;
default:
setImmediate(callback, null, id);
break;
}
};
Flags.getTargetCid = function (type, id, callback) {
switch (type) {
case 'post':
posts.getCidByPid(id, callback);
break;
case 'post':
posts.getCidByPid(id, callback);
break;
default:
setImmediate(callback, null, id);
break;
default:
setImmediate(callback, null, id);
break;
}
};
@ -453,14 +452,14 @@ Flags.update = function (flagId, uid, changeset, callback) {
} else {
// Add tasks as necessary
switch (prop) {
case 'state':
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));
break;
case 'assignee':
tasks.push(async.apply(db.sortedSetAdd.bind(db), 'flags:byAssignee:' + changeset[prop], now, flagId));
break;
case 'state':
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));
break;
case 'assignee':
tasks.push(async.apply(db.sortedSetAdd.bind(db), 'flags:byAssignee:' + changeset[prop], now, flagId));
break;
}
}
}
@ -483,7 +482,7 @@ Flags.update = function (flagId, uid, changeset, callback) {
async.parallel(tasks, function (err, data) {
return next(err);
});
}
},
], callback);
};
@ -512,12 +511,12 @@ Flags.getHistory = function (flagId, callback) {
uid: entry.value[0],
fields: changeset,
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);
}
},
], function (err, users) {
if (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(Flags.appendHistory, flagId, uid, {
notes: null,
datetime: datetime
})
datetime: datetime,
}),
], callback);
};
@ -576,88 +575,88 @@ Flags.notify = function (flagObj, uid, callback) {
}
switch (flagObj.type) {
case 'post':
async.parallel({
post: function (next) {
async.waterfall([
async.apply(posts.getPostData, flagObj.targetId),
async.apply(posts.parsePost)
], next);
},
title: async.apply(topics.getTitleByPid, flagObj.targetId),
admins: async.apply(groups.getMembers, 'administrators', 0, -1),
globalMods: async.apply(groups.getMembers, 'Global Moderators', 0, -1),
moderators: function (next) {
async.waterfall([
async.apply(posts.getCidByPid, flagObj.targetId),
function (cid, next) {
groups.getMembers('cid:' + cid + ':privileges:mods', 0, -1, next);
}
], next);
}
}, function (err, results) {
if (err) {
case 'post':
async.parallel({
post: function (next) {
async.waterfall([
async.apply(posts.getPostData, flagObj.targetId),
async.apply(posts.parsePost),
], next);
},
title: async.apply(topics.getTitleByPid, flagObj.targetId),
admins: async.apply(groups.getMembers, 'administrators', 0, -1),
globalMods: async.apply(groups.getMembers, 'Global Moderators', 0, -1),
moderators: function (next) {
async.waterfall([
async.apply(posts.getCidByPid, flagObj.targetId),
function (cid, next) {
groups.getMembers('cid:' + cid + ':privileges:mods', 0, -1, next);
},
], next);
},
}, function (err, results) {
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);
}
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);
}
plugins.fireHook('action:flag.create', {
flag: flagObj
});
notifications.push(notification, results.admins.concat(results.moderators).concat(results.globalMods), callback);
plugins.fireHook('action:flag.create', {
flag: flagObj,
});
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':
async.parallel({
admins: async.apply(groups.getMembers, 'administrators', 0, -1),
globalMods: async.apply(groups.getMembers, 'Global Moderators', 0, -1),
}, function (err, results) {
if (err) {
notifications.create({
bodyShort: '[[notifications:user_flagged_user, ' + flagObj.reporter.username + ', ' + flagObj.target.username + ']]',
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);
}
notifications.create({
bodyShort: '[[notifications:user_flagged_user, ' + flagObj.reporter.username + ', ' + flagObj.target.username + ']]',
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);
plugins.fireHook('action:flag.create', {
flag: flagObj,
});
notifications.push(notification, results.admins.concat(results.globalMods), callback);
});
break;
default:
callback(new Error('[[error:invalid-data]]'));
break;
});
break;
default:
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);
},
function (results, next) {
plugins.fireHook('action:group.create', {group: groupData});
plugins.fireHook('action:group.create', { group: groupData });
next(null, groupData);
},
], callback);

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

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

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

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

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

@ -65,7 +65,7 @@ module.exports = function (Posts) {
postData.cid = results.topic.cid;
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));
pubsub.publish('post:edit', String(postData.pid));
@ -136,7 +136,7 @@ module.exports = function (Posts) {
function (tags, next) {
topicData.tags = data.tags;
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, {
tid: tid,
cid: results.topic.cid,

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

@ -95,7 +95,7 @@ module.exports = function (SocketTopics) {
var start = parseInt(data.after, 10);
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) {

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

@ -82,7 +82,7 @@ module.exports = function (Topics) {
], next);
},
function (results, next) {
plugins.fireHook('action:topic.save', {topic: _.clone(topicData)});
plugins.fireHook('action:topic.save', { topic: _.clone(topicData) });
next(null, topicData.tid);
},
], callback);
@ -174,7 +174,7 @@ module.exports = function (Topics) {
data.postData.index = 0;
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)) {
user.notifications.sendTopicNotificationToFollowers(uid, data.topicData, data.postData);
@ -269,7 +269,7 @@ module.exports = function (Topics) {
Topics.notifyFollowers(postData, uid);
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);
},

@ -334,11 +334,11 @@ Upgrade.upgrade = function (callback) {
posts = posts.filter(function (post) {
return post.hasOwnProperty('flags');
});
async.each(posts, function (post, next) {
async.parallel({
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) {
if (err) {
return next(err);
@ -362,7 +362,7 @@ Upgrade.upgrade = function (callback) {
flags.update(flagObj.flagId, 1, {
state: post['flag:state'],
assignee: post['flag:assignee'],
datetime: datetime
datetime: datetime,
}, next);
} else {
setImmediate(next);
@ -383,7 +383,7 @@ Upgrade.upgrade = function (callback) {
} else {
setImmediate(next);
}
}
},
], function (err) {
if (err && err.message === '[[error:already-flagged]]') {
// 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!');
next();
}
}
},
// Add new schema updates here
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!!
], function (err) {

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

@ -140,7 +140,7 @@ module.exports = function (User) {
if (userNameChanged) {
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);
},
], callback);

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

Loading…
Cancel
Save