Merge branch 'master' into csrf

This commit is contained in:
gaba
2016-12-22 14:23:01 -08:00
56 changed files with 1802 additions and 7840 deletions
+35 -7
View File
@@ -20,18 +20,47 @@ router.get('/', (req, res, next) => {
skip = 0,
sort = 'asc',
field = 'created_at',
filter = 'all',
search = ''
} = req.query;
const FilterOpenAssets = (query, filter) => {
switch(filter) {
case 'open':
return query.merge({
$or: [
{
closedAt: null
},
{
closedAt: {
$gt: Date.now()
}
}
]
});
case 'closed':
return query.merge({
closedAt: {
$lt: Date.now()
}
});
default:
return query;
}
};
// Find all the assets.
Promise.all([
Asset
.search(search)
// Find the actuall assets.
FilterOpenAssets(Asset.search(search), filter)
.sort({[field]: (sort === 'asc') ? 1 : -1})
.skip(skip)
.limit(limit),
Asset
.search(search)
.skip(parseInt(skip))
.limit(parseInt(limit)),
// Get the count of actual assets.
FilterOpenAssets(Asset.search(search), filter)
.count()
])
.then(([result, count]) => {
@@ -115,7 +144,6 @@ router.put('/:asset_id/status', (req, res, next) => {
}
})
.then(() => {
res.status(204).json();
})
.catch((err) => {
+12 -4
View File
@@ -104,7 +104,7 @@ router.post('/', parseForm, csrfProtection, wordlist.filter('body'), (req, res,
// premod, set it to `premod`.
let status;
if (req.wordlist.matched) {
if (req.wordlist.banned) {
status = Promise.resolve('rejected');
} else {
status = Asset
@@ -142,6 +142,15 @@ router.post('/', parseForm, csrfProtection, wordlist.filter('body'), (req, res,
status,
author_id: req.user.id
}))
.then((comment) => {
if (req.wordlist.suspect) {
return Comment
.addAction(comment.id, null, 'flag', 'body', 'Matched suspect word filters.')
.then(() => comment);
}
return comment;
})
.then((comment) => {
// The comment was created! Send back the created comment.
@@ -198,12 +207,11 @@ router.post('/:comment_id/actions', parseForm, csrfProtection, (req, res, next)
const {
action_type,
field,
detail
metadata
} = req.body;
Comment
.addAction(req.params.comment_id, req.user.id, action_type, field, detail)
.addAction(req.params.comment_id, req.user.id, action_type, metadata)
.then((action) => {
res.status(201).json(action);
})
+2 -3
View File
@@ -170,12 +170,11 @@ router.put('/:user_id/bio', (req, res, next) => {
router.post('/:user_id/actions', parseForm, csrfProtection, authorization.needed(), (req, res, next) => {
const {
action_type,
field,
detail
metadata
} = req.body;
User
.addAction(req.params.user_id, req.user.id, action_type, field, detail)
.addAction(req.params.user_id, req.user.id, action_type, metadata)
.then((action) => {
res.status(201).json(action);
})